ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilTermsOfServiceAcceptanceDatabaseGatewayTest Class Reference
+ Inheritance diagram for ilTermsOfServiceAcceptanceDatabaseGatewayTest:
+ Collaboration diagram for ilTermsOfServiceAcceptanceDatabaseGatewayTest:

Public Member Functions

 setUp ()
 
 testInstanceCanBeCreated ()
 
 testAcceptanceIsTrackedAndCreatesANewTermsOfServicesVersion ()
 
 testAcceptanceIsTrackedAndRefersToAnExistingTermsOfServicesVersion ()
 
 testCurrentAcceptanceOfUserIsLoaded ()
 
 testAcceptanceHistoryOfAUserIsDeleted ()
 

Protected Attributes

 $backupGlobals = false
 

Detailed Description

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

Definition at line 11 of file ilTermsOfServiceAcceptanceDatabaseGatewayTest.php.

Member Function Documentation

◆ setUp()

ilTermsOfServiceAcceptanceDatabaseGatewayTest::setUp ( )

Definition at line 21 of file ilTermsOfServiceAcceptanceDatabaseGatewayTest.php.

22 {
23 if(!defined('MDB2_AUTOQUERY_INSERT'))
24 {
25 define('MDB2_AUTOQUERY_INSERT', 1);
26 }
27
28 parent::setUp();
29 }

◆ testAcceptanceHistoryOfAUserIsDeleted()

ilTermsOfServiceAcceptanceDatabaseGatewayTest::testAcceptanceHistoryOfAUserIsDeleted ( )

Definition at line 157 of file ilTermsOfServiceAcceptanceDatabaseGatewayTest.php.

158 {
159 $entity = new ilTermsOfServiceAcceptanceEntity();
160 $entity->setUserId(4711);
161
162 $database = $this->getMockBuilder('ilDB')->disableOriginalConstructor()->getMock();
163 $database->expects($this->once())->method('quote')->with($entity->getUserId(), 'integer')->will($this->returnValue($entity->getUserId()));
164 $database->expects($this->once())->method('manipulate')->with('DELETE FROM tos_acceptance_track WHERE usr_id = ' . $entity->getUserId());
165 $gateway = new ilTermsOfServiceAcceptanceDatabaseGateway($database);
166 $gateway->deleteAcceptanceHistoryByUser($entity);
167 }

◆ testAcceptanceIsTrackedAndCreatesANewTermsOfServicesVersion()

ilTermsOfServiceAcceptanceDatabaseGatewayTest::testAcceptanceIsTrackedAndCreatesANewTermsOfServicesVersion ( )

Definition at line 44 of file ilTermsOfServiceAcceptanceDatabaseGatewayTest.php.

45 {
47 $entity->setUserId(666);
48 $entity->setIso2LanguageCode('de');
49 $entity->setSource('/path/to/file');
50 $entity->setSourceType(0);
51 $entity->setText('PHP Unit');
52 $entity->setTimestamp(time());
53 $entity->setHash(md5($entity->getText()));
54
55 $expected_id = 4711;
56
57 $database = $this->getMockBuilder('ilDB')->disableOriginalConstructor()->getMock();
58 $result = $this->getMockBuilder('MDB2_BufferedResult_mysqli')->disableOriginalConstructor()->getMock();
59
60 $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));
61 $database->expects($this->once())->method('numRows')->with($result)->will($this->returnValue(0));
62 $database->expects($this->once())->method('nextId')->with('tos_versions')->will($this->returnValue($expected_id));
63
64 $expectedVersions = array(
65 'id' => array('integer', $expected_id),
66 'lng' => array('text', $entity->getIso2LanguageCode()),
67 'src' => array('text', $entity->getSource()),
68 'src_type' => array('integer', $entity->getSourceType()),
69 'text' => array('clob', $entity->getText()),
70 'hash' => array('text', $entity->getHash()),
71 'ts' => array('integer', $entity->getTimestamp())
72 );
73 $expectedTracking = array(
74 'tosv_id' => array('integer', $expected_id),
75 'usr_id' => array('integer', $entity->getUserId()),
76 'ts' => array('integer', $entity->getTimestamp())
77 );
78 $database->expects($this->exactly(2))->method('insert')->with(
79 $this->logicalOr('tos_versions', 'tos_acceptance_track'),
80 $this->logicalOr($expectedVersions, $expectedTracking)
81 );
82
83 $gateway = new ilTermsOfServiceAcceptanceDatabaseGateway($database);
84 $gateway->trackAcceptance($entity);
85 }
$result

