ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 ()
 
 setGlobalVariable (string $name, $value)
 
 assertException (string $exceptionClass)
 
 getCriterionConfig ($value=null)
 
- Protected Attributes inherited from ilTermsOfServiceBaseTest
 $dic
 

Detailed Description

Member Function Documentation

◆ testAcceptanceHistoryCanBeDeleted()

ilTermsOfServiceHelperTest::testAcceptanceHistoryCanBeDeleted ( )

Definition at line 92 of file ilTermsOfServiceHelperTest.php.

References $user, and Sabre\Event\once().

93  {
94  $dataGatewayFactory = $this->getMockBuilder(\ilTermsOfServiceDataGatewayFactory::class)->getMock();
95  $dataGateway = $this
96  ->getMockBuilder(\ilTermsOfServiceAcceptanceDataGateway::class)
97  ->getMock();
98 
99  $dataGateway
100  ->expects($this->once())
101  ->method('deleteAcceptanceHistoryByUser')
102  ->with($this->isInstanceOf(\ilTermsOfServiceAcceptanceEntity::class));
103 
104  $dataGatewayFactory
105  ->expects($this->any())
106  ->method('getByName')
107  ->willReturn($dataGateway);
108 
109  $helper = new \ilTermsOfServiceHelper(
110  $this->getMockBuilder(\ilDBInterface::class)->getMock(),
111  $dataGatewayFactory
112  );
113 
114  $user = $this
115  ->getMockBuilder(\ilObjUser::class)
116  ->disableOriginalConstructor()
117  ->setMethods(['getId', 'getLogin'])
118  ->getMock();
119 
120  $user
121  ->expects($this->any())
122  ->method('getId')
123  ->willReturn(-1);
124 
125  $user
126  ->expects($this->any())
127  ->method('getLogin')
128  ->willReturn('phpunit');
129 
130  $helper->deleteAcceptanceHistoryByUser($user->getId());
131  }
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
$user
Definition: migrateto20.php:57
+ Here is the call graph for this function:

◆ testAcceptanceHistoryEntityCanBeLoadedById()

ilTermsOfServiceHelperTest::testAcceptanceHistoryEntityCanBeLoadedById ( )

Definition at line 185 of file ilTermsOfServiceHelperTest.php.

References $user.

186  {
187  $dataGatewayFactory = $this->getMockBuilder(\ilTermsOfServiceDataGatewayFactory::class)->getMock();
188  $dataGateway = $this
189  ->getMockBuilder(\ilTermsOfServiceAcceptanceDataGateway::class)
190  ->getMock();
191 
192  $entity = new \ilTermsOfServiceAcceptanceEntity();
193  $entity->withId(4711);
194 
195  $dataGateway
196  ->expects($this->atLeast(1))
197  ->method('loadById')
198  ->willReturn($entity);
199 
200  $dataGatewayFactory
201  ->expects($this->any())
202  ->method('getByName')
203  ->willReturn($dataGateway);
204 
205  $helper = new \ilTermsOfServiceHelper(
206  $this->getMockBuilder(\ilDBInterface::class)->getMock(),
207  $dataGatewayFactory
208  );
209 
210  $user = $this
211  ->getMockBuilder(\ilObjUser::class)
212  ->disableOriginalConstructor()
213  ->setMethods(['getId', 'getLogin'])
214  ->getMock();
215 
216  $user
217  ->expects($this->any())
218  ->method('getId')
219  ->willReturn(-1);
220 
221  $user
222  ->expects($this->any())
223  ->method('getLogin')
224  ->willReturn('phpunit');
225 
226  $this->assertInstanceOf(\ilTermsOfServiceAcceptanceEntity::class, $helper->getById($entity->getId()));
227  $this->assertEquals($entity, $helper->getById($entity->getId()));
228  }
$user
Definition: migrateto20.php:57

◆ testDocumentCanBeAccepted()

ilTermsOfServiceHelperTest::testDocumentCanBeAccepted ( )

Definition at line 13 of file ilTermsOfServiceHelperTest.php.

References $user, and Sabre\Event\once().

