server/src/tests/Models/DocumentTest.php
changeset 138 3079cbf80006
parent 130 fac22d8c2df8
child 143 023b6d467566
equal deleted inserted replaced
137:1baa7c6bd370 138:3079cbf80006
   123         $this->assertEquals("http://purl.org/dc/terms/W3CDTF", $doc->getModified()->getDatatypeURI(), "type must be http://purl.org/dc/terms/W3CDTF");
   123         $this->assertEquals("http://purl.org/dc/terms/W3CDTF", $doc->getModified()->getDatatypeURI(), "type must be http://purl.org/dc/terms/W3CDTF");
   124         $this->assertEquals("2013-10-12T14:35:57+02:00", $doc->getModified(), "modified must be 2013-10-12T14:35:57+02:00");
   124         $this->assertEquals("2013-10-12T14:35:57+02:00", $doc->getModified(), "modified must be 2013-10-12T14:35:57+02:00");
   125 
   125 
   126     }
   126     }
   127 
   127 
       
   128     public function testSetModified() {
       
   129         $currentTime = gmdate(DateTime::ATOM);
       
   130         $doc = new Document("http://corpusdelaparole.huma-num.fr/corpus/res/crdo-CFPP2000_35_SOUND", $this->graph);
       
   131         $doc->setModified($currentTime);
       
   132         $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getModified(), "Modified must be a literal");
       
   133         $this->assertEquals("http://purl.org/dc/terms/W3CDTF", $doc->getModified()->getDatatypeURI(), "type must be http://purl.org/dc/terms/W3CDTF");
       
   134         $this->assertEquals(preg_replace('/[\+\-]00(\:?)00$/', 'Z', $currentTime), $doc->getModified()->getValue(), "modified must be $currentTime");
       
   135     }
       
   136 
       
   137     public function testSetModifiedNull() {
       
   138         $doc = new Document("http://corpusdelaparole.huma-num.fr/corpus/res/crdo-CFPP2000_35_SOUND", $this->graph);
       
   139         $doc->setModified();
       
   140         $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getModified(), "Modified must be a literal");
       
   141         $this->assertEquals("http://purl.org/dc/terms/W3CDTF", $doc->getModified()->getDatatypeURI(), "type must be http://purl.org/dc/terms/W3CDTF");
       
   142         $foundDateTime = \DateTime::createFromFormat(\DateTime::ATOM, $doc->getModified()->getValue());
       
   143         $nowUTC = new \DateTime('now', new \DateTimeZone("UTC"));
       
   144         $this->assertTrue($nowUTC->getTimestamp() -  $foundDateTime->getTimestamp() < 2, "must have less than 2 seconds diff");
       
   145     }
   128 
   146 
   129     public function testPublisher() {
   147     public function testPublisher() {
   130 
   148 
   131         $doc = new Document("http://corpusdelaparole.huma-num.fr/corpus/res/crdo-CFPP2000_35_SOUND", $this->graph);
   149         $doc = new Document("http://corpusdelaparole.huma-num.fr/corpus/res/crdo-CFPP2000_35_SOUND", $this->graph);
   132 
   150 
   429     public function testGetSubjects() {
   447     public function testGetSubjects() {
   430         $doc = new Document("http://corpusdelaparole.huma-num.fr/corpus/res/crdo-CFPP2000_35_SOUND", $this->graph);
   448         $doc = new Document("http://corpusdelaparole.huma-num.fr/corpus/res/crdo-CFPP2000_35_SOUND", $this->graph);
   431 
   449 
   432         $subjects = $doc->getSubjects();
   450         $subjects = $doc->getSubjects();
   433 
   451 
   434         $this->assertCount(28, $subjects, "Must have 15 subjects");
   452         $this->assertCount(28, $subjects, "Must have 28 subjects");
   435 
   453 
   436         foreach ($doc->getSubjects() as $s) {
   454         foreach ($doc->getSubjects() as $s) {
   437             $this->assertThat(
   455             $this->assertThat(
   438                 $s,
   456                 $s,
   439                 $this->logicalXor(
   457                 $this->logicalXor(
   442                 )
   460                 )
   443             );
   461             );
   444         }
   462         }
   445     }
   463     }
   446 
   464 
       
   465     public function testSetSubjects() {
       
   466         $doc = new Document("http://corpusdelaparole.huma-num.fr/corpus/res/crdo-CFPP2000_35_SOUND", $this->graph);
       
   467 
       
   468         $newSubjects = [
       
   469             "http://ark.bnf.fr/ark:/12148/cb13318415c",
       
   470             "http://ark.bnf.fr/ark:/12148/cb133188907",
       
   471             "http://ark.bnf.fr/ark:/12148/cb11932762f",
       
   472             "http://ark.bnf.fr/ark:/12148/cb133183660",
       
   473             "http://ark.bnf.fr/ark:/12148/cb122368540",
       
   474             "http://ark.bnf.fr/ark:/12148/cb119418302",
       
   475             "http://ark.bnf.fr/ark:/12148/cb135540729",
       
   476             "http://ark.bnf.fr/ark:/12148/cb133192210",
       
   477             "http://ark.bnf.fr/ark:/12148/cb119377452",
       
   478             "http://ark.bnf.fr/ark:/12148/cb13320451h",
       
   479             "http://ark.bnf.fr/ark:/12148/cb13318422n",
       
   480             "http://ark.bnf.fr/ark:/12148/cb11975823c"
       
   481         ];
       
   482 
       
   483         $doc->setSubjects($newSubjects);
       
   484 
       
   485         $this->assertTrue($doc->isDirty(), "The document must have changed");
       
   486 
       
   487         $subjects = $doc->getSubjects();
       
   488 
       
   489         $this->assertCount(12, $subjects, "Must have 12 subjects");
       
   490 
       
   491         foreach ($doc->getSubjects() as $s) {
       
   492             $this->assertInstanceOf('EasyRdf\Resource', $s, "Mustbe a Resource");
       
   493             $this->assertTrue(strrpos($s->getUri(), "http://ark.bnf.fr/ark:/12148/cb") === 0, "Must start with http://ark.bnf.fr/ark:/12148/cb");
       
   494             $this->assertContains($s->getUri(), $newSubjects, "$s must be in new subjects list");
       
   495             if(($key = array_search($s->getUri(), $newSubjects)) !== false) {
       
   496                 unset($newSubjects[$key]);
       
   497             }
       
   498         }
       
   499         $this->assertEmpty($newSubjects, "all subjects must have been removed");
       
   500     }
       
   501 
       
   502 
   447 }
   503 }