server/src/tests/Models/DocumentTest.php
changeset 28 b0b56e0f8c7f
parent 20 a9b98b16b053
child 111 af85c436048f
--- a/server/src/tests/Models/DocumentTest.php	Fri Jan 15 15:27:56 2016 +0100
+++ b/server/src/tests/Models/DocumentTest.php	Fri Jan 15 15:35:00 2016 +0100
@@ -302,6 +302,31 @@
 
     }
 
+    public function testUpdateTitle() {
+        $doc = new Document("http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-CFPP2000_35_SOUND", $this->graph);
+
+        $oldTitle = $doc->getTitle();
+
+        $doc->setTitle("new title", "en");
+
+        $this->assertEquals("new title", $doc->getTitleValue());
+        $this->assertEquals("new title", $doc->getTitle()->getValue());
+        $this->assertEquals("en", $doc->getTitle()->getLang());
+
+        $this->assertTrue($doc->isDirty());
+        $this->assertEquals(1, $doc->deltaCount(), "There is one delta");
+
+        $delta = $doc->getDeltaList()[0];
+
+        $addedTitles = $delta->getAddedGraph()->allLiterals($doc->getProvidedCHO(), '<http://purl.org/dc/elements/1.1/title>');
+        $this->assertCount(1, $addedTitles);
+
+        $removedTitles = $delta->getDeletedGraph()->allLiterals($doc->getProvidedCHO(), '<http://purl.org/dc/elements/1.1/title>');
+        $this->assertCount(1, $removedTitles);
+
+
+    }
+
     public function testUpdateDiscourseTypesIsomorphic() {
 
         $newDiscourseTypes = ['oratory','dialogue','narrative'];
@@ -330,4 +355,81 @@
         }
     }
 
+    public function testSetContributors() {
+        $doc = new Document("http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-CFPP2000_35_SOUND", $this->graph);
+
+        $contributors = $doc->getContributors();
+
+        $contribList = [[
+            "name"=> "Guylaine Brun-Trigaud",
+            "url"=> "http://viaf.org/viaf/56666014",
+            "role"=> "http://www.language-archives.org/OLAC/1.1/data_inputter"
+        ], [
+            "name"=> "LDOR",
+            "url"=> null,
+            "role"=> "http://www.language-archives.org/OLAC/1.1/depositor"
+        ], [
+            "name"=> "Thésaurus Occitan",
+            "url"=> null,
+            "role"=> "http://www.language-archives.org/OLAC/1.1/depositor"
+        ], [
+            "name"=> "Équipe de Recherche en Syntaxe et Sémantique",
+            "url"=> null,
+            "role"=> "http://www.language-archives.org/OLAC/1.1/editor"
+        ], [
+            "name"=> "Bases, corpus, langage",
+            "url"=> null,
+            "role"=> "http://www.language-archives.org/OLAC/1.1/editor"
+        ], [
+            "name"=> "Patrick Sauzet",
+            "url"=> "http://viaf.org/viaf/51700729",
+            "role"=> "http://www.language-archives.org/OLAC/1.1/researcher"
+        ], [
+            "name"=> "Alazet, Pierre",
+            "url"=> null,
+            "role"=> "http://www.language-archives.org/OLAC/1.1/speaker"
+        ], [
+            "name"=> "Del Duca, Jeanne",
+            "url"=> null,
+            "role"=> "http://www.language-archives.org/OLAC/1.1/transcriber"
+        ], [
+            "name"=> "Jane Austen, 1775-1817",
+            "url"=> "http://viaf.org/viaf/102333412",
+            "role"=> "http://www.language-archives.org/OLAC/1.1/compiler"
+        ]];
+
+        $doc->setContributors($contribList);
+
+        $newContribs = $doc->getContributors();
+
+        $this->assertCount(9, $newContribs);
+
+        $this->assertTrue($doc->isDirty());
+        $this->assertEquals(1, $doc->deltaCount(), "There is one delta");
+
+        $delta = $doc->getDeltaList()[0];
+
+        $addedGraph = $delta->getAddedGraph();
+        $this->assertEquals(9, $addedGraph->countTriples());
+
+        $removedGraph = $delta->getDeletedGraph();
+        $this->assertEquals(count($contributors), $removedGraph->countTriples());
+
+        $foundJaneAusten = false;
+        foreach ($newContribs as $contribDef) {
+            if(!is_null($contribDef['nameLiteral'])) {
+                $lit = $contribDef['nameLiteral'];
+                $this->assertNull($lit->getDatatype(), "Data type must be null $lit");
+                $this->assertNotNull($lit->getLang(), "lang must not be null $lit");
+            }
+            if($contribDef['url'] == 'http://viaf.org/viaf/102333412') {
+                $this->assertNull($contribDef['name'], 'Name must be null');
+                $this->assertNull($contribDef['nameLiteral'], 'Name literal must be null');
+                $foundJaneAusten = true;
+            }
+        }
+        $this->assertTrue($foundJaneAusten, "Jane austenn not foud");
+
+    }
+
 }