14  {
15  $dataGatewayFactory = $this->getMockBuilder(\ilTermsOfServiceDataGatewayFactory::class)->getMock();
16  $dataGateway = $this
17  ->getMockBuilder(\ilTermsOfServiceAcceptanceDataGateway::class)
18  ->getMock();
19 
20  $dataGateway
21  ->expects($this->once())
22  ->method('trackAcceptance')
23  ->with($this->isInstanceOf(\ilTermsOfServiceAcceptanceEntity::class));
24 
25  $dataGatewayFactory
26  ->expects($this->any())
27  ->method('getByName')
28  ->willReturn($dataGateway);
29 
30  $helper = new \ilTermsOfServiceHelper(
31  $this->getMockBuilder(\ilDBInterface::class)->getMock(),
32  $dataGatewayFactory
33  );
34 
35  $user = $this
36  ->getMockBuilder(\ilObjUser::class)
37  ->disableOriginalConstructor()
38  ->setMethods(['getLanguage', 'getId', 'getLogin', 'writeAccepted', 'hasToAcceptTermsOfServiceInSession'])
39  ->getMock();
40 
41  $user
42  ->expects($this->any())
43  ->method('getId')
44  ->willReturn(-1);
45 
46  $user
47  ->expects($this->any())
48  ->method('getLogin')
49  ->willReturn('phpunit');
50 
51  $user
52  ->expects($this->once())
53  ->method('writeAccepted');
54 
55  $user
56  ->expects($this->once())
57  ->method('hasToAcceptTermsOfServiceInSession')
58  ->with(false);
59 
60  $document = $this
61  ->getMockBuilder(\ilTermsOfServiceDocument::class)
62  ->disableOriginalConstructor()
63  ->setMethods(['content', 'id', 'criteria', 'title'])
64  ->getMock();
65 
66  $document
67  ->expects($this->atLeast(1))
68  ->method('content')
69  ->willReturn('phpunit');
70 
71  $document
72  ->expects($this->atLeast(1))
73  ->method('title')
74  ->willReturn('phpunit');
75 
76  $document
77  ->expects($this->atLeast(1))
78  ->method('id')
79  ->willReturn(1);
80 
81  $document
82  ->expects($this->atLeast(1))
83  ->method('criteria')
84  ->willReturn([]);
85 
86  $helper->trackAcceptance($user, $document);
87  }
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
$user
Definition: migrateto20.php:57
+ Here is the call graph for this function:

◆ testLatestAcceptanceHistoryEntityCanBeLoadedForUser()

ilTermsOfServiceHelperTest::testLatestAcceptanceHistoryEntityCanBeLoadedForUser ( )

Definition at line 136 of file ilTermsOfServiceHelperTest.php.

References $user.

137  {
138  $dataGatewayFactory = $this->getMockBuilder(\ilTermsOfServiceDataGatewayFactory::class)->getMock();
139  $dataGateway = $this
140  ->getMockBuilder(\ilTermsOfServiceAcceptanceDataGateway::class)
141  ->getMock();
142 
143  $entity = new \ilTermsOfServiceAcceptanceEntity();
144  $entity->withId(4711);
145 
146  $dataGateway
147  ->expects($this->atLeast(1))
148  ->method('loadCurrentAcceptanceOfUser')
149  ->with($this->isInstanceOf(\ilTermsOfServiceAcceptanceEntity::class))
150  ->willReturn($entity);
151 
152  $dataGatewayFactory
153  ->expects($this->any())
154  ->method('getByName')
155  ->willReturn($dataGateway);
156 
157  $helper = new \ilTermsOfServiceHelper(
158  $this->getMockBuilder(\ilDBInterface::class)->getMock(),
159  $dataGatewayFactory
160  );
161 
162  $user = $this
163  ->getMockBuilder(\ilObjUser::class)
164  ->disableOriginalConstructor()
165  ->setMethods(['getId', 'getLogin'])
166  ->getMock();
167 
168  $user
169  ->expects($this->any())
170  ->method('getId')
171  ->willReturn(-1);
172 
173  $user
174  ->expects($this->any())
175  ->method('getLogin')
176  ->willReturn('phpunit');
177 
178  $this->assertInstanceOf(\ilTermsOfServiceAcceptanceEntity::class, $helper->getCurrentAcceptanceForUser($user));
179  $this->assertEquals($entity, $helper->getCurrentAcceptanceForUser($user));
180  }
$user
Definition: migrateto20.php:57

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