server/src/tests/Models/DocumentTest.php
changeset 20 a9b98b16b053
parent 19 eadaf0b8f02e
child 28 b0b56e0f8c7f
equal deleted inserted replaced
19:eadaf0b8f02e 20:a9b98b16b053
     1 <?php
     1 <?php
     2 
     2 
     3 use CorpusParole\Models\Document;
     3 use CorpusParole\Models\Document;
       
     4 use CorpusParole\Libraries\CocoonUtils;
     4 
     5 
     5 /**
     6 /**
     6  *
     7  *
     7  */
     8  */
     8 class DocumentTest extends TestCase {
     9 class DocumentTest extends TestCase {
   118         $this->assertEquals("CFPP2000 [03-01] Ozgur_Kilic_H_32_alii_3e Entretien de Ozgur KILIÇ 2",$doc->getTitle(),'Must have correct title');
   119         $this->assertEquals("CFPP2000 [03-01] Ozgur_Kilic_H_32_alii_3e Entretien de Ozgur KILIÇ 2",$doc->getTitle(),'Must have correct title');
   119         $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getTitle(), "Title must be a literal");
   120         $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getTitle(), "Title must be a literal");
   120         $this->assertEquals('fr', $doc->getTitle()->getLang(), "Language title must be fr");
   121         $this->assertEquals('fr', $doc->getTitle()->getLang(), "Language title must be fr");
   121     }
   122     }
   122 
   123 
       
   124     public function testModified() {
       
   125         $this->assertNotNull($this->graph, 'Graph shoud not be null');
       
   126 
       
   127         $doc = new Document("http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-CFPP2000_35_SOUND", $this->graph);
       
   128         $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getModified(), "Modified must be a literal");
       
   129         $this->assertEquals("http://purl.org/dc/terms/W3CDTF", $doc->getModified()->getDatatypeURI(), "type must be http://purl.org/dc/terms/W3CDTF");
       
   130         $this->assertEquals("2013-10-12T14:35:57+02:00", $doc->getModified(), "modified must be 2013-10-12T14:35:57+02:00");
       
   131 
       
   132     }
       
   133 
       
   134 
   123     public function testPublisher() {
   135     public function testPublisher() {
   124 
   136 
   125         $doc = new Document("http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-CFPP2000_35_SOUND", $this->graph);
   137         $doc = new Document("http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-CFPP2000_35_SOUND", $this->graph);
   126 
   138 
   127         $this->assertCount(1, $doc->getPublishers(), 'Publisher is an array of size 1');
   139         $this->assertCount(1, $doc->getPublishers(), 'Publisher is an array of size 1');
   167                 $this->assertGreaterThan(0, $media['extent_ms'], "extent_ms must be > 0");
   179                 $this->assertGreaterThan(0, $media['extent_ms'], "extent_ms must be > 0");
   168                 $this->assertStringStartsWith('audio/', $media['format']);
   180                 $this->assertStringStartsWith('audio/', $media['format']);
   169             }
   181             }
   170             else {
   182             else {
   171                 $this->assertNull($media['extent'], "no media extent");
   183                 $this->assertNull($media['extent'], "no media extent");
   172                 $this->assertSame(0, $media['extent_ms'], "extend in ms is 0");
   184                 $this->assertNull($media['extent_ms'], "extend in ms is null");
   173                 $this->assertStringStartsWith('application/', $media['format']);
   185                 $this->assertStringStartsWith('application/', $media['format']);
   174             }
   186             }
   175 
   187 
   176         }
   188         }
   177     }
   189     }
   300         $doc2 = new Document("http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-CFPP2000_35_SOUND", new EasyRdf\Graph("http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-CFPP2000_35_SOUND", DocumentTest::TEST_DOC));
   312         $doc2 = new Document("http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-CFPP2000_35_SOUND", new EasyRdf\Graph("http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-CFPP2000_35_SOUND", DocumentTest::TEST_DOC));
   301 
   313 
   302         $this->assertFalse($doc->isIsomorphic($doc2),"document must not be isomorphic after adding discourse type");
   314         $this->assertFalse($doc->isIsomorphic($doc2),"document must not be isomorphic after adding discourse type");
   303     }
   315     }
   304 
   316 
       
   317     public function testGetContributors() {
       
   318         $doc = new Document("http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-CFPP2000_35_SOUND", $this->graph);
       
   319 
       
   320         $contributors = $doc->getContributors();
       
   321 
       
   322         $this->assertNotEmpty($contributors, "The contributors array should not be empty");
       
   323         $this->assertCount(8, $contributors, "The contributors array should have 8 elements");
       
   324 
       
   325         foreach ($contributors as $contribDef) {
       
   326             $this->assertArrayHasKey('name', $contribDef, "ContribDef must have name key");
       
   327             $this->assertArrayHasKey('url', $contribDef, "ContribDef must have url key");
       
   328             $this->assertArrayHasKey('role', $contribDef, "ContribDef must have role key");
       
   329             $this->assertContains($contribDef['role'], CocoonUtils::OLAC_ROLES, "Role should be in OLAC_ROLES");
       
   330         }
       
   331     }
       
   332 
   305 }
   333 }