server/src/tests/Models/DocumentTest.php
changeset 28 b0b56e0f8c7f
parent 20 a9b98b16b053
child 111 af85c436048f
equal deleted inserted replaced
27:a2342f26c9de 28:b0b56e0f8c7f
   300             $this->assertContains($dt, $resQueryDiscourseType, "all discourse types must be in result list");
   300             $this->assertContains($dt, $resQueryDiscourseType, "all discourse types must be in result list");
   301         }
   301         }
   302 
   302 
   303     }
   303     }
   304 
   304 
       
   305     public function testUpdateTitle() {
       
   306         $doc = new Document("http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-CFPP2000_35_SOUND", $this->graph);
       
   307 
       
   308         $oldTitle = $doc->getTitle();
       
   309 
       
   310         $doc->setTitle("new title", "en");
       
   311 
       
   312         $this->assertEquals("new title", $doc->getTitleValue());
       
   313         $this->assertEquals("new title", $doc->getTitle()->getValue());
       
   314         $this->assertEquals("en", $doc->getTitle()->getLang());
       
   315 
       
   316         $this->assertTrue($doc->isDirty());
       
   317         $this->assertEquals(1, $doc->deltaCount(), "There is one delta");
       
   318 
       
   319         $delta = $doc->getDeltaList()[0];
       
   320 
       
   321         $addedTitles = $delta->getAddedGraph()->allLiterals($doc->getProvidedCHO(), '<http://purl.org/dc/elements/1.1/title>');
       
   322         $this->assertCount(1, $addedTitles);
       
   323 
       
   324         $removedTitles = $delta->getDeletedGraph()->allLiterals($doc->getProvidedCHO(), '<http://purl.org/dc/elements/1.1/title>');
       
   325         $this->assertCount(1, $removedTitles);
       
   326 
       
   327 
       
   328     }
       
   329 
   305     public function testUpdateDiscourseTypesIsomorphic() {
   330     public function testUpdateDiscourseTypesIsomorphic() {
   306 
   331 
   307         $newDiscourseTypes = ['oratory','dialogue','narrative'];
   332         $newDiscourseTypes = ['oratory','dialogue','narrative'];
   308 
   333 
   309         $doc = new Document("http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-CFPP2000_35_SOUND", $this->graph);
   334         $doc = new Document("http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-CFPP2000_35_SOUND", $this->graph);
   328             $this->assertArrayHasKey('role', $contribDef, "ContribDef must have role key");
   353             $this->assertArrayHasKey('role', $contribDef, "ContribDef must have role key");
   329             $this->assertContains($contribDef['role'], CocoonUtils::OLAC_ROLES, "Role should be in OLAC_ROLES");
   354             $this->assertContains($contribDef['role'], CocoonUtils::OLAC_ROLES, "Role should be in OLAC_ROLES");
   330         }
   355         }
   331     }
   356     }
   332 
   357 
       
   358     public function testSetContributors() {
       
   359         $doc = new Document("http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-CFPP2000_35_SOUND", $this->graph);
       
   360 
       
   361         $contributors = $doc->getContributors();
       
   362 
       
   363         $contribList = [[
       
   364             "name"=> "Guylaine Brun-Trigaud",
       
   365             "url"=> "http://viaf.org/viaf/56666014",
       
   366             "role"=> "http://www.language-archives.org/OLAC/1.1/data_inputter"
       
   367         ], [
       
   368             "name"=> "LDOR",
       
   369             "url"=> null,
       
   370             "role"=> "http://www.language-archives.org/OLAC/1.1/depositor"
       
   371         ], [
       
   372             "name"=> "Thésaurus Occitan",
       
   373             "url"=> null,
       
   374             "role"=> "http://www.language-archives.org/OLAC/1.1/depositor"
       
   375         ], [
       
   376             "name"=> "Équipe de Recherche en Syntaxe et Sémantique",
       
   377             "url"=> null,
       
   378             "role"=> "http://www.language-archives.org/OLAC/1.1/editor"
       
   379         ], [
       
   380             "name"=> "Bases, corpus, langage",
       
   381             "url"=> null,
       
   382             "role"=> "http://www.language-archives.org/OLAC/1.1/editor"
       
   383         ], [
       
   384             "name"=> "Patrick Sauzet",
       
   385             "url"=> "http://viaf.org/viaf/51700729",
       
   386             "role"=> "http://www.language-archives.org/OLAC/1.1/researcher"
       
   387         ], [
       
   388             "name"=> "Alazet, Pierre",
       
   389             "url"=> null,
       
   390             "role"=> "http://www.language-archives.org/OLAC/1.1/speaker"
       
   391         ], [
       
   392             "name"=> "Del Duca, Jeanne",
       
   393             "url"=> null,
       
   394             "role"=> "http://www.language-archives.org/OLAC/1.1/transcriber"
       
   395         ], [
       
   396             "name"=> "Jane Austen, 1775-1817",
       
   397             "url"=> "http://viaf.org/viaf/102333412",
       
   398             "role"=> "http://www.language-archives.org/OLAC/1.1/compiler"
       
   399         ]];
       
   400 
       
   401         $doc->setContributors($contribList);
       
   402 
       
   403         $newContribs = $doc->getContributors();
       
   404 
       
   405         $this->assertCount(9, $newContribs);
       
   406 
       
   407         $this->assertTrue($doc->isDirty());
       
   408         $this->assertEquals(1, $doc->deltaCount(), "There is one delta");
       
   409 
       
   410         $delta = $doc->getDeltaList()[0];
       
   411 
       
   412         $addedGraph = $delta->getAddedGraph();
       
   413         $this->assertEquals(9, $addedGraph->countTriples());
       
   414 
       
   415         $removedGraph = $delta->getDeletedGraph();
       
   416         $this->assertEquals(count($contributors), $removedGraph->countTriples());
       
   417 
       
   418         $foundJaneAusten = false;
       
   419         foreach ($newContribs as $contribDef) {
       
   420             if(!is_null($contribDef['nameLiteral'])) {
       
   421                 $lit = $contribDef['nameLiteral'];
       
   422                 $this->assertNull($lit->getDatatype(), "Data type must be null $lit");
       
   423                 $this->assertNotNull($lit->getLang(), "lang must not be null $lit");
       
   424             }
       
   425             if($contribDef['url'] == 'http://viaf.org/viaf/102333412') {
       
   426                 $this->assertNull($contribDef['name'], 'Name must be null');
       
   427                 $this->assertNull($contribDef['nameLiteral'], 'Name literal must be null');
       
   428                 $foundJaneAusten = true;
       
   429             }
       
   430         }
       
   431         $this->assertTrue($foundJaneAusten, "Jane austenn not foud");
       
   432 
       
   433     }
       
   434 
   333 }
   435 }