19declare(strict_types=1);
 
   29        $database = $this->getMockBuilder(ilDBInterface::class)->getMock();
 
   32        $this->assertInstanceOf(ilTermsOfServiceAcceptanceDatabaseGateway::class, $gateway);
 
   40            ->withDocumentId(4711)
 
   41            ->withTitle(
'Document PHP Unit')
 
   42            ->withSerializedCriteria(
'')
 
   43            ->withText(
'PHP Unit')
 
   44            ->withTimestamp(time())
 
   45            ->withHash(md5($entity->getText()));
 
   49        $database = $this->getMockBuilder(ilDBInterface::class)->getMock();
 
   50        $result = $this->getMockBuilder(ilDBStatement::class)->getMock();
 
   53            ->expects($this->once())
 
   56                'SELECT id FROM tos_versions WHERE hash = %s AND doc_id = %s',
 
   58                [$entity->getHash(), $entity->getDocumentId()]
 
   59            )->willReturn($result);
 
   62            ->expects($this->once())
 
   68            ->expects($this->once())
 
   70            ->with(
'tos_versions')
 
   71            ->willReturn($expected_id);
 
   74            'id' => [
'integer', $expected_id],
 
   75            'doc_id' => [
'integer', $entity->getDocumentId()],
 
   76            'title' => [
'text', $entity->getTitle()],
 
   77            'text' => [
'clob', $entity->getText()],
 
   78            'hash' => [
'text', $entity->getHash()],
 
   79            'ts' => [
'integer', $entity->getTimestamp()]
 
   82            'tosv_id' => [
'integer', $expected_id],
 
   83            'usr_id' => [
'integer', $entity->getUserId()],
 
   84            'criteria' => [
'clob', $entity->getSerializedCriteria()],
 
   85            'ts' => [
'integer', $entity->getTimestamp()]
 
   89            ->expects($this->exactly(2))
 
   92                $this->logicalOr(
'tos_versions', 
'tos_acceptance_track'),
 
   93                $this->logicalOr($expectedVersions, $expectedTracking)
 
   97        $gateway->trackAcceptance($entity);
 
  105            ->withDocumentId(4711)
 
  106            ->withTitle(
'Document PHP Unit')
 
  107            ->withSerializedCriteria(
'')
 
  108            ->withText(
'PHP Unit')
 
  109            ->withTimestamp(time())
 
  110            ->withHash(md5($entity->getText()));
 
  114        $database = $this->getMockBuilder(ilDBInterface::class)->getMock();
 
  115        $result = $this->getMockBuilder(ilDBStatement::class)->getMock();
 
  118            ->expects($this->once())
 
  121                'SELECT id FROM tos_versions WHERE hash = %s AND doc_id = %s',
 
  123                [$entity->getHash(), $entity->getDocumentId()]
 
  124            )->willReturn($result);
 
  127            ->expects($this->once())
 
  133            ->expects($this->once())
 
  134            ->method(
'fetchAssoc')
 
  136            ->willReturn([
'id' => $expected_id]);
 
  138        $expectedTracking = [
 
  139            'tosv_id' => [
'integer', $expected_id],
 
  140            'usr_id' => [
'integer', $entity->getUserId()],
 
  141            'criteria' => [
'clob', $entity->getSerializedCriteria()],
 
  142            'ts' => [
'integer', $entity->getTimestamp()]
 
  145            ->expects($this->once())
 
  147            ->with(
'tos_acceptance_track', $expectedTracking);
 
  150        $gateway->trackAcceptance($entity);
 
  160            'title' => 
'Document PHP Unit',
 
  163            'text' => 
'PHP Unit',
 
  164            'hash' => md5(
'PHP Unit'),
 
  165            'accepted_ts' => time()
 
  168        $database = $this->getMockBuilder(ilDBInterface::class)->getMock();
 
  170            ->expects($this->once())
 
  171            ->method(
'fetchAssoc')
 
  172            ->will($this->onConsecutiveCalls($expected));
 
  175        $entity = $gateway->loadCurrentAcceptanceOfUser($entity);
 
  177        $this->assertSame($expected[
'id'], $entity->getId());
 
  178        $this->assertSame($expected[
'usr_id'], $entity->getUserId());
 
  179        $this->assertSame($expected[
'doc_id'], $entity->getDocumentId());
 
  180        $this->assertSame($expected[
'title'], $entity->getTitle());
 
  181        $this->assertSame($expected[
'criteria'], $entity->getSerializedCriteria());
 
  182        $this->assertSame($expected[
'text'], $entity->getText());
 
  183        $this->assertSame($expected[
'accepted_ts'], $entity->getTimestamp());
 
  184        $this->assertSame($expected[
'hash'], $entity->getHash());
 
  190        $entity = $entity->withUserId(4711);
 
  192        $database = $this->getMockBuilder(ilDBInterface::class)->getMock();
 
  195            ->expects($this->once())
 
  197            ->with($entity->getUserId(), 
'integer')
 
  198            ->willReturn((
string) $entity->getUserId());
 
  201            ->expects($this->once())
 
  202            ->method(
'manipulate')
 
  203            ->with(
'DELETE FROM tos_acceptance_track WHERE usr_id = ' . $entity->getUserId());
 
  206        $gateway->deleteAcceptanceHistoryByUser($entity);
 
  215            'title' => 
'Document PHP Unit',
 
  218            'text' => 
'PHP Unit',
 
  219            'hash' => md5(
'PHP Unit'),
 
  222        $database = $this->getMockBuilder(ilDBInterface::class)->getMock();
 
  224            ->expects($this->once())
 
  225            ->method(
'fetchAssoc')
 
  226            ->will($this->onConsecutiveCalls($expected));
 
  229        $entity = $gateway->loadById($entity);
 
  231        $this->assertSame($expected[
'id'], $entity->getId());
 
  232        $this->assertSame($expected[
'doc_id'], $entity->getDocumentId());
 
  233        $this->assertSame($expected[
'title'], $entity->getTitle());
 
  234        $this->assertSame($expected[
'criteria'], $entity->getSerializedCriteria());
 
  235        $this->assertSame($expected[
'text'], $entity->getText());
 
  236        $this->assertSame($expected[
'hash'], $entity->getHash());
 
Class ilTermsOfServiceAcceptanceDatabaseGatewayTest.
 
testAcceptanceIsTrackedAndCreatesANewTermsOfServicesVersionIfNecessary()
 
testAcceptanceHistoryRecordCanBeLoadedById()
 
testAcceptanceHistoryOfAUserCanBeDeleted()
 
testInstanceCanBeCreated()
 
testLatestAcceptanceOfUserCanBeLoaded()
 
testAcceptanceIsTrackedAndRefersToAnExistingTermsOfServicesVersion()
 
Class ilTermsOfServiceAcceptanceDatabaseGateway.
 
Class ilTermsOfServiceAcceptanceEntity.
 
Class ilTermsOfServiceBaseTest.