References $result.

◆ testAcceptanceIsTrackedAndRefersToAnExistingTermsOfServicesVersion()

ilTermsOfServiceAcceptanceDatabaseGatewayTest::testAcceptanceIsTrackedAndRefersToAnExistingTermsOfServicesVersion ( )

Definition at line 90 of file ilTermsOfServiceAcceptanceDatabaseGatewayTest.php.

91 {
93 $entity->setUserId(666);
94 $entity->setIso2LanguageCode('de');
95 $entity->setSource('/path/to/file');
96 $entity->setSourceType(0);
97 $entity->setText('PHP Unit');
98 $entity->setTimestamp(time());
99 $entity->setHash(md5($entity->getText()));
100
101 $expected_id = 4711;
102
103 $database = $this->getMockBuilder('ilDB')->disableOriginalConstructor()->getMock();
104 $result = $this->getMockBuilder('MDB2_BufferedResult_mysqli')->disableOriginalConstructor()->getMock();
105
106 $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));
107 $database->expects($this->once())->method('numRows')->with($result)->will($this->returnValue(1));
108 $database->expects($this->once())->method('fetchAssoc')->with($result)->will($this->returnValue(array('id' => $expected_id)));
109
110 $expectedTracking = array(
111 'tosv_id' => array('integer', $expected_id),
112 'usr_id' => array('integer', $entity->getUserId()),
113 'ts' => array('integer', $entity->getTimestamp())
114 );
115 $database->expects($this->once())->method('insert')->with('tos_acceptance_track', $expectedTracking);
116
117 $gateway = new ilTermsOfServiceAcceptanceDatabaseGateway($database);
118 $gateway->trackAcceptance($entity);
119 }

References $result.

◆ testCurrentAcceptanceOfUserIsLoaded()

ilTermsOfServiceAcceptanceDatabaseGatewayTest::testCurrentAcceptanceOfUserIsLoaded ( )

Definition at line 124 of file ilTermsOfServiceAcceptanceDatabaseGatewayTest.php.

125 {
126 $entity = new ilTermsOfServiceAcceptanceEntity();
127
128 $expected = array(
129 'id' => 4711,
130 'usr_id' => 6,
131 'lng' => 'de',
132 'src' => '/path/to/file',
133 'src_type' => 0,
134 'text' => 'PHP Unit',
135 'hash' => md5('PHP Unit'),
136 'accepted_ts' => time()
137 );
138
139 $database = $this->getMockBuilder('ilDB')->disableOriginalConstructor()->getMock();
140 $database->expects($this->once())->method('fetchAssoc')->will($this->onConsecutiveCalls($expected));
141 $gateway = new ilTermsOfServiceAcceptanceDatabaseGateway($database);
142 $gateway->loadCurrentAcceptanceOfUser($entity);
143
144 $this->assertEquals($expected['id'], $entity->getId());
145 $this->assertEquals($expected['usr_id'], $entity->getUserId());
146 $this->assertEquals($expected['lng'], $entity->getIso2LanguageCode());
147 $this->assertEquals($expected['src'], $entity->getSource());
148 $this->assertEquals($expected['src_type'], $entity->getSourceType());
149 $this->assertEquals($expected['text'], $entity->getText());
150 $this->assertEquals($expected['accepted_ts'], $entity->getTimestamp());
151 $this->assertEquals($expected['hash'], $entity->getHash());
152 }

◆ testInstanceCanBeCreated()

ilTermsOfServiceAcceptanceDatabaseGatewayTest::testInstanceCanBeCreated ( )

Definition at line 34 of file ilTermsOfServiceAcceptanceDatabaseGatewayTest.php.

35 {
36 $database = $this->getMockBuilder('ilDB')->disableOriginalConstructor()->getMock();
37 $gateway = new ilTermsOfServiceAcceptanceDatabaseGateway($database);
38 $this->assertInstanceOf('ilTermsOfServiceAcceptanceDatabaseGateway', $gateway);
39 }

Field Documentation

◆ $backupGlobals

ilTermsOfServiceAcceptanceDatabaseGatewayTest::$backupGlobals = false
protected

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