/**
     * @param ilTermsOfServiceAcceptanceEntity $entity
     * @return ilTermsOfServiceAcceptanceEntity
     */
    public function loadById(ilTermsOfServiceAcceptanceEntity $entity)
    {
        $res = $this->db->queryF('
			SELECT *
			FROM tos_versions
			WHERE id = %s
			', array('integer'), array($entity->getId()));
        $row = $this->db->fetchAssoc($res);
        $entity->setId($row['id']);
        $entity->setIso2LanguageCode($row['lng']);
        $entity->setSource($row['src']);
        $entity->setSourceType($row['src_type']);
        $entity->setText($row['text']);
        $entity->setTimestamp($row['ts']);
        $entity->setHash($row['hash']);
        return $entity;
    }
 /**
  *
  */
 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 testEntityShouldReturnHashWhenHashIsSet()
 {
     $expected = 'hash';
     $entity = new ilTermsOfServiceAcceptanceEntity();
     $entity->setHash($expected);
     $this->assertEquals($expected, $entity->getHash());
 }