ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilUtilTest Class Reference
+ Inheritance diagram for ilUtilTest:
+ Collaboration diagram for ilUtilTest:

Public Member Functions

 testMakeClickableWithoutGotoLinks ()
 ilUtil::makeClickable must call the refinery transformation make clickable. More...
 
 testMakeClickableWithGotoLinksAndInvalidRefId (string $expected, string $input, array $ref_to_obj, array $obj_to_title)
 

Static Public Member Functions

static provideGotoLinkData ()
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 

Private Member Functions

 mockClickableCall (string $input, string $transformed)
 

Private Attributes

const string HTTP_HOST = 'http://localhost'
 
Container $original_dic = null
 

Detailed Description

Definition at line 28 of file ilUtilTest.php.

Member Function Documentation

◆ mockClickableCall()

ilUtilTest::mockClickableCall ( string  $input,
string  $transformed 
)
private

Definition at line 186 of file ilUtilTest.php.

186 : Container&MockObject
187 {
188 $transformation = $this->getMockBuilder(Transformation::class)->getMock();
189 $transformation->expects($this->once())->method('transform')->with($input)->willReturn($transformed);
190
191 $string_group = $this->getMockBuilder(StringGroup::class)->disableOriginalConstructor()->getMock();
192 $string_group->expects($this->once())->method('makeClickable')->willReturn($transformation);
193
194 $refinery = $this->getMockBuilder(Refinery::class)->disableOriginalConstructor()->getMock();
195 $refinery->expects($this->once())->method('string')->willReturn($string_group);
196
197 $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
198 $container->expects($this->once())->method('refinery')->willReturn($refinery);
199
200 return $container;
201 }
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
$container
@noRector
Definition: wac.php:37

References $container, and ILIAS\UI\examples\Layout\Page\Standard\$refinery.

Referenced by testMakeClickableWithoutGotoLinks().

+ Here is the caller graph for this function:

◆ provideGotoLinkData()

static ilUtilTest::provideGotoLinkData ( )
static

Definition at line 117 of file ilUtilTest.php.

117 : array
118 {
119 // Please note that these test cases represent the current state, not necessarily the correct state.
120 // For example all anchor attributes are REMOVED and the target is ALWAYS set to target="_self".
121
122 $tests = [
123 'Test with empty string.' => ['', '', [], []],
124 'Test with correct link and target = _self is added.' => [
125 'A link to <a href="%scrs_345%s" target="_self">a course</a>.',
126 'A link to <a href="%scrs_345%s">somewhere</a>.',
127 [345 => 5],
128 [5 => 'a course'],
129 ],
130 'Test with multiple correct links.' => [
131 'A link to <a href="%scrs_345%s" target="_self">a course</a> and to <a href="%scrs_87%s" target="_self">another course</a>.',
132 'A link to <a href="%scrs_345%s">somewhere</a> and to <a href="%scrs_87%s">somewhere else</a>.',
133 [345 => 5, 87 => 45],
134 [5 => 'a course', 45 => 'another course'],
135 ],
136 'Test links with invalid ref id.' => [
137 'A link to <a href="%scrs_345%s">somewhere</a>.',
138 'A link to <a href="%scrs_345%s">somewhere</a>.',
139 [345 => 0],
140 [],
141 ],
142 'The target attribute is REPLACED with _self.' => [
143 'A link to <a href="%scrs_345%s" target="_self">some course</a>.',
144 'A link to <a target="bogus target" href="%scrs_345%s">somewhere</a>.',
145 [345 => 8],
146 [8 => 'some course'],
147 ],
148 'The attributes position does not matter, it is always replaced with target="_self".' => [
149 'A link to <a href="%scrs_345%s" target="_self">some course</a>.',
150 'A link to <a href="%scrs_345%s" target="bogus target">somewhere</a>.',
151 [345 => 8],
152 [8 => 'some course'],
153 ],
154 'All attributes are removed from the link.' => [
155 'A link to <a href="%scrs_345%s" target="_self">some course</a>.',
156 'A link to <a href="%scrs_345%s" class="very-important-css-class">somewhere</a>.',
157 [345 => 8],
158 [8 => 'some course'],
159 ],
160 ];
161
162 $linkFormats = [
163 'With goto.php: ' => [self::HTTP_HOST . '/goto.php?target=', ''],
164 'With goto_*.html: ' => [self::HTTP_HOST . '/goto_', '.html'],
165 ];
166
167 $repeatForFormat = static function (string $format, array $values): array {
168 return array_merge(
169 ...array_fill(0, (count(explode('%s', $format)) - 1) / 2, $values)
170 );
171 };
172
173 $allTests = [];
174 foreach ($linkFormats as $name => $args) {
175 foreach ($tests as $key => $array) {
176 $allTests[$name . $key] = array_merge([
177 sprintf($array[0], ...$repeatForFormat($array[0], $args)),
178 sprintf($array[1], ...$repeatForFormat($array[1], $args)),
179 ], array_slice($array, 2));
180 }
181 }
182
183 return $allTests;
184 }

