19 declare(strict_types=1);
29 protected function setUp(): void
32 if (!defined(
"ILIAS_HTTP_PATH")) {
33 define(
"ILIAS_HTTP_PATH",
"http://localhost");
42 $input =
'Small things make base men proud.';
43 $expected =
'I do desire we may be better strangers.';
52 #[\PHPUnit\Framework\Attributes\DataProvider('provideGotoLinkData')] 55 $wrap_array =
static fn(array $array): array => (
56 array_map(
static fn(
int $x): array => [$x], $array)
61 $cache = $this->getMockBuilder(ilObjectDataCache::class)->disableOriginalConstructor()->getMock();
64 foreach($ref_to_obj as $k => $v) {
65 $consecutive_id[] = [$k, $v];
67 $cache->expects(self::exactly(count($ref_to_obj)))
68 ->method(
'lookupObjId')
70 function (
$id) use (&$consecutive_id) {
71 list($k, $v) = array_shift($consecutive_id);
72 $this->assertEquals($k,
$id);
77 $consecutive_title = [];
78 foreach($obj_to_title as $k => $v) {
79 $consecutive_title[] = [$k, $v];
81 $cache->expects(self::exactly(count($obj_to_title)))
82 ->method(
'lookupTitle')
84 function (
$id) use (&$consecutive_title) {
85 list($k, $v) = array_shift($consecutive_title);
86 $this->assertEquals($k,
$id);
91 $container->expects(self::exactly(count($ref_to_obj)))->method(
'offsetGet')->with(
'ilObjDataCache')->willReturn($cache);
106 'Test with empty string.' => [
'',
'', [], []],
107 'Test with correct link and target = _self is added.' => [
108 'A link to <a href="%scrs_345%s" target="_self">a course</a>.',
109 'A link to <a href="%scrs_345%s">somewhere</a>.',
113 'Test with multiple correct links.' => [
114 '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>.',
115 'A link to <a href="%scrs_345%s">somewhere</a> and to <a href="%scrs_87%s">somewhere else</a>.',
116 [345 => 5, 87 => 45],
117 [5 =>
'a course', 45 =>
'another course'],
119 'Test links with invalid ref id.' => [
120 'A link to <a href="%scrs_345%s">somewhere</a>.',
121 'A link to <a href="%scrs_345%s">somewhere</a>.',
125 'The target attribute is REPLACED with _self.' => [
126 'A link to <a href="%scrs_345%s" target="_self">some course</a>.',
127 'A link to <a target="bogus target" href="%scrs_345%s">somewhere</a>.',
129 [8 =>
'some course'],
131 'The attributes position does not matter, it is always replaced with target="_self".' => [
132 'A link to <a href="%scrs_345%s" target="_self">some course</a>.',
133 'A link to <a href="%scrs_345%s" target="bogus target">somewhere</a>.',
135 [8 =>
'some course'],
137 'All attributes are removed from the link.' => [
138 'A link to <a href="%scrs_345%s" target="_self">some course</a>.',
139 'A link to <a href="%scrs_345%s" class="very-important-css-class">somewhere</a>.',
141 [8 =>
'some course'],
146 'With goto.php: ' => [
'http://localhost/goto.php?target=',
''],
147 'With goto_*.html: ' => [
'http://localhost/goto_',
'.html'],
150 $repeatForFormat =
function (
string $format, array $values): array {
152 ...array_fill(0, (count(explode(
'%s', $format)) - 1) / 2, $values)
157 foreach ($linkFormats as $name => $args) {
158 foreach ($tests as $key => $array) {
159 $allTests[$name . $key] = array_merge([
160 sprintf($array[0], ...$repeatForFormat($array[0], $args)),
161 sprintf($array[1], ...$repeatForFormat($array[1], $args)),
162 ], array_slice($array, 2));
171 $transformation = $this->getMockBuilder(Transformation::class)->getMock();
172 $transformation->expects(self::once())->method(
'transform')->with($input)->willReturn($transformed);
174 $string_group = $this->getMockBuilder(StringGroup::class)->disableOriginalConstructor()->getMock();
175 $string_group->expects(self::once())->method(
'makeClickable')->willReturn($transformation);
177 $refinery = $this->getMockBuilder(Refinery::class)->disableOriginalConstructor()->getMock();
178 $refinery->expects(self::once())->method(
'string')->willReturn($string_group);
180 $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
static provideGotoLinkData()
testMakeClickableWithoutGotoLinks()
ilUtil::makeClickable must call the refinery transformation make clickable.
Customizing of pimple-DIC for ILIAS.
testMakeClickableWithGotoLinksAndInvalidRefId(string $expected, string $input, array $ref_to_obj, array $obj_to_title)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
mockClickableCall(string $input, string $transformed)
static makeClickable(string $a_text, bool $detectGotoLinks=false)