/** * @param ilTermsOfServiceAcceptanceEntity $entity */ public function trackAcceptance(ilTermsOfServiceAcceptanceEntity $entity) { $query = 'SELECT id FROM tos_versions WHERE hash = %s AND lng = %s'; $res = $this->db->queryF($query, array('text', 'text'), array($entity->getHash(), $entity->getIso2LanguageCode())); if ($this->db->numRows($res)) { $row = $this->db->fetchAssoc($res); $tosv_id = $row['id']; } else { $tosv_id = $this->db->nextId('tos_versions'); $this->db->insert('tos_versions', array('id' => array('integer', $tosv_id), 'lng' => array('text', $entity->getIso2LanguageCode()), 'src' => array('text', $entity->getSource()), 'src_type' => array('integer', $entity->getSourceType()), 'text' => array('clob', $entity->getText()), 'hash' => array('text', $entity->getHash()), 'ts' => array('integer', $entity->getTimestamp()))); } $this->db->insert('tos_acceptance_track', array('tosv_id' => array('integer', $tosv_id), 'usr_id' => array('integer', $entity->getUserId()), 'ts' => array('integer', $entity->getTimestamp()))); }
/** * */ public function testAcceptanceIsTrackedAndRefersToAnExistingTermsOfServicesVersion() { $entity = new ilTermsOfServiceAcceptanceEntity(); $entity->setUserId(666); $entity->setIso2LanguageCode('de'); $entity->setSource('/path/to/file'); $entity->setSourceType(0); $entity->setText('PHP Unit'); $entity->setTimestamp(time()); $entity->setHash(md5($entity->getText())); $expected_id = 4711; $database = $this->getMockBuilder('ilDB')->disableOriginalConstructor()->getMock(); $result = $this->getMockBuilder('MDB2_BufferedResult_mysqli')->disableOriginalConstructor()->getMock(); $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)); $database->expects($this->once())->method('numRows')->with($result)->will($this->returnValue(1)); $database->expects($this->once())->method('fetchAssoc')->with($result)->will($this->returnValue(array('id' => $expected_id))); $expectedTracking = array('tosv_id' => array('integer', $expected_id), 'usr_id' => array('integer', $entity->getUserId()), 'ts' => array('integer', $entity->getTimestamp())); $database->expects($this->once())->method('insert')->with('tos_acceptance_track', $expectedTracking); $gateway = new ilTermsOfServiceAcceptanceDatabaseGateway($database); $gateway->trackAcceptance($entity); }
/** * */ public function testEntityShouldReturnTimestampWhenTimestampIsSet() { $expected = time(); $entity = new ilTermsOfServiceAcceptanceEntity(); $entity->setTimestamp($expected); $this->assertEquals($expected, $entity->getTimestamp()); }