15 $database = $this->getMockBuilder(\ilDBInterface::class)->getMock();
16 $gateway = new \ilTermsOfServiceAcceptanceDatabaseGateway($database);
18 $this->assertInstanceOf(\ilTermsOfServiceAcceptanceDatabaseGateway::class, $gateway);
26 $entity = new \ilTermsOfServiceAcceptanceEntity();
27 $entity->withUserId(666);
28 $entity->withDocumentId(4711);
29 $entity->withTitle(
'Document PHP Unit');
30 $entity->withSerializedCriteria(
'');
31 $entity->withText(
'PHP Unit');
32 $entity->withTimestamp(time());
33 $entity->withHash(md5($entity->getText()));
37 $database = $this->getMockBuilder(\ilDBInterface::class)->getMock();
38 $result = $this->getMockBuilder(\ilDBStatement::class)->getMock();
41 ->expects($this->
once())
44 'SELECT id FROM tos_versions WHERE hash = %s AND doc_id = %s',
46 [$entity->getHash(), $entity->getDocumentId()]
47 )->will($this->returnValue(
$result));
50 ->expects($this->
once())
53 will($this->returnValue(0));
56 ->expects($this->
once())
58 ->with(
'tos_versions')
59 ->will($this->returnValue($expected_id));
62 'id' => [
'integer', $expected_id],
63 'doc_id' => [
'integer', $entity->getDocumentId()],
64 'title' => [
'text', $entity->getTitle()],
65 'text' => [
'clob', $entity->getText()],
66 'hash' => [
'text', $entity->getHash()],
67 'ts' => [
'integer', $entity->getTimestamp()]
70 'tosv_id' => [
'integer', $expected_id],
71 'usr_id' => [
'integer', $entity->getUserId()],
72 'criteria' => [
'clob', $entity->getSerializedCriteria()],
73 'ts' => [
'integer', $entity->getTimestamp()]
77 ->expects($this->exactly(2))
80 $this->logicalOr(
'tos_versions',
'tos_acceptance_track'),
81 $this->logicalOr($expectedVersions, $expectedTracking)
84 $gateway = new \ilTermsOfServiceAcceptanceDatabaseGateway($database);
85 $gateway->trackAcceptance($entity);
93 $entity = new \ilTermsOfServiceAcceptanceEntity();
94 $entity->withUserId(666);
95 $entity->withDocumentId(4711);
96 $entity->withTitle(
'Document PHP Unit');
97 $entity->withSerializedCriteria(
'');
98 $entity->withText(
'PHP Unit');
99 $entity->withTimestamp(time());
100 $entity->withHash(md5($entity->getText()));
104 $database = $this->getMockBuilder(\ilDBInterface::class)->getMock();
105 $result = $this->getMockBuilder(\ilDBStatement::class)->getMock();
108 ->expects($this->
once())
111 'SELECT id FROM tos_versions WHERE hash = %s AND doc_id = %s',
113 [$entity->getHash(), $entity->getDocumentId()]
114 )->will($this->returnValue(
$result));
117 ->expects($this->
once())
120 ->will($this->returnValue(1));
123 ->expects($this->
once())
124 ->method(
'fetchAssoc')
126 ->will($this->returnValue([
'id' => $expected_id]));
128 $expectedTracking = [
129 'tosv_id' => [
'integer', $expected_id],
130 'usr_id' => [
'integer', $entity->getUserId()],
131 'criteria' => [
'clob', $entity->getSerializedCriteria()],
132 'ts' => [
'integer', $entity->getTimestamp()]
135 ->expects($this->
once())
137 ->with(
'tos_acceptance_track', $expectedTracking);
139 $gateway = new \ilTermsOfServiceAcceptanceDatabaseGateway($database);
140 $gateway->trackAcceptance($entity);
148 $entity = new \ilTermsOfServiceAcceptanceEntity();
153 'title' =>
'Document PHP Unit',
156 'text' =>
'PHP Unit',
157 'hash' => md5(
'PHP Unit'),
158 'accepted_ts' => time()
161 $database = $this->getMockBuilder(\ilDBInterface::class)->getMock();
163 ->expects($this->
once())
164 ->method(
'fetchAssoc')
165 ->will($this->onConsecutiveCalls($expected));
167 $gateway = new \ilTermsOfServiceAcceptanceDatabaseGateway($database);
168 $entity = $gateway->loadCurrentAcceptanceOfUser($entity);
170 $this->assertEquals($expected[
'id'], $entity->getId());
171 $this->assertEquals($expected[
'usr_id'], $entity->getUserId());
172 $this->assertEquals($expected[
'doc_id'], $entity->getDocumentId());
173 $this->assertEquals($expected[
'title'], $entity->getTitle());
174 $this->assertEquals($expected[
'criteria'], $entity->getSerializedCriteria());
175 $this->assertEquals($expected[
'text'], $entity->getText());
176 $this->assertEquals($expected[
'accepted_ts'], $entity->getTimestamp());
177 $this->assertEquals($expected[
'hash'], $entity->getHash());
185 $entity = new \ilTermsOfServiceAcceptanceEntity();
186 $entity->withUserId(4711);
188 $database = $this->getMockBuilder(\ilDBInterface::class)->getMock();
191 ->expects($this->
once())
193 ->with($entity->getUserId(),
'integer')
194 ->will($this->returnValue($entity->getUserId()));
197 ->expects($this->
once())
198 ->method(
'manipulate')
199 ->with(
'DELETE FROM tos_acceptance_track WHERE usr_id = ' . $entity->getUserId());
201 $gateway = new \ilTermsOfServiceAcceptanceDatabaseGateway($database);
202 $gateway->deleteAcceptanceHistoryByUser($entity);
210 $entity = new \ilTermsOfServiceAcceptanceEntity();
214 'title' =>
'Document PHP Unit',
217 'text' =>
'PHP Unit',
218 'hash' => md5(
'PHP Unit'),
221 $database = $this->getMockBuilder(\ilDBInterface::class)->getMock();
223 ->expects($this->
once())
224 ->method(
'fetchAssoc')
225 ->will($this->onConsecutiveCalls($expected));
227 $gateway = new \ilTermsOfServiceAcceptanceDatabaseGateway($database);
228 $entity = $gateway->loadById($entity);
230 $this->assertEquals($expected[
'id'], $entity->getId());
231 $this->assertEquals($expected[
'doc_id'], $entity->getDocumentId());
232 $this->assertEquals($expected[
'title'], $entity->getTitle());
233 $this->assertEquals($expected[
'criteria'], $entity->getSerializedCriteria());
234 $this->assertEquals($expected[
'text'], $entity->getText());
235 $this->assertEquals($expected[
'hash'], $entity->getHash());
testAcceptanceHistoryOfAUserCanBeDeleted()
Class ilTermsOfServiceAcceptanceDatabaseGatewayTest.
Class ilTermsOfServiceBaseTest.
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
testInstanceCanBeCreated()
testAcceptanceIsTrackedAndCreatesANewTermsOfServicesVersionIfNecessary()
testLatestAcceptanceOfUserCanBeLoaded()
testAcceptanceHistoryRecordCanBeLoadedById()
testAcceptanceIsTrackedAndRefersToAnExistingTermsOfServicesVersion()