ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilWebResourceItemInternalTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
27 class ilWebResourceItemInternalTest extends TestCase
28 {
29  protected function getItem(string $target, ilWebLinkParameter ...$parameters): ilWebLinkItemInternal
30  {
31  $item = $this->getMockBuilder(ilWebLinkItemInternal::class)
32  ->setConstructorArgs([
33  0,
34  1,
35  'title',
36  null,
37  $target,
38  true,
39  new DateTimeImmutable(),
40  new DateTimeImmutable(),
41  $parameters
42  ])
43  ->onlyMethods(['appendParameter'])
44  ->getMock();
45  $item->method('appendParameter')->willReturnCallback(
46  fn(string $link, string $key, string $value) => $link . '.' . $key . '.' . $value
47  );
48  return $item;
49  }
50 
55  public function testGetResolvedLink(): void
56  {
57  $array_util = Mockery::mock('alias:' . ilLink::class);
58  $array_util->shouldReceive('_getStaticLink')
59  ->twice()
60  ->with(13, 'tar')
61  ->andReturn('tar.13');
62  $array_util->shouldReceive('_getStaticLink')
63  ->once()
64  ->with(0, 'wiki', true)
65  ->andReturn('wiki_page');
66  $array_util->shouldReceive('_getStaticLink')
67  ->once()
68  ->with(0, 'git', true)
69  ->andReturn('gl_term');
70  $array_util->shouldReceive('_getStaticLink')
71  ->once()
72  ->with(16, 'pg')
73  ->andReturn('lm_page.16');
74 
75  $param1 = $this->getMockBuilder(ilWebLinkParameter::class)
76  ->disableOriginalConstructor()
77  ->onlyMethods(['appendToLink'])
78  ->getMock();
79  $param1->expects($this->once())
80  ->method('appendToLink')
81  ->with('tar.13')
82  ->willReturn('tar.13?param1');
83  $param2 = $this->getMockBuilder(ilWebLinkParameter::class)
84  ->disableOriginalConstructor()
85  ->onlyMethods(['appendToLink'])
86  ->getMock();
87  $param2->expects($this->once())
88  ->method('appendToLink')
89  ->with('tar.13?param1')
90  ->willReturn('tar.13?param1&param2');
91 
92  $item = $this->getItem('tar|13', $param1, $param2);
93  $this->assertSame(
94  'tar.13?param1&param2',
95  $item->getResolvedLink(true)
96  );
97  $this->assertSame(
98  'tar.13',
99  $item->getResolvedLink(false)
100  );
101 
102  $item = $this->getItem('wpage|14', $param1, $param2);
103  $this->assertSame(
104  'wiki_page.target.wiki_wpage_14',
105  $item->getResolvedLink(false)
106  );
107 
108  $item = $this->getItem('term|15', $param1, $param2);
109  $this->assertSame(
110  'gl_term.target.git_15',
111  $item->getResolvedLink(false)
112  );
113 
114  $item = $this->getItem('page|16', $param1, $param2);
115  $this->assertSame(
116  'lm_page.16',
117  $item->getResolvedLink(false)
118  );
119  }
120 }
getItem(string $target, ilWebLinkParameter ... $parameters)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $key
Consumer key/client ID value.
Definition: System.php:193
Immutable class for internal Web Link items.
Unit tests for ilWebLinkItemInternal.