ILIAS  release_8 Revision v8.23
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)
 provideGotoLinkData More...
 
 provideGotoLinkData ()
 

Private Member Functions

 mockClickableCall (string $input, string $transformed)
 
 repeatForFormat (string $format, array $values)
 

Detailed Description

Definition at line 27 of file ilUtilTest.php.

Member Function Documentation

◆ mockClickableCall()

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

Definition at line 139 of file ilUtilTest.php.

References $container, and ILIAS\Repository\$refinery.

Referenced by testMakeClickableWithGotoLinksAndInvalidRefId(), and testMakeClickableWithoutGotoLinks().

139  : Container
140  {
141  $transformation = $this->getMockBuilder(Transformation::class)->getMock();
142  $transformation->expects(self::once())->method('transform')->with($input)->willReturn($transformed);
143 
144  $string_group = $this->getMockBuilder(StringGroup::class)->disableOriginalConstructor()->getMock();
145  $string_group->expects(self::once())->method('makeClickable')->willReturn($transformation);
146 
147  $refinery = $this->getMockBuilder(Refinery::class)->disableOriginalConstructor()->getMock();
148  $refinery->expects(self::once())->method('string')->willReturn($string_group);
149 
150  $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
151  $container->expects(self::once())->method('refinery')->willReturn($refinery);
152 
153  return $container;
154  }
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:31
$container
Definition: wac.php:14
Refinery Factory $refinery
+ Here is the caller graph for this function:

◆ provideGotoLinkData()

ilUtilTest::provideGotoLinkData ( )

Definition at line 76 of file ilUtilTest.php.

References ILIAS\LTI\ToolProvider\$key, $name, and repeatForFormat().

76  : array
77  {
78  // Please note that these test cases represent the current state, not necessarily the correct state.
79  // For example all anchor attributes are REMOVED and the target is ALWAYS set to target="_self".
80 
81  $tests = [
82  'Test with empty string.' => ['', '', [], []],
83  'Test with correct link and target = _self is added.' => [
84  'A link to <a href="%scrs_345%s" target="_self">a course</a>.',
85  'A link to <a href="%scrs_345%s">somewhere</a>.',
86  [345 => 5],
87  [5 => 'a course'],
88  ],
89  'Test with multiple correct links.' => [
90  '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>.',
91  'A link to <a href="%scrs_345%s">somewhere</a> and to <a href="%scrs_87%s">somewhere else</a>.',
92  [345 => 5, 87 => 45],
93  [5 => 'a course', 45 => 'another course'],
94  ],
95  'Test links with invalid ref id.' => [
96  'A link to <a href="%scrs_345%s">somewhere</a>.',
97  'A link to <a href="%scrs_345%s">somewhere</a>.',
98  [345 => 0],
99  [],
100  ],
101  'The target attribute is REPLACED with _self.' => [
102  'A link to <a href="%scrs_345%s" target="_self">some course</a>.',
103  'A link to <a target="bogus target" href="%scrs_345%s">somewhere</a>.',
104  [345 => 8],
105  [8 => 'some course'],
106  ],
107  'The attributes position does not matter, it is always replaced with target="_self".' => [
108  'A link to <a href="%scrs_345%s" target="_self">some course</a>.',
109  'A link to <a href="%scrs_345%s" target="bogus target">somewhere</a>.',
110  [345 => 8],
111  [8 => 'some course'],
112  ],
113  'All attributes are removed from the link.' => [
114  'A link to <a href="%scrs_345%s" target="_self">some course</a>.',
115  'A link to <a href="%scrs_345%s" class="very-important-css-class">somewhere</a>.',
116  [345 => 8],
117  [8 => 'some course'],
118  ],
119  ];
120 
121  $linkFormats = [
122  'With goto.php: ' => ['http://localhost/goto.php?target=', ''],
123  'With goto_*.html: ' => ['http://localhost/goto_', '.html'],
124  ];
125 
126  $allTests = [];
127  foreach ($linkFormats as $name => $args) {
128  foreach ($tests as $key => $array) {
129  $allTests[$name . $key] = array_merge([
130  sprintf($array[0], ...$this->repeatForFormat($array[0], $args)),
131  sprintf($array[1], ...$this->repeatForFormat($array[1], $args)),
132  ], array_slice($array, 2));
133  }
134  }
135 
136  return $allTests;
137  }
repeatForFormat(string $format, array $values)
Definition: ilUtilTest.php:156
if($format !==null) $name
Definition: metadata.php:247
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:

◆ repeatForFormat()

ilUtilTest::repeatForFormat ( string  $format,
array  $values 
)
private

Definition at line 156 of file ilUtilTest.php.

Referenced by provideGotoLinkData().

156  : array
157  {
158  return array_merge(
159  ...array_fill(0, (count(explode('%s', $format)) - 1) / 2, $values)
160  );
161  }
$format
Definition: metadata.php:235
+ Here is the caller graph for this function:

◆ testMakeClickableWithGotoLinksAndInvalidRefId()

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

provideGotoLinkData

Definition at line 47 of file ilUtilTest.php.

References $container, $GLOBALS, ilUtil\makeClickable(), and mockClickableCall().

47  : void
48  {
49  $wrap_array = static fn (array $array): array => (
50  array_map(static fn (int $x): array => [$x], $array)
51  );
52 
53  $container = $this->mockClickableCall($input, $expected);
54 
55  $cache = $this->getMockBuilder(ilObjectDataCache::class)->disableOriginalConstructor()->getMock();
56 
57  $cache->expects(self::exactly(count($ref_to_obj)))
58  ->method('lookupObjId')
59  ->withConsecutive(...$wrap_array(array_keys($ref_to_obj)))
60  ->willReturnOnConsecutiveCalls(...array_values($ref_to_obj));
61 
62  $cache->expects(self::exactly(count($obj_to_title)))
63  ->method('lookupTitle')
64  ->withConsecutive(...$wrap_array(array_keys($obj_to_title)))
65  ->willReturnOnConsecutiveCalls(...array_values($obj_to_title));
66 
67  $container->expects(self::exactly(count($ref_to_obj)))->method('offsetGet')->with('ilObjDataCache')->willReturn($cache);
68 
69  $GLOBALS['DIC'] = $container;
70 
71  $this->assertSame($expected, ilUtil::makeClickable($input, true));
72 
73  unset($GLOBALS['DIC']);
74  }
$container
Definition: wac.php:14
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
mockClickableCall(string $input, string $transformed)
Definition: ilUtilTest.php:139
static makeClickable(string $a_text, bool $detectGotoLinks=false)
+ Here is the call graph for this function:

◆ testMakeClickableWithoutGotoLinks()

ilUtilTest::testMakeClickableWithoutGotoLinks ( )

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

Definition at line 32 of file ilUtilTest.php.

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

32  : void
33  {
34  $input = 'Small things make base men proud.';
35  $expected = 'I do desire we may be better strangers.';
36 
37  $GLOBALS['DIC'] = $this->mockClickableCall($input, $expected);
38 
39  $this->assertSame($expected, ilUtil::makeClickable($input));
40 
41  unset($GLOBALS['DIC']);
42  }
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
mockClickableCall(string $input, string $transformed)
Definition: ilUtilTest.php:139
static makeClickable(string $a_text, bool $detectGotoLinks=false)
+ Here is the call graph for this function:

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