ILIAS  release_8 Revision v8.24
ilWebResourceParameterTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use PHPUnit\Framework\TestCase;
23
28class ilWebResourceParameterTest extends TestCase
29{
30 protected function initDependencies(): void
31 {
32 $user = $this->getMockBuilder(ilObjUser::class)
33 ->disableOriginalConstructor()
34 ->onlyMethods(['getLogin', 'getId', 'getMatriculation'])
35 ->getMock();
36 $user->method('getLogin')->willReturn('login');
37 $user->method('getId')->willReturn(37);
38 $user->method('getMatriculation')->willReturn('matriculation');
39 }
40
41 public function testAppendToLink(): void
42 {
43 $user = $this->getMockBuilder(ilObjUser::class)
44 ->disableOriginalConstructor()
45 ->onlyMethods(['getLogin', 'getId', 'getMatriculation'])
46 ->getMock();
47 $user->method('getLogin')->willReturn('login');
48 $user->method('getId')->willReturn(37);
49 $user->method('getMatriculation')->willReturn('matriculation');
50
51 $link1 = 'link';
52 $link2 = 'li?nk';
53
55 $user,
56 3,
57 7,
58 13,
60 'name'
61 );
62
63 $this->assertSame(
64 'link?name=37',
65 $param->appendToLink($link1)
66 );
67 $this->assertSame(
68 'li?nk&name=37',
69 $param->appendToLink($link2)
70 );
71
73 $user,
74 3,
75 7,
76 13,
78 'name'
79 );
80
81 $this->assertSame(
82 'link?name=login',
83 $param->appendToLink($link1)
84 );
85 $this->assertSame(
86 'li?nk&name=login',
87 $param->appendToLink($link2)
88 );
89
91 $user,
92 3,
93 7,
94 13,
95 ilWebLinkBaseParameter::VALUES['matriculation'],
96 'name'
97 );
98
99 $this->assertSame(
100 'link?name=matriculation',
101 $param->appendToLink($link1)
102 );
103 $this->assertSame(
104 'li?nk&name=matriculation',
105 $param->appendToLink($link2)
106 );
107 }
108
109 public function testAppendToLinkException(): void
110 {
111 $user = $this->getMockBuilder(ilObjUser::class)
112 ->disableOriginalConstructor()
113 ->getMock();
114 $user->expects($this->never())
115 ->method($this->anything());
116
117 $link = 'link';
118 $param = new ilWebLinkParameter($user, 3, 7, 13, 1241, 'name');
119 $this->expectException(ilWebLinkParameterException::class);
120 $param->appendToLink($link);
121 }
122
123 public function testToXML(): void
124 {
125 $user = $this->getMockBuilder(ilObjUser::class)
126 ->disableOriginalConstructor()
127 ->getMock();
128 $user->expects($this->never())
129 ->method($this->anything());
130
131 $writer = $this->getMockBuilder(ilXmlWriter::class)
132 ->disableOriginalConstructor()
133 ->onlyMethods(['xmlElement'])
134 ->getMock();
135 $writer->expects($this->exactly(3))
136 ->method('xmlElement')
137 ->withConsecutive(
138 ['DynamicParameter', [
139 'id' => 7,
140 'name' => 'name1',
141 'type' => 'userId'
142 ]],
143 ['DynamicParameter', [
144 'id' => 8,
145 'name' => 'name2',
146 'type' => 'userName'
147 ]],
148 ['DynamicParameter', [
149 'id' => 9,
150 'name' => 'name3',
151 'type' => 'matriculation'
152 ]]
153 );
154
156 $user,
157 0,
158 13,
159 7,
161 'name1'
162 );
163 $param->toXML($writer);
165 $user,
166 0,
167 13,
168 8,
170 'name2'
171 );
172 $param->toXML($writer);
174 $user,
175 0,
176 13,
177 9,
178 ilWebLinkBaseParameter::VALUES['matriculation'],
179 'name3'
180 );
181 $param->toXML($writer);
182 $param = new ilWebLinkParameter($user, 0, 13, 9, 987, 'name3');
183 $param->toXML($writer);
184 }
185
186 public function testGetInfo(): void
187 {
188 $user = $this->getMockBuilder(ilObjUser::class)
189 ->disableOriginalConstructor()
190 ->getMock();
191 $user->expects($this->never())
192 ->method($this->anything());
193
195 $user,
196 0,
197 13,
198 7,
200 'name1'
201 );
202 $this->assertSame('name1=USER_ID', $param->getInfo());
204 $user,
205 0,
206 13,
207 8,
209 'name2'
210 );
211 $this->assertSame('name2=LOGIN', $param->getInfo());
213 $user,
214 0,
215 13,
216 9,
217 ilWebLinkBaseParameter::VALUES['matriculation'],
218 'name3'
219 );
220 $this->assertSame('name3=MATRICULATION', $param->getInfo());
222 $user,
223 0,
224 13,
225 9,
226 ilWebLinkBaseParameter::VALUES['session_id'],
227 'name4'
228 );
229 $this->assertSame('name4=SESSION_ID', $param->getInfo());
230 }
231
232 public function testGetInfoException(): void
233 {
234 $user = $this->getMockBuilder(ilObjUser::class)
235 ->disableOriginalConstructor()
236 ->getMock();
237 $user->expects($this->never())
238 ->method($this->anything());
239
240 $param = new ilWebLinkParameter($user, 0, 13, 7, 374, 'name1');
241 $this->expectException(ilWebLinkParameterException::class);
242 $param->getInfo();
243 }
244}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
const VALUES
TODO Once the GUI is updated, undefined can be dropped.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Unit tests for ilWebLinkParameter.
$param
Definition: xapitoken.php:46