4 require_once
'Services/TermsOfService/classes/class.ilTermsOfServiceAcceptanceDatabaseGateway.php';
5 require_once
'Services/TermsOfService/classes/class.ilTermsOfServiceAcceptanceEntity.php';
6 require_once
'Services/TermsOfService/test/ilTermsOfServiceBaseTest.php';
32 $database = $this->getMockBuilder(
'ilDBInterface')->getMock();
34 $this->assertInstanceOf(
'ilTermsOfServiceAcceptanceDatabaseGateway', $gateway);
43 $entity->setUserId(666);
44 $entity->setIso2LanguageCode(
'de');
45 $entity->setSource(
'/path/to/file');
46 $entity->setSourceType(0);
47 $entity->setText(
'PHP Unit');
48 $entity->setTimestamp(
time());
49 $entity->setHash(md5($entity->getText()));
53 $database = $this->getMockBuilder(
'ilDBInterface')->getMock();
54 $result = $this->getMockBuilder(
'ilDBStatement')->getMock();
56 $database->expects($this->once())->method(
'queryF')->with(
'SELECT id FROM tos_versions WHERE hash = %s AND lng = %s',
array(
'text',
'text'),
array($entity->getHash(), $entity->getIso2LanguageCode()))->will($this->returnValue(
$result));
57 $database->expects($this->once())->method(
'numRows')->with(
$result)->will($this->returnValue(0));
58 $database->expects($this->once())->method(
'nextId')->with(
'tos_versions')->will($this->returnValue($expected_id));
60 $expectedVersions =
array(
61 'id' =>
array(
'integer', $expected_id),
62 'lng' =>
array(
'text', $entity->getIso2LanguageCode()),
63 'src' =>
array(
'text', $entity->getSource()),
64 'src_type' =>
array(
'integer', $entity->getSourceType()),
65 'text' =>
array(
'clob', $entity->getText()),
66 'hash' =>
array(
'text', $entity->getHash()),
67 'ts' =>
array(
'integer', $entity->getTimestamp())
69 $expectedTracking =
array(
70 'tosv_id' =>
array(
'integer', $expected_id),
71 'usr_id' =>
array(
'integer', $entity->getUserId()),
72 'ts' =>
array(
'integer', $entity->getTimestamp())
74 $database->expects($this->exactly(2))->method(
'insert')->with(
75 $this->logicalOr(
'tos_versions',
'tos_acceptance_track'),
76 $this->logicalOr($expectedVersions, $expectedTracking)
80 $gateway->trackAcceptance($entity);
89 $entity->setUserId(666);
90 $entity->setIso2LanguageCode(
'de');
91 $entity->setSource(
'/path/to/file');
92 $entity->setSourceType(0);
93 $entity->setText(
'PHP Unit');
94 $entity->setTimestamp(
time());
95 $entity->setHash(md5($entity->getText()));
99 $database = $this->getMockBuilder(
'ilDBInterface')->getMock();
100 $result = $this->getMockBuilder(
'ilDBStatement')->getMock();
102 $database->expects($this->once())->method(
'queryF')->with(
'SELECT id FROM tos_versions WHERE hash = %s AND lng = %s',
array(
'text',
'text'),
array($entity->getHash(), $entity->getIso2LanguageCode()))->will($this->returnValue(
$result));
103 $database->expects($this->once())->method(
'numRows')->with(
$result)->will($this->returnValue(1));
104 $database->expects($this->once())->method(
'fetchAssoc')->with(
$result)->will($this->returnValue(
array(
'id' => $expected_id)));
106 $expectedTracking =
array(
107 'tosv_id' =>
array(
'integer', $expected_id),
108 'usr_id' =>
array(
'integer', $entity->getUserId()),
109 'ts' =>
array(
'integer', $entity->getTimestamp())
111 $database->expects($this->once())->method(
'insert')->with(
'tos_acceptance_track', $expectedTracking);
114 $gateway->trackAcceptance($entity);
128 'src' =>
'/path/to/file',
130 'text' =>
'PHP Unit',
131 'hash' => md5(
'PHP Unit'),
132 'accepted_ts' =>
time()
135 $database = $this->getMockBuilder(
'ilDBInterface')->getMock();
136 $database->expects($this->once())->method(
'fetchAssoc')->will($this->onConsecutiveCalls($expected));
138 $gateway->loadCurrentAcceptanceOfUser($entity);
140 $this->assertEquals($expected[
'id'], $entity->getId());
141 $this->assertEquals($expected[
'usr_id'], $entity->getUserId());
142 $this->assertEquals($expected[
'lng'], $entity->getIso2LanguageCode());
143 $this->assertEquals($expected[
'src'], $entity->getSource());
144 $this->assertEquals($expected[
'src_type'], $entity->getSourceType());
145 $this->assertEquals($expected[
'text'], $entity->getText());
146 $this->assertEquals($expected[
'accepted_ts'], $entity->getTimestamp());
147 $this->assertEquals($expected[
'hash'], $entity->getHash());
156 $entity->setUserId(4711);
158 $database = $this->getMockBuilder(
'ilDBInterface')->getMock();
159 $database->expects($this->once())->method(
'quote')->with($entity->getUserId(),
'integer')->will($this->returnValue($entity->getUserId()));
160 $database->expects($this->once())->method(
'manipulate')->with(
'DELETE FROM tos_acceptance_track WHERE usr_id = ' . $entity->getUserId());
162 $gateway->deleteAcceptanceHistoryByUser($entity);
testAcceptanceHistoryOfAUserIsDeleted()
testAcceptanceIsTrackedAndCreatesANewTermsOfServicesVersion()
testInstanceCanBeCreated()
Create styles array
The data for the language used.
testCurrentAcceptanceOfUserIsLoaded()
testAcceptanceIsTrackedAndRefersToAnExistingTermsOfServicesVersion()
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.