19 declare(strict_types=1);
34 $input =
'Small things make base men proud.';
35 $expected =
'I do desire we may be better strangers.';
49 $wrap_array =
static fn (array $array): array => (
50 array_map(
static fn (
int $x): array => [$x], $array)
55 $cache = $this->getMockBuilder(ilObjectDataCache::class)->disableOriginalConstructor()->getMock();
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));
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));
67 $container->expects(self::exactly(count($ref_to_obj)))->method(
'offsetGet')->with(
'ilObjDataCache')->willReturn($cache);
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>.',
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>.',
93 [5 =>
'a course', 45 =>
'another course'],
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>.',
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>.',
105 [8 =>
'some course'],
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>.',
111 [8 =>
'some course'],
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>.',
117 [8 =>
'some course'],
122 'With goto.php: ' => [
'http://localhost/goto.php?target=',
''],
123 'With goto_*.html: ' => [
'http://localhost/goto_',
'.html'],
127 foreach ($linkFormats as
$name => $args) {
128 foreach ($tests as
$key => $array) {
132 ], array_slice($array, 2));
141 $transformation = $this->getMockBuilder(Transformation::class)->getMock();
142 $transformation->expects(self::once())->method(
'transform')->with($input)->willReturn($transformed);
144 $string_group = $this->getMockBuilder(StringGroup::class)->disableOriginalConstructor()->getMock();
145 $string_group->expects(self::once())->method(
'makeClickable')->willReturn($transformation);
147 $refinery = $this->getMockBuilder(Refinery::class)->disableOriginalConstructor()->getMock();
148 $refinery->expects(self::once())->method(
'string')->willReturn($string_group);
150 $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
159 ...array_fill(0, (count(explode(
'%s', $format)) - 1) / 2, $values)
repeatForFormat(string $format, array $values)
testMakeClickableWithoutGotoLinks()
ilUtil::makeClickable must call the refinery transformation make clickable.
Customizing of pimple-DIC for ILIAS.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
testMakeClickableWithGotoLinksAndInvalidRefId(string $expected, string $input, array $ref_to_obj, array $obj_to_title)
provideGotoLinkData
mockClickableCall(string $input, string $transformed)
static makeClickable(string $a_text, bool $detectGotoLinks=false)
Refinery Factory $refinery