ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTermsOfServiceHelperTest Class Reference

Class ilTermsOfServiceHelperTest. More...

+ Inheritance diagram for ilTermsOfServiceHelperTest:
+ Collaboration diagram for ilTermsOfServiceHelperTest:

Public Member Functions

 testDocumentCanBeAccepted ()
 
 testAcceptanceHistoryCanBeDeleted ()
 
 testLatestAcceptanceHistoryEntityCanBeLoadedForUser ()
 
 testAcceptanceHistoryEntityCanBeLoadedById ()
 

Additional Inherited Members

- Protected Member Functions inherited from ilTermsOfServiceBaseTest
 setUp ()
 
 getLanguageMock ()
 
 getUiFactoryMock ()
 
 setGlobalVariable (string $name, $value)
 
 getCriterionConfig ($value=null)
 
- Protected Attributes inherited from ilTermsOfServiceBaseTest
 $dic
 

Detailed Description

Member Function Documentation

◆ testAcceptanceHistoryCanBeDeleted()

ilTermsOfServiceHelperTest::testAcceptanceHistoryCanBeDeleted ( )
Exceptions
ilTermsOfServiceMissingDatabaseAdapterException
ReflectionException

Definition at line 97 of file ilTermsOfServiceHelperTest.php.

97  : void
98  {
99  $dataGatewayFactory = $this->getMockBuilder(ilTermsOfServiceDataGatewayFactory::class)->getMock();
100  $dataGateway = $this
101  ->getMockBuilder(ilTermsOfServiceAcceptanceDataGateway::class)
102  ->getMock();
103 
104  $dataGateway
105  ->expects($this->once())
106  ->method('deleteAcceptanceHistoryByUser')
107  ->with($this->isInstanceOf(ilTermsOfServiceAcceptanceEntity::class));
108 
109  $dataGatewayFactory
110  ->expects($this->any())
111  ->method('getByName')
112  ->willReturn($dataGateway);
113 
114  $helper = new ilTermsOfServiceHelper(
115  $dataGatewayFactory,
116  $this->getMockBuilder(ilTermsOfServiceDocumentEvaluation::class)->getMock(),
117  $this->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)->getMock(),
118  $this->getMockBuilder(ilObjTermsOfService::class)->disableOriginalConstructor()->getMock()
119  );
120 
121  $user = $this
122  ->getMockBuilder(ilObjUser::class)
123  ->disableOriginalConstructor()
124  ->onlyMethods(['getId', 'getLogin'])
125  ->getMock();
126 
127  $user
128  ->expects($this->any())
129  ->method('getId')
130  ->willReturn(-1);
131 
132  $user
133  ->expects($this->any())
134  ->method('getLogin')
135  ->willReturn('phpunit');
136 
137  $helper->deleteAcceptanceHistoryByUser($user->getId());
138  }
Class ilTermsOfServiceHelper.

◆ testAcceptanceHistoryEntityCanBeLoadedById()

ilTermsOfServiceHelperTest::testAcceptanceHistoryEntityCanBeLoadedById ( )
Exceptions
ilTermsOfServiceMissingDatabaseAdapterException
ReflectionException

Definition at line 196 of file ilTermsOfServiceHelperTest.php.

196  : void
197  {
198  $dataGatewayFactory = $this->getMockBuilder(ilTermsOfServiceDataGatewayFactory::class)->getMock();
199  $dataGateway = $this
200  ->getMockBuilder(ilTermsOfServiceAcceptanceDataGateway::class)
201  ->getMock();
202 
203  $entity = new ilTermsOfServiceAcceptanceEntity();
204  $entity->withId(4711);
205 
206  $dataGateway
207  ->expects($this->atLeast(1))
208  ->method('loadById')
209  ->willReturn($entity);
210 
211  $dataGatewayFactory
212  ->expects($this->any())
213  ->method('getByName')
214  ->willReturn($dataGateway);
215 
216  $helper = new ilTermsOfServiceHelper(
217  $dataGatewayFactory,
218  $this->getMockBuilder(ilTermsOfServiceDocumentEvaluation::class)->getMock(),
219  $this->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)->getMock(),
220  $this->getMockBuilder(ilObjTermsOfService::class)->disableOriginalConstructor()->getMock()
221  );
222 
223  $user = $this
224  ->getMockBuilder(ilObjUser::class)
225  ->disableOriginalConstructor()
226  ->onlyMethods(['getId', 'getLogin'])
227  ->getMock();
228 
229  $user
230  ->expects($this->any())
231  ->method('getId')
232  ->willReturn(-1);
233 
234  $user
235  ->expects($this->any())
236  ->method('getLogin')
237  ->willReturn('phpunit');
238 
239  $this->assertInstanceOf(ilTermsOfServiceAcceptanceEntity::class, $helper->getById($entity->getId()));
240  $this->assertEquals($entity, $helper->getById($entity->getId()));
241  }
Class ilTermsOfServiceHelper.
Class ilTermsOfServiceAcceptanceEntity.

◆ testDocumentCanBeAccepted()

ilTermsOfServiceHelperTest::testDocumentCanBeAccepted ( )
Exceptions
ReflectionException
ilTermsOfServiceMissingDatabaseAdapterException
ilTermsOfServiceUnexpectedCriteriaBagContentException

Definition at line 15 of file ilTermsOfServiceHelperTest.php.

15  : void
16  {
17  $dataGatewayFactory = $this->getMockBuilder(ilTermsOfServiceDataGatewayFactory::class)->getMock();
18  $dataGateway = $this
19  ->getMockBuilder(ilTermsOfServiceAcceptanceDataGateway::class)
20  ->getMock();
21 
22  $dataGateway
23  ->expects($this->once())
24  ->method('trackAcceptance')
25  ->with($this->isInstanceOf(ilTermsOfServiceAcceptanceEntity::class));
26 
27  $dataGatewayFactory
28  ->expects($this->any())
29  ->method('getByName')
30  ->willReturn($dataGateway);
31 
32  $helper = new ilTermsOfServiceHelper(
33  $dataGatewayFactory,
34  $this->getMockBuilder(ilTermsOfServiceDocumentEvaluation::class)->getMock(),
35  $this->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)->getMock(),
36  $this->getMockBuilder(ilObjTermsOfService::class)->disableOriginalConstructor()->getMock()
37  );
38 
39  $user = $this
40  ->getMockBuilder(ilObjUser::class)
41  ->disableOriginalConstructor()
42  ->onlyMethods(['getLanguage', 'getId', 'getLogin', 'writeAccepted', 'hasToAcceptTermsOfServiceInSession'])
43  ->getMock();
44 
45  $user
46  ->expects($this->any())
47  ->method('getId')
48  ->willReturn(-1);
49 
50  $user
51  ->expects($this->any())
52  ->method('getLogin')
53  ->willReturn('phpunit');
54 
55  $user
56  ->expects($this->once())
57  ->method('writeAccepted');
58 
59  $user
60  ->expects($this->once())
61  ->method('hasToAcceptTermsOfServiceInSession')
62  ->with(false);
63 
64  $document = $this
65  ->getMockBuilder(ilTermsOfServiceDocument::class)
66  ->disableOriginalConstructor()
67  ->onlyMethods(['content', 'id', 'criteria', 'title'])
68  ->getMock();
69 
70  $document
71  ->expects($this->atLeast(1))
72  ->method('content')
73  ->willReturn('phpunit');
74 
75  $document
76  ->expects($this->atLeast(1))
77  ->method('title')
78  ->willReturn('phpunit');
79 
80  $document
81  ->expects($this->atLeast(1))
82  ->method('id')
83  ->willReturn(1);
84 
85  $document
86  ->expects($this->atLeast(1))
87  ->method('criteria')
88  ->willReturn([]);
89 
90  $helper->trackAcceptance($user, $document);
91  }
Class ilTermsOfServiceHelper.

◆ testLatestAcceptanceHistoryEntityCanBeLoadedForUser()

ilTermsOfServiceHelperTest::testLatestAcceptanceHistoryEntityCanBeLoadedForUser ( )
Exceptions
ilTermsOfServiceMissingDatabaseAdapterException
ReflectionException

Definition at line 144 of file ilTermsOfServiceHelperTest.php.

144  : void
145  {
146  $dataGatewayFactory = $this->getMockBuilder(ilTermsOfServiceDataGatewayFactory::class)->getMock();
147  $dataGateway = $this
148  ->getMockBuilder(ilTermsOfServiceAcceptanceDataGateway::class)
149  ->getMock();
150 
151  $entity = new ilTermsOfServiceAcceptanceEntity();
152  $entity->withId(4711);
153 
154  $dataGateway
155  ->expects($this->atLeast(1))
156  ->method('loadCurrentAcceptanceOfUser')
157  ->with($this->isInstanceOf(ilTermsOfServiceAcceptanceEntity::class))
158  ->willReturn($entity);
159 
160  $dataGatewayFactory
161  ->expects($this->any())
162  ->method('getByName')
163  ->willReturn($dataGateway);
164 
165  $helper = new ilTermsOfServiceHelper(
166  $dataGatewayFactory,
167  $this->getMockBuilder(ilTermsOfServiceDocumentEvaluation::class)->getMock(),
168  $this->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)->getMock(),
169  $this->getMockBuilder(ilObjTermsOfService::class)->disableOriginalConstructor()->getMock()
170  );
171 
172  $user = $this
173  ->getMockBuilder(ilObjUser::class)
174  ->disableOriginalConstructor()
175  ->onlyMethods(['getId', 'getLogin'])
176  ->getMock();
177 
178  $user
179  ->expects($this->any())
180  ->method('getId')
181  ->willReturn(-1);
182 
183  $user
184  ->expects($this->any())
185  ->method('getLogin')
186  ->willReturn('phpunit');
187 
188  $this->assertInstanceOf(ilTermsOfServiceAcceptanceEntity::class, $helper->getCurrentAcceptanceForUser($user));
189  $this->assertEquals($entity, $helper->getCurrentAcceptanceForUser($user));
190  }
Class ilTermsOfServiceHelper.
Class ilTermsOfServiceAcceptanceEntity.

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