4 require_once
'Services/TermsOfService/classes/class.ilTermsOfServiceAcceptanceDatabaseGateway.php';
5 require_once
'Services/TermsOfService/classes/class.ilTermsOfServiceAcceptanceEntity.php';
30 $database = $this->getMockBuilder(
'ilDB')->disableOriginalConstructor()->getMock();
32 $this->assertInstanceOf(
'ilTermsOfServiceAcceptanceDatabaseGateway', $gateway);
41 $entity->setUserId(666);
42 $entity->setIso2LanguageCode(
'de');
43 $entity->setSource(
'/path/to/file');
44 $entity->setSourceType(0);
45 $entity->setText(
'PHP Unit');
46 $entity->setTimestamp(time());
47 $entity->setHash(md5($entity->getText()));
51 $database = $this->getMockBuilder(
'ilDB')->disableOriginalConstructor()->getMock();
52 $result = $this->getMockBuilder(
'MDB2_BufferedResult_mysqli')->disableOriginalConstructor()->getMock();
54 $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));
55 $database->expects($this->once())->method(
'numRows')->with(
$result)->will($this->returnValue(0));
56 $database->expects($this->once())->method(
'nextId')->with(
'tos_versions')->will($this->returnValue($expected_id));
58 $expectedVersions = array(
59 'id' => array(
'integer', $expected_id),
60 'lng' => array(
'text', $entity->getIso2LanguageCode()),
61 'src' => array(
'text', $entity->getSource()),
62 'src_type' => array(
'integer', $entity->getSourceType()),
63 'text' => array(
'clob', $entity->getText()),
64 'hash' => array(
'text', $entity->getHash()),
65 'ts' => array(
'integer', $entity->getTimestamp())
67 $expectedTracking = array(
68 'tosv_id' => array(
'integer', $expected_id),
69 'usr_id' => array(
'integer', $entity->getUserId()),
70 'ts' => array(
'integer', $entity->getTimestamp())
72 $database->expects($this->exactly(2))->method(
'insert')->with(
73 $this->logicalOr(
'tos_versions',
'tos_acceptance_track'),
74 $this->logicalOr($expectedVersions, $expectedTracking)
78 $gateway->trackAcceptance($entity);
87 $entity->setUserId(666);
88 $entity->setIso2LanguageCode(
'de');
89 $entity->setSource(
'/path/to/file');
90 $entity->setSourceType(0);
91 $entity->setText(
'PHP Unit');
92 $entity->setTimestamp(time());
93 $entity->setHash(md5($entity->getText()));
97 $database = $this->getMockBuilder(
'ilDB')->disableOriginalConstructor()->getMock();
98 $result = $this->getMockBuilder(
'MDB2_BufferedResult_mysqli')->disableOriginalConstructor()->getMock();
100 $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));
101 $database->expects($this->once())->method(
'numRows')->with(
$result)->will($this->returnValue(1));
102 $database->expects($this->once())->method(
'fetchAssoc')->with(
$result)->will($this->returnValue(array(
'id' => $expected_id)));
104 $expectedTracking = array(
105 'tosv_id' => array(
'integer', $expected_id),
106 'usr_id' => array(
'integer', $entity->getUserId()),
107 'ts' => array(
'integer', $entity->getTimestamp())
109 $database->expects($this->once())->method(
'insert')->with(
'tos_acceptance_track', $expectedTracking);
112 $gateway->trackAcceptance($entity);
126 'src' =>
'/path/to/file',
128 'text' =>
'PHP Unit',
129 'accepted_ts' => time()
132 $database = $this->getMockBuilder(
'ilDB')->disableOriginalConstructor()->getMock();
133 $database->expects($this->once())->method(
'fetchAssoc')->will($this->onConsecutiveCalls($expected));
135 $gateway->loadCurrentAcceptanceOfUser($entity);
137 $this->assertEquals($expected[
'id'], $entity->getId());
138 $this->assertEquals($expected[
'usr_id'], $entity->getUserId());
139 $this->assertEquals($expected[
'lng'], $entity->getIso2LanguageCode());
140 $this->assertEquals($expected[
'src'], $entity->getSource());
141 $this->assertEquals($expected[
'src_type'], $entity->getSourceType());
142 $this->assertEquals($expected[
'text'], $entity->getText());
143 $this->assertEquals($expected[
'accepted_ts'], $entity->getTimestamp());
152 $entity->setUserId(4711);
154 $database = $this->getMockBuilder(
'ilDB')->disableOriginalConstructor()->getMock();
155 $database->expects($this->once())->method(
'quote')->with($entity->getUserId(),
'integer')->will($this->returnValue($entity->getUserId()));
156 $database->expects($this->once())->method(
'manipulate')->with(
'DELETE FROM tos_acceptance_track WHERE usr_id = ' . $entity->getUserId());
158 $gateway->deleteAcceptanceHistoryByUser($entity);