◆ setUp()

ilUtilTest::setUp ( )
protected

Definition at line 34 of file ilUtilTest.php.

34 : void
35 {
36 global $DIC;
37
38 $this->original_dic = is_object($DIC) ? clone $DIC : $DIC;
39
40 parent::setUp();
41 }
global $DIC
Definition: shib_login.php:26

References $DIC.

◆ tearDown()

ilUtilTest::tearDown ( )
protected

Definition at line 43 of file ilUtilTest.php.

43 : void
44 {
45 global $DIC;
46
48
49 parent::tearDown();
50 }
Container $original_dic
Definition: ilUtilTest.php:32

References $DIC, and $original_dic.

◆ testMakeClickableWithGotoLinksAndInvalidRefId()

ilUtilTest::testMakeClickableWithGotoLinksAndInvalidRefId ( string  $expected,
string  $input,
array  $ref_to_obj,
array  $obj_to_title 
)

Definition at line 68 of file ilUtilTest.php.

73 : void {
74 global $DIC;
75
76 $container = $this->mockClickableCall($input, $expected);
77
78 $cache = $this->getMockBuilder(ilObjectDataCache::class)->disableOriginalConstructor()->getMock();
79
80 $consecutive_id = [];
81 foreach ($ref_to_obj as $k => $v) {
82 $consecutive_id[] = [$k, $v];
83 }
84
85 $cache->expects($this->exactly(count($ref_to_obj)))
86 ->method('lookupObjId')
87 ->willReturnCallback(
88 function ($id) use (&$consecutive_id) {
89 [$k, $v] = array_shift($consecutive_id);
90 $this->assertEquals($k, $id);
91 return $v;
92 }
93 );
94
95 $consecutive_title = [];
96 foreach ($obj_to_title as $k => $v) {
97 $consecutive_title[] = [$k, $v];
98 }
99
100 $cache->expects($this->exactly(count($obj_to_title)))
101 ->method('lookupTitle')
102 ->willReturnCallback(
103 function ($id) use (&$consecutive_title) {
104 [$k, $v] = array_shift($consecutive_title);
105 $this->assertEquals($k, $id);
106 return $v;
107 }
108 );
109
110 $container->expects($this->exactly(count($ref_to_obj)))->method('offsetGet')->with('ilObjDataCache')->willReturn($cache);
111
113
114 $this->assertSame($expected, ilUtil::makeClickable($input, true, self::HTTP_HOST));
115 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
mockClickableCall(string $input, string $transformed)
Definition: ilUtilTest.php:186
static makeClickable(string $a_text, bool $detectGotoLinks=false, ?string $ilias_http_path=null)

◆ testMakeClickableWithoutGotoLinks()

ilUtilTest::testMakeClickableWithoutGotoLinks ( )

ilUtil::makeClickable must call the refinery transformation make clickable.

Definition at line 55 of file ilUtilTest.php.

55 : void
56 {
57 global $DIC;
58
59 $input = 'Small things make base men proud.';
60 $expected = 'I do desire we may be better strangers.';
61
62 $DIC = $this->mockClickableCall($input, $expected);
63
64 $this->assertSame($expected, ilUtil::makeClickable($input));
65 }

References $DIC, ilUtil\makeClickable(), and mockClickableCall().

+ Here is the call graph for this function:

Field Documentation

◆ $original_dic

Container ilUtilTest::$original_dic = null
private

Definition at line 32 of file ilUtilTest.php.

Referenced by tearDown().

◆ HTTP_HOST

const string ilUtilTest::HTTP_HOST = 'http://localhost'
private

Definition at line 30 of file ilUtilTest.php.


The documentation for this class was generated from the following file: