ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilTermsOfServiceDocumentTest Class Reference

Class ilTermsOfServiceDocumentTest. More...

+ Inheritance diagram for ilTermsOfServiceDocumentTest:
+ Collaboration diagram for ilTermsOfServiceDocumentTest:

Public Member Functions

 criteriaAssignmentProvider ()
 
 testDocumentModelCanBeBuiltFromArrayWithAttachedCriteriaBeingRead (\ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment1, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment2, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment3)
 criteriaAssignmentProvider More...
 
 testDocumentModelCanCreatedByIdWithAttachedCriteriaBeingRead (\ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment1, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment2, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment3)
 criteriaAssignmentProvider More...
 
 testCriteriaCanBeAttachedToDocument (\ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment1, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment2, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment3)
 criteriaAssignmentProvider More...
 
 testCriteriaCanBeDetachedFromDocument (\ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment1, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment2, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment3)
 criteriaAssignmentProvider More...
 
 testCriteriaCanBeAttachedToAndDetachedFromDocumentPersistently (\ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment1, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment2, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment3)
 criteriaAssignmentProvider More...
 
 testExceptionIsRaisedWhenAttachingDuplicateCriteria ()
 
 testExceptionIsRaisedWhenAttachingDuplicateCriteriaEvenWithDifferentIds ()
 
 testExceptionIsRaisedWhenRemovingUnknownCriterion ()
 

Additional Inherited Members

- Protected Member Functions inherited from ilTermsOfServiceCriterionBaseTest
 getRbacReviewMock ()
 
 getObjectDataCacheMock ()
 
 getRadioGroupMock ()
 
 getFormMock ()
 
 getUserMock ()
 
- Protected Member Functions inherited from ilTermsOfServiceBaseTest
 setUp ()
 
 getLanguageMock ()
 
 setGlobalVariable (string $name, $value)
 
 assertException (string $exceptionClass)
 
 getCriterionConfig ($value=null)
 
- Protected Attributes inherited from ilTermsOfServiceBaseTest
 $dic
 

Detailed Description

Member Function Documentation

◆ criteriaAssignmentProvider()

ilTermsOfServiceDocumentTest::criteriaAssignmentProvider ( )
Returns
array

Definition at line 13 of file ilTermsOfServiceDocumentTest.php.

References ilTermsOfServiceBaseTest\getCriterionConfig().

13  : array
14  {
15  $criterionAssignment1 = $this
16  ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
17  ->disableOriginalConstructor()
18  ->setMethods(['getId', 'getCriterionValue', 'getCriterionId', 'store', 'delete'])
19  ->getMock();
20 
21  $criterionAssignment1
22  ->expects($this->any())
23  ->method('getId')
24  ->willReturn(1);
25 
26  $criterionAssignment1
27  ->expects($this->any())
28  ->method('getCriterionId')
29  ->willReturn('usr_global_role');
30 
31  $criterionAssignment1
32  ->expects($this->any())
33  ->method('getCriterionValue')
34  ->willReturn($this->getCriterionConfig(['role_id' => 4]));
35 
36  $criterionAssignment2 = $this
37  ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
38  ->disableOriginalConstructor()
39  ->setMethods(['getId', 'getCriterionValue', 'getCriterionId', 'store', 'delete'])
40  ->getMock();
41 
42  $criterionAssignment2
43  ->expects($this->any())
44  ->method('getId')
45  ->willReturn(2);
46 
47  $criterionAssignment2
48  ->expects($this->any())
49  ->method('getCriterionId')
50  ->willReturn('usr_language');
51 
52  $criterionAssignment2
53  ->expects($this->any())
54  ->method('getCriterionValue')
55  ->willReturn($this->getCriterionConfig(['lng' => 'de']));
56 
57  $criterionAssignment3 = $this
58  ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
59  ->disableOriginalConstructor()
60  ->setMethods(['getId', 'getCriterionValue', 'getCriterionId', 'store', 'delete'])
61  ->getMock();
62 
63  $criterionAssignment3
64  ->expects($this->any())
65  ->method('getId')
66  ->willReturn(3);
67 
68  $criterionAssignment3
69  ->expects($this->any())
70  ->method('getCriterionId')
71  ->willReturn('usr_global_role');
72 
73  $criterionAssignment3
74  ->expects($this->any())
75  ->method('getCriterionValue')
76  ->willReturn($this->getCriterionConfig(['role_id' => 6]));
77 
78  return [
79  [$criterionAssignment1, $criterionAssignment2, $criterionAssignment3]
80  ];
81  }
+ Here is the call graph for this function:

◆ testCriteriaCanBeAttachedToAndDetachedFromDocumentPersistently()

ilTermsOfServiceDocumentTest::testCriteriaCanBeAttachedToAndDetachedFromDocumentPersistently ( \ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment1,
\ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment2,
\ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment3 
)

criteriaAssignmentProvider

Parameters
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment1
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment2
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment3

Definition at line 242 of file ilTermsOfServiceDocumentTest.php.

References Sabre\Event\once(), arConnectorMap\register(), and ActiveRecord\store().

246  {
247  $documentConnector = $this->getMockBuilder(\arConnector::class)->getMock();
248 
249  $document = new \ilTermsOfServiceDocument();
250 
251  $documentConnector
252  ->expects($this->exactly(2))
253  ->method('affectedRows')
254  ->willReturnOnConsecutiveCalls(0, 1);
255 
256  $documentConnector
257  ->expects($this->once())
258  ->method('nextId')
259  ->willReturn(1);
260 
261  $documentConnector
262  ->expects($this->once())
263  ->method('create');
264 
265  \arConnectorMap::register($document, $documentConnector);
266 
267  $document->attachCriterion($criterionAssignment1);
268  $document->attachCriterion($criterionAssignment2);
269  $document->attachCriterion($criterionAssignment3);
270 
271  $criterionAssignment1
272  ->expects($this->exactly(2))
273  ->method('store');
274 
275  $criterionAssignment1
276  ->expects($this->once())
277  ->method('delete');
278 
279  $criterionAssignment2
280  ->expects($this->once())
281  ->method('store');
282 
283  $criterionAssignment2
284  ->expects($this->once())
285  ->method('delete');
286 
287  $criterionAssignment3
288  ->expects($this->exactly(2))
289  ->method('store');
290 
291  $criterionAssignment3
292  ->expects($this->once())
293  ->method('delete');
294 
295  $this->assertCount(3, $document->criteria());
296 
297  $document->store(); // 1 / 2 / 3
298 
299  $document->detachCriterion($criterionAssignment2);
300 
301  $document->store(); // 1 / 3
302 
303  $this->assertCount(2, $document->criteria());
304 
305  $document->detachCriterion($criterionAssignment1);
306  $document->detachCriterion($criterionAssignment3);
307 
308  $this->assertCount(0, $document->criteria());
309 
310  $document->delete();
311  }
static register(ActiveRecord $ar, arConnector $connector)
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testCriteriaCanBeAttachedToDocument()

ilTermsOfServiceDocumentTest::testCriteriaCanBeAttachedToDocument ( \ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment1,
\ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment2,
\ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment3 
)

criteriaAssignmentProvider

Parameters
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment1
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment2
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment3

Definition at line 200 of file ilTermsOfServiceDocumentTest.php.

204  {
205  $document = new \ilTermsOfServiceDocument();
206  $document->attachCriterion($criterionAssignment1);
207  $document->attachCriterion($criterionAssignment2);
208  $document->attachCriterion($criterionAssignment3);
209 
210  $this->assertCount(3, $document->criteria());
211  }

◆ testCriteriaCanBeDetachedFromDocument()

ilTermsOfServiceDocumentTest::testCriteriaCanBeDetachedFromDocument ( \ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment1,
\ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment2,
\ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment3 
)

criteriaAssignmentProvider

Parameters
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment1
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment2
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment3

Definition at line 219 of file ilTermsOfServiceDocumentTest.php.

223  {
224  $document = new \ilTermsOfServiceDocument();
225  $document->attachCriterion($criterionAssignment1);
226  $document->attachCriterion($criterionAssignment2);
227  $document->attachCriterion($criterionAssignment3);
228 
229  $this->assertCount(3, $document->criteria());
230 
231  $document->detachCriterion($criterionAssignment2);
232 
233  $this->assertCount(2, $document->criteria());
234  }

◆ testDocumentModelCanBeBuiltFromArrayWithAttachedCriteriaBeingRead()

ilTermsOfServiceDocumentTest::testDocumentModelCanBeBuiltFromArrayWithAttachedCriteriaBeingRead ( \ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment1,
\ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment2,
\ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment3 
)

criteriaAssignmentProvider

Parameters
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment1
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment2
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment3

Definition at line 89 of file ilTermsOfServiceDocumentTest.php.

References ilTermsOfServiceDocumentCriterionAssignment\getCriterionId(), ilTermsOfServiceDocumentCriterionAssignment\getCriterionValue(), Sabre\Event\once(), and arConnectorMap\register().

93  {
94  $documentConnector = $this->getMockBuilder(\arConnector::class)->getMock();
95  $criterionConnector = $this->getMockBuilder(\arConnector::class)->getMock();
96 
97  $criterionConnector
98  ->expects($this->once())
99  ->method('readSet')
100  ->willReturnCallback(function () use ($criterionAssignment1, $criterionAssignment2, $criterionAssignment3) {
101  return [[
102  'id' => $criterionAssignment1->getId(),
103  'doc_id' => 4711,
104  'criterion_id' => $criterionAssignment1->getCriterionId(),
105  'criterion_value' => $criterionAssignment1->getCriterionValue(),
106  ], [
107  'id' => $criterionAssignment2->getId(),
108  'doc_id' => 4711,
109  'criterion_id' => $criterionAssignment2->getCriterionId(),
110  'criterion_value' => $criterionAssignment2->getCriterionValue(),
111  ], [
112  'id' => $criterionAssignment3->getId(),
113  'doc_id' => 4711,
114  'criterion_id' => $criterionAssignment3->getCriterionId(),
115  'criterion_value' => $criterionAssignment3->getCriterionValue(),
116  ]];
117  });
118 
119  \arConnectorMap::register(new \ilTermsOfServiceDocument(), $documentConnector);
121 
122  $document = new \ilTermsOfServiceDocument();
123 
124  $document->buildFromArray([
125  'id' => 4711,
126  'title' => 'phpunit',
127  ]);
128 
129  $this->assertCount(3, $document->criteria());
130  }
static register(ActiveRecord $ar, arConnector $connector)
Class ilTermsOfServiceDocument.
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testDocumentModelCanCreatedByIdWithAttachedCriteriaBeingRead()

ilTermsOfServiceDocumentTest::testDocumentModelCanCreatedByIdWithAttachedCriteriaBeingRead ( \ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment1,
\ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment2,
\ilTermsOfServiceDocumentCriterionAssignment  $criterionAssignment3 
)

criteriaAssignmentProvider

Parameters
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment1
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment2
ilTermsOfServiceDocumentCriterionAssignment$criterionAssignment3

Definition at line 138 of file ilTermsOfServiceDocumentTest.php.

References ilTermsOfServiceDocumentCriterionAssignment\getCriterionId(), ilTermsOfServiceDocumentCriterionAssignment\getCriterionValue(), Sabre\Event\once(), and arConnectorMap\register().

142  {
143  $documentConnector = $this->getMockBuilder(\arConnector::class)->getMock();
144  $criterionConnector = $this->getMockBuilder(\arConnector::class)->getMock();
145 
146  $documentConnector
147  ->expects($this->once())
148  ->method('read')
149  ->willReturnCallback(function () {
150  $object = new stdClass();
151 
152  $object->id = 4711;
153  $object->title = 'phpunit';
154  $object->creation_ts = time();
155  $object->modification_ts = time();
156  $object->owner_usr_id = 6;
157  $object->last_modified_usr_id = 6;
158  $object->sorting = 10;
159  $object->text = 'HelloWorld';
160 
161  return [$object];
162  });
163 
164  $criterionConnector
165  ->expects($this->once())
166  ->method('readSet')
167  ->willReturnCallback(function () use ($criterionAssignment1, $criterionAssignment2, $criterionAssignment3) {
168  return [[
169  'id' => $criterionAssignment1->getId(),
170  'doc_id' => 4711,
171  'criterion_id' => $criterionAssignment1->getCriterionId(),
172  'criterion_value' => $criterionAssignment1->getCriterionValue(),
173  ], [
174  'id' => $criterionAssignment2->getId(),
175  'doc_id' => 4711,
176  'criterion_id' => $criterionAssignment2->getCriterionId(),
177  'criterion_value' => $criterionAssignment2->getCriterionValue(),
178  ], [
179  'id' => $criterionAssignment3->getId(),
180  'doc_id' => 4711,
181  'criterion_id' => $criterionAssignment3->getCriterionId(),
182  'criterion_value' => $criterionAssignment3->getCriterionValue(),
183  ]];
184  });
185 
186  \arConnectorMap::register(new \ilTermsOfServiceDocument(), $documentConnector);
188 
189  $document = new \ilTermsOfServiceDocument(4711);
190 
191  $this->assertCount(3, $document->criteria());
192  }
static register(ActiveRecord $ar, arConnector $connector)
Class ilTermsOfServiceDocument.
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testExceptionIsRaisedWhenAttachingDuplicateCriteria()

ilTermsOfServiceDocumentTest::testExceptionIsRaisedWhenAttachingDuplicateCriteria ( )

Definition at line 316 of file ilTermsOfServiceDocumentTest.php.

References ilTermsOfServiceBaseTest\assertException(), and ilTermsOfServiceBaseTest\getCriterionConfig().

317  {
318  $this->assertException(\ilTermsOfServiceDuplicateCriterionAssignmentException::class);
319 
320  $criterionAssignment1 = $this
321  ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
322  ->disableOriginalConstructor()
323  ->setMethods(['getId', 'getCriterionValue', 'getCriterionId'])
324  ->getMock();
325 
326  $criterionAssignment1
327  ->expects($this->any())
328  ->method('getId')
329  ->willReturn(0);
330 
331  $criterionAssignment1
332  ->expects($this->any())
333  ->method('getCriterionId')
334  ->willReturn('usr_global_role');
335 
336  $criterionAssignment1
337  ->expects($this->any())
338  ->method('getCriterionValue')
339  ->willReturn($this->getCriterionConfig(['role_id' => 4]));
340 
341  $criterionAssignment2 = $this
342  ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
343  ->disableOriginalConstructor()
344  ->setMethods(['getId', 'getCriterionValue', 'getCriterionId'])
345  ->getMock();
346 
347  $criterionAssignment2
348  ->expects($this->any())
349  ->method('getId')
350  ->willReturn(0);
351 
352  $criterionAssignment2
353  ->expects($this->any())
354  ->method('getCriterionId')
355  ->willReturn('usr_global_role');
356 
357  $criterionAssignment2
358  ->expects($this->any())
359  ->method('getCriterionValue')
360  ->willReturn($this->getCriterionConfig(['role_id' => 4]));
361 
362  $document = new \ilTermsOfServiceDocument();
363 
364  $document->attachCriterion($criterionAssignment1);
365  $document->attachCriterion($criterionAssignment2);
366  }
assertException(string $exceptionClass)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedWhenAttachingDuplicateCriteriaEvenWithDifferentIds()

ilTermsOfServiceDocumentTest::testExceptionIsRaisedWhenAttachingDuplicateCriteriaEvenWithDifferentIds ( )

Definition at line 371 of file ilTermsOfServiceDocumentTest.php.

References ilTermsOfServiceBaseTest\assertException(), and ilTermsOfServiceBaseTest\getCriterionConfig().

372  {
373  $this->assertException(\ilTermsOfServiceDuplicateCriterionAssignmentException::class);
374 
375  $criterionAssignment1 = $this
376  ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
377  ->disableOriginalConstructor()
378  ->setMethods(['getId', 'getCriterionValue', 'getCriterionId'])
379  ->getMock();
380 
381  $criterionAssignment1
382  ->expects($this->any())
383  ->method('getId')
384  ->willReturn(1);
385 
386  $criterionAssignment1
387  ->expects($this->any())
388  ->method('getCriterionId')
389  ->willReturn('usr_global_role');
390 
391  $criterionAssignment1
392  ->expects($this->any())
393  ->method('getCriterionValue')
394  ->willReturn($this->getCriterionConfig(['role_id' => 4]));
395 
396  $criterionAssignment2 = $this
397  ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
398  ->disableOriginalConstructor()
399  ->setMethods(['getId', 'getCriterionValue', 'getCriterionId'])
400  ->getMock();
401 
402  $criterionAssignment2
403  ->expects($this->any())
404  ->method('getId')
405  ->willReturn(2);
406 
407  $criterionAssignment2
408  ->expects($this->any())
409  ->method('getCriterionId')
410  ->willReturn('usr_global_role');
411 
412  $criterionAssignment2
413  ->expects($this->any())
414  ->method('getCriterionValue')
415  ->willReturn($this->getCriterionConfig(['role_id' => 4]));
416 
417  $document = new \ilTermsOfServiceDocument();
418 
419  $document->attachCriterion($criterionAssignment1);
420  $document->attachCriterion($criterionAssignment2);
421  }
assertException(string $exceptionClass)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedWhenRemovingUnknownCriterion()

ilTermsOfServiceDocumentTest::testExceptionIsRaisedWhenRemovingUnknownCriterion ( )

Definition at line 426 of file ilTermsOfServiceDocumentTest.php.

References ilTermsOfServiceBaseTest\assertException(), and ilTermsOfServiceBaseTest\getCriterionConfig().

427  {
428  $this->assertException(\OutOfBoundsException::class);
429 
430  $criterionAssignment1 = $this
431  ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
432  ->disableOriginalConstructor()
433  ->setMethods(['getId', 'getCriterionValue', 'getCriterionId'])
434  ->getMock();
435 
436  $criterionAssignment1
437  ->expects($this->any())
438  ->method('getId')
439  ->willReturn(1);
440 
441  $criterionAssignment1
442  ->expects($this->any())
443  ->method('getCriterionId')
444  ->willReturn('usr_global_role');
445 
446  $criterionAssignment1
447  ->expects($this->any())
448  ->method('getCriterionValue')
449  ->willReturn($this->getCriterionConfig(['role_id' => 4]));
450 
451  $document = new \ilTermsOfServiceDocument();
452 
453  $document->detachCriterion($criterionAssignment1);
454  }
assertException(string $exceptionClass)
+ Here is the call graph for this function:

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