ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilTermsOfServiceAcceptanceHistoryCriteriaBagTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
14  {
15  $configCrit1 = $this->getMockBuilder(\ilTermsOfServiceCriterionConfig::class)->getMock();
16 
17  $configCrit1
18  ->expects($this->any())
19  ->method('jsonSerialize')
20  ->willReturn([
21  'usr_language' => 'de'
22  ]);
23 
24  $configCrit2 = $this->getMockBuilder(\ilTermsOfServiceCriterionConfig::class)->getMock();
25 
26  $configCrit2
27  ->expects($this->any())
28  ->method('jsonSerialize')
29  ->willReturn([
30  'usr_global_role' => 4
31  ]);
32 
33  $criterion1 = $this->getMockBuilder(\ilTermsOfServiceEvaluableCriterion::class)->getMock();
34 
35  $criterion1
36  ->expects($this->any())
37  ->method('getCriterionId')
38  ->willReturn('crit1');
39 
40  $criterion1
41  ->expects($this->any())
42  ->method('getCriterionValue')
43  ->willReturn($configCrit1);
44 
45  $criterion2 = $this->getMockBuilder(\ilTermsOfServiceEvaluableCriterion::class)->getMock();
46 
47  $criterion2
48  ->expects($this->any())
49  ->method('getCriterionId')
50  ->willReturn('crit2');
51 
52  $criterion2
53  ->expects($this->any())
54  ->method('getCriterionValue')
55  ->willReturn($configCrit2);
56 
57  $data = [
58  $criterion1, $criterion2
59  ];
60 
61  $bag = new \ilTermsOfServiceAcceptanceHistoryCriteriaBag($data);
62 
63  $this->assertCount(count($data), $bag);
64  $this->assertArrayHasKey(0, $bag);
65  $this->assertArrayHasKey(1, $bag);
66  $this->assertArrayHasKey('id', $bag[0]);
67  $this->assertArrayHasKey('value', $bag[0]);
68  $this->assertArrayHasKey('id', $bag[1]);
69  $this->assertArrayHasKey('value', $bag[1]);
70  $this->assertEquals(
71  '[{"id":"crit1","value":{"usr_language":"de"}},{"id":"crit2","value":{"usr_global_role":4}}]',
72  $bag->toJson()
73  );
74  }
75 
80  {
81  $configCrit1 = $this->getMockBuilder(\ilTermsOfServiceCriterionConfig::class)->getMock();
82 
83  $criterion1 = $this->getMockBuilder(\ilTermsOfServiceEvaluableCriterion::class)->getMock();
84 
85  $criterion1
86  ->expects($this->any())
87  ->method('getCriterionId')
88  ->willReturn('crit1');
89 
90  $criterion1
91  ->expects($this->any())
92  ->method('getCriterionValue')
93  ->willReturn($configCrit1);
94 
95  $this->assertException(\ilTermsOfServiceUnexpectedCriteriaBagContentException::class);
96 
97  new \ilTermsOfServiceAcceptanceHistoryCriteriaBag([
98  $criterion1, 5
99  ]);
100  }
101 
106  {
107  $configCrit1 = $this->getMockBuilder(\ilTermsOfServiceCriterionConfig::class)->getMock();
108 
109  $criterion1 = $this->getMockBuilder(\ilTermsOfServiceEvaluableCriterion::class)->getMock();
110 
111  $criterion1
112  ->expects($this->any())
113  ->method('getCriterionId')
114  ->willReturn('crit1');
115 
116  $criterion1
117  ->expects($this->any())
118  ->method('getCriterionValue')
119  ->willReturn($configCrit1);
120 
121  $this->assertException(\ilTermsOfServiceUnexpectedCriteriaBagContentException::class);
122 
123  $bag = new \ilTermsOfServiceAcceptanceHistoryCriteriaBag();
124  $bag->fromJson('5');
125  }
126 
131  {
132  $configCrit1 = $this->getMockBuilder(\ilTermsOfServiceCriterionConfig::class)->getMock();
133 
134  $criterion1 = $this->getMockBuilder(\ilTermsOfServiceEvaluableCriterion::class)->getMock();
135 
136  $criterion1
137  ->expects($this->any())
138  ->method('getCriterionId')
139  ->willReturn('crit1');
140 
141  $criterion1
142  ->expects($this->any())
143  ->method('getCriterionValue')
144  ->willReturn($configCrit1);
145 
146  $this->assertException(\ilTermsOfServiceUnexpectedCriteriaBagContentException::class);
147 
148  $bag = new \ilTermsOfServiceAcceptanceHistoryCriteriaBag();
149  $bag->fromJson('[{"invalid":"crit1","value":{"usr_language":"de"}},{"id":"crit2","value":{"usr_global_role":4}}]');
150  }
151 
156  {
157  $bag = new \ilTermsOfServiceAcceptanceHistoryCriteriaBag();
158  $bag->fromJson('[{"id":"crit1","value":{"usr_language":"de"}},{"id":"crit2","value":{"usr_global_role":4}}]');
159 
160  $this->assertCount(count($bag), $bag);
161  $this->assertArrayHasKey(0, $bag);
162  $this->assertArrayHasKey(1, $bag);
163  $this->assertArrayHasKey('id', $bag[0]);
164  $this->assertArrayHasKey('value', $bag[0]);
165  $this->assertArrayHasKey('id', $bag[1]);
166  $this->assertArrayHasKey('value', $bag[1]);
167  $this->assertEquals(
168  '[{"id":"crit1","value":{"usr_language":"de"}},{"id":"crit2","value":{"usr_global_role":4}}]',
169  $bag->toJson()
170  );
171  }
172 }
assertException(string $exceptionClass)
Class ilTermsOfServiceBaseTest.
Class ilTermsOfServiceAcceptanceHistoryCriteriaBagTest.
$data
Definition: bench.php:6