ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilWebResourceParameterTest Class Reference

Unit tests for ilWebLinkParameter. More...

+ Inheritance diagram for ilWebResourceParameterTest:
+ Collaboration diagram for ilWebResourceParameterTest:

Public Member Functions

 testAppendToLink ()
 
 testAppendToLinkException ()
 
 testToXML ()
 
 testGetInfo ()
 
 testGetInfoException ()
 

Protected Member Functions

 initDependencies ()
 

Detailed Description

Unit tests for ilWebLinkParameter.

Author
Tim Schmitz schmi.nosp@m.tz@l.nosp@m.eifos.nosp@m..com

Definition at line 28 of file ilWebResourceParameterTest.php.

Member Function Documentation

◆ initDependencies()

ilWebResourceParameterTest::initDependencies ( )
protected

Definition at line 30 of file ilWebResourceParameterTest.php.

30  : 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  }

◆ testAppendToLink()

ilWebResourceParameterTest::testAppendToLink ( )

Definition at line 41 of file ilWebResourceParameterTest.php.

References $param, and ilWebLinkBaseParameter\VALUES.

41  : 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 
90  $param = new ilWebLinkParameter(
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  }
Immutable class for parameters attached to Web Link items.
const array VALUES
TODO Once the GUI is updated, undefined can be dropped.
$param
Definition: xapitoken.php:46

◆ testAppendToLinkException()

ilWebResourceParameterTest::testAppendToLinkException ( )

Definition at line 109 of file ilWebResourceParameterTest.php.

References $param.

109  : 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  }
Immutable class for parameters attached to Web Link items.
$param
Definition: xapitoken.php:46

◆ testGetInfo()

ilWebResourceParameterTest::testGetInfo ( )

Definition at line 193 of file ilWebResourceParameterTest.php.

References $param, and ilWebLinkBaseParameter\VALUES.

193  : void
194  {
195  $user = $this->getMockBuilder(ilObjUser::class)
196  ->disableOriginalConstructor()
197  ->getMock();
198  $user->expects($this->never())
199  ->method($this->anything());
200 
202  $user,
203  0,
204  13,
205  7,
207  'name1'
208  );
209  $this->assertSame('name1=USER_ID', $param->getInfo());
211  $user,
212  0,
213  13,
214  8,
216  'name2'
217  );
218  $this->assertSame('name2=LOGIN', $param->getInfo());
219  $param = new ilWebLinkParameter(
220  $user,
221  0,
222  13,
223  9,
224  ilWebLinkBaseParameter::VALUES['matriculation'],
225  'name3'
226  );
227  $this->assertSame('name3=MATRICULATION', $param->getInfo());
228  }
Immutable class for parameters attached to Web Link items.
const array VALUES
TODO Once the GUI is updated, undefined can be dropped.
$param
Definition: xapitoken.php:46

◆ testGetInfoException()

ilWebResourceParameterTest::testGetInfoException ( )

Definition at line 230 of file ilWebResourceParameterTest.php.

References $param.

230  : void
231  {
232  $user = $this->getMockBuilder(ilObjUser::class)
233  ->disableOriginalConstructor()
234  ->getMock();
235  $user->expects($this->never())
236  ->method($this->anything());
237 
238  $param = new ilWebLinkParameter($user, 0, 13, 7, 374, 'name1');
239  $this->expectException(ilWebLinkParameterException::class);
240  $param->getInfo();
241  }
Immutable class for parameters attached to Web Link items.
$param
Definition: xapitoken.php:46

◆ testToXML()

ilWebResourceParameterTest::testToXML ( )

Definition at line 123 of file ilWebResourceParameterTest.php.

References $param, and ilWebLinkBaseParameter\VALUES.

123  : 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  /*
136  * willReturnCallback is a workaround to replace withConsecutive.
137  * The return value is irrelevant here, but if an unexpected parameter
138  * is passed, an exception will be thrown (instead of an assumption being
139  * broken as before).
140  * These tests should be rewritten to rely much less on PHPUnit for mocking.
141  */
142  $writer->expects($this->exactly(3))
143  ->method('xmlElement')
144  ->willReturnCallback(fn($tag, $attrs) => match([$tag, $attrs]) {
145  ['DynamicParameter', [
146  'id' => 7,
147  'name' => 'name1',
148  'type' => 'userId'
149  ]] => 1,
150  ['DynamicParameter', [
151  'id' => 8,
152  'name' => 'name2',
153  'type' => 'userName'
154  ]] => 2,
155  ['DynamicParameter', [
156  'id' => 9,
157  'name' => 'name3',
158  'type' => 'matriculation'
159  ]] => 3
160  });
161 
163  $user,
164  0,
165  13,
166  7,
168  'name1'
169  );
170  $param->toXML($writer);
172  $user,
173  0,
174  13,
175  8,
177  'name2'
178  );
179  $param->toXML($writer);
181  $user,
182  0,
183  13,
184  9,
185  ilWebLinkBaseParameter::VALUES['matriculation'],
186  'name3'
187  );
188  $param->toXML($writer);
189  $param = new ilWebLinkParameter($user, 0, 13, 9, 987, 'name3');
190  $param->toXML($writer);
191  }
Immutable class for parameters attached to Web Link items.
const array VALUES
TODO Once the GUI is updated, undefined can be dropped.
$param
Definition: xapitoken.php:46

The documentation for this class was generated from the following file: