19declare(strict_types=1);
21use PHPUnit\Framework\TestCase;
26use PHPUnit\Framework\MockObject\MockObject;
30 private const string HTTP_HOST =
'http://localhost';
34 protected function setUp(): void
38 $this->original_dic = is_object(
$DIC) ? clone
$DIC :
$DIC;
59 $input =
'Small things make base men proud.';
60 $expected =
'I do desire we may be better strangers.';
67 #[\PHPUnit\Framework\Attributes\DataProvider('provideGotoLinkData')]
78 $cache = $this->getMockBuilder(ilObjectDataCache::class)->disableOriginalConstructor()->getMock();
81 foreach ($ref_to_obj as $k => $v) {
82 $consecutive_id[] = [$k, $v];
85 $cache->expects($this->exactly(count($ref_to_obj)))
86 ->method(
'lookupObjId')
88 function (
$id) use (&$consecutive_id) {
89 [$k, $v] = array_shift($consecutive_id);
90 $this->assertEquals($k,
$id);
95 $consecutive_title = [];
96 foreach ($obj_to_title as $k => $v) {
97 $consecutive_title[] = [$k, $v];
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);
110 $container->expects($this->exactly(count($ref_to_obj)))->method(
'offsetGet')->with(
'ilObjDataCache')->willReturn($cache);
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>.',
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'],
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>.',
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>.',
146 [8 =>
'some course'],
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>.',
152 [8 =>
'some course'],
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>.',
158 [8 =>
'some course'],
163 'With goto.php: ' => [self::HTTP_HOST .
'/goto.php?target=',
''],
164 'With goto_*.html: ' => [self::HTTP_HOST .
'/goto_',
'.html'],
167 $repeatForFormat =
static function (
string $format, array $values): array {
169 ...array_fill(0, (count(explode(
'%s', $format)) - 1) / 2, $values)
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));
188 $transformation = $this->getMockBuilder(Transformation::class)->getMock();
189 $transformation->expects($this->once())->method(
'transform')->with($input)->willReturn($transformed);
191 $string_group = $this->getMockBuilder(StringGroup::class)->disableOriginalConstructor()->getMock();
192 $string_group->expects($this->once())->method(
'makeClickable')->willReturn($transformation);
194 $refinery = $this->getMockBuilder(Refinery::class)->disableOriginalConstructor()->getMock();
195 $refinery->expects($this->once())->method(
'string')->willReturn($string_group);
197 $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Customizing of pimple-DIC for ILIAS.
static provideGotoLinkData()
testMakeClickableWithoutGotoLinks()
ilUtil::makeClickable must call the refinery transformation make clickable.
mockClickableCall(string $input, string $transformed)
testMakeClickableWithGotoLinksAndInvalidRefId(string $expected, string $input, array $ref_to_obj, array $obj_to_title)
static makeClickable(string $a_text, bool $detectGotoLinks=false, ?string $ilias_http_path=null)