ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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...
 

Static Public Member Functions

static provideGotoLinkData ()
 

Protected Member Functions

 setUp ()
 

Private Member Functions

 mockClickableCall (string $input, string $transformed)
 

Detailed Description

Definition at line 27 of file ilUtilTest.php.

Member Function Documentation

◆ mockClickableCall()

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

Definition at line 171 of file ilUtilTest.php.

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

Referenced by testMakeClickableWithGotoLinksAndInvalidRefId(), and testMakeClickableWithoutGotoLinks().

171  : Container
172  {
173  $transformation = $this->getMockBuilder(Transformation::class)->getMock();
174  $transformation->expects(self::once())->method('transform')->with($input)->willReturn($transformed);
175 
176  $string_group = $this->getMockBuilder(StringGroup::class)->disableOriginalConstructor()->getMock();
177  $string_group->expects(self::once())->method('makeClickable')->willReturn($transformation);
178 
179  $refinery = $this->getMockBuilder(Refinery::class)->disableOriginalConstructor()->getMock();
180  $refinery->expects(self::once())->method('string')->willReturn($string_group);
181 
182  $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
183  $container->expects(self::once())->method('refinery')->willReturn($refinery);
184 
185  return $container;
186  }
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
$container
Definition: wac.php:36
+ Here is the caller graph for this function:

◆ provideGotoLinkData()

static ilUtilTest::provideGotoLinkData ( )
static

Definition at line 102 of file ilUtilTest.php.

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

◆ setUp()

ilUtilTest::setUp ( )
protected

Definition at line 29 of file ilUtilTest.php.

29  : void
30  {
31  parent::setUp();
32  if (!defined("ILIAS_HTTP_PATH")) {
33  define("ILIAS_HTTP_PATH", "http://localhost");
34  }
35  }

◆ testMakeClickableWithGotoLinksAndInvalidRefId()

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

provideGotoLinkData

Definition at line 55 of file ilUtilTest.php.

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

55  : void
56  {
57  $wrap_array = static fn(array $array): array => (
58  array_map(static fn(int $x): array => [$x], $array)
59  );
60 
61  $container = $this->mockClickableCall($input, $expected);
62 
63  $cache = $this->getMockBuilder(ilObjectDataCache::class)->disableOriginalConstructor()->getMock();
64 
65  $consecutive_id = [];
66  foreach($ref_to_obj as $k => $v) {
67  $consecutive_id[] = [$k, $v];
68  }
69  $cache->expects(self::exactly(count($ref_to_obj)))
70  ->method('lookupObjId')
71  ->willReturnCallback(
72  function ($id) use (&$consecutive_id) {
73  list($k, $v) = array_shift($consecutive_id);
74  $this->assertEquals($k, $id);
75  return $v;
76  }
77  );
78 
79  $consecutive_title = [];
80  foreach($obj_to_title as $k => $v) {
81  $consecutive_title[] = [$k, $v];
82  }
83  $cache->expects(self::exactly(count($obj_to_title)))
84  ->method('lookupTitle')
85  ->willReturnCallback(
86  function ($id) use (&$consecutive_title) {
87  list($k, $v) = array_shift($consecutive_title);
88  $this->assertEquals($k, $id);
89  return $v;
90  }
91  );
92 
93  $container->expects(self::exactly(count($ref_to_obj)))->method('offsetGet')->with('ilObjDataCache')->willReturn($cache);
94 
95  $GLOBALS['DIC'] = $container;
96 
97  $this->assertSame($expected, ilUtil::makeClickable($input, true));
98 
99  unset($GLOBALS['DIC']);
100  }
$container
Definition: wac.php:36
$GLOBALS["DIC"]
Definition: wac.php:53
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
mockClickableCall(string $input, string $transformed)
Definition: ilUtilTest.php:171
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 40 of file ilUtilTest.php.

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

40  : void
41  {
42  $input = 'Small things make base men proud.';
43  $expected = 'I do desire we may be better strangers.';
44 
45  $GLOBALS['DIC'] = $this->mockClickableCall($input, $expected);
46 
47  $this->assertSame($expected, ilUtil::makeClickable($input));
48 
49  unset($GLOBALS['DIC']);
50  }
$GLOBALS["DIC"]
Definition: wac.php:53
mockClickableCall(string $input, string $transformed)
Definition: ilUtilTest.php:171
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: