ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilWebResourceParameterTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
23
28class ilWebResourceParameterTest extends TestCase
29{
30 protected function initDependencies(): void
31 {
32 $user = $this->createStub(ilObjUser::class);
33 $user->method('getLogin')->willReturn('login');
34 $user->method('getId')->willReturn(37);
35 $user->method('getMatriculation')->willReturn('matriculation');
36 }
37
38 public function testAppendToLink(): void
39 {
40 $user = $this->createStub(ilObjUser::class);
41 $user->method('getLogin')->willReturn('login');
42 $user->method('getId')->willReturn(37);
43 $user->method('getMatriculation')->willReturn('matriculation');
44
45 $link1 = 'link';
46 $link2 = 'li?nk';
47
49 $user,
50 3,
51 7,
52 13,
54 'name'
55 );
56
57 $this->assertSame(
58 'link?name=37',
59 $param->appendToLink($link1)
60 );
61 $this->assertSame(
62 'li?nk&name=37',
63 $param->appendToLink($link2)
64 );
65
67 $user,
68 3,
69 7,
70 13,
72 'name'
73 );
74
75 $this->assertSame(
76 'link?name=login',
77 $param->appendToLink($link1)
78 );
79 $this->assertSame(
80 'li?nk&name=login',
81 $param->appendToLink($link2)
82 );
83
85 $user,
86 3,
87 7,
88 13,
89 ilWebLinkBaseParameter::VALUES['matriculation'],
90 'name'
91 );
92
93 $this->assertSame(
94 'link?name=matriculation',
95 $param->appendToLink($link1)
96 );
97 $this->assertSame(
98 'li?nk&name=matriculation',
99 $param->appendToLink($link2)
100 );
101 }
102
103 public function testAppendToLinkException(): void
104 {
105 $user = $this->createMock(ilObjUser::class);
106 $user->expects($this->never())
107 ->method($this->anything());
108
109 $link = 'link';
110 $param = new ilWebLinkParameter($user, 3, 7, 13, 1241, 'name');
111 $this->expectException(ilWebLinkParameterException::class);
112 $param->appendToLink($link);
113 }
114
115 public function testToXML(): void
116 {
117 $user = $this->createMock(ilObjUser::class);
118 $user->expects($this->never())
119 ->method($this->anything());
120
121 $writer = $this->createMock(ilXmlWriter::class);
122 /*
123 * willReturnCallback is a workaround to replace withConsecutive.
124 * The return value is irrelevant here, but if an unexpected parameter
125 * is passed, an exception will be thrown (instead of an assumption being
126 * broken as before).
127 * These tests should be rewritten to rely much less on PHPUnit for mocking.
128 */
129 $writer->expects($this->exactly(3))
130 ->method('xmlElement')
131 ->willReturnCallback(fn($tag, $attrs) => match([$tag, $attrs]) {
132 ['DynamicParameter', [
133 'id' => 7,
134 'name' => 'name1',
135 'type' => 'userId'
136 ]] => 1,
137 ['DynamicParameter', [
138 'id' => 8,
139 'name' => 'name2',
140 'type' => 'userName'
141 ]] => 2,
142 ['DynamicParameter', [
143 'id' => 9,
144 'name' => 'name3',
145 'type' => 'matriculation'
146 ]] => 3
147 });
148
150 $user,
151 0,
152 13,
153 7,
155 'name1'
156 );
157 $param->toXML($writer);
159 $user,
160 0,
161 13,
162 8,
164 'name2'
165 );
166 $param->toXML($writer);
168 $user,
169 0,
170 13,
171 9,
172 ilWebLinkBaseParameter::VALUES['matriculation'],
173 'name3'
174 );
175 $param->toXML($writer);
176 $param = new ilWebLinkParameter($user, 0, 13, 9, 987, 'name3');
177 $param->toXML($writer);
178 }
179
180 public function testGetInfo(): void
181 {
182 $user = $this->createMock(ilObjUser::class);
183 $user->expects($this->never())
184 ->method($this->anything());
185
187 $user,
188 0,
189 13,
190 7,
192 'name1'
193 );
194 $this->assertSame('name1=USER_ID', $param->getInfo());
196 $user,
197 0,
198 13,
199 8,
201 'name2'
202 );
203 $this->assertSame('name2=LOGIN', $param->getInfo());
205 $user,
206 0,
207 13,
208 9,
209 ilWebLinkBaseParameter::VALUES['matriculation'],
210 'name3'
211 );
212 $this->assertSame('name3=MATRICULATION', $param->getInfo());
213 }
214
215 public function testGetInfoException(): void
216 {
217 $user = $this->createMock(ilObjUser::class);
218 $user->expects($this->never())
219 ->method($this->anything());
220
221 $param = new ilWebLinkParameter($user, 0, 13, 7, 374, 'name1');
222 $this->expectException(ilWebLinkParameterException::class);
223 $param->getInfo();
224 }
225}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:38
const array VALUES
TODO Once the GUI is updated, undefined can be dropped.
Immutable class for parameters attached to Web Link items.
Unit tests for ilWebLinkParameter.
$param
Definition: xapitoken.php:44