server/src/tests/Models/DocumentTest.php
changeset 277 bd4bc1db4f40
parent 169 8fddc113095e
child 326 226d5b17a119
equal deleted inserted replaced
276:ef32bf573d9c 277:bd4bc1db4f40
     1 <?php
     1 <?php
     2 
     2 
     3 use CorpusParole\Models\Document;
     3 use CorpusParole\Models\Document;
     4 use CorpusParole\Libraries\CocoonUtils;
     4 use CorpusParole\Libraries\CocoonUtils;
       
     5 
       
     6 use EasyRdf\RdfNamespace;
     5 
     7 
     6 /**
     8 /**
     7  *
     9  *
     8  */
    10  */
     9 class DocumentTest extends TestCase {
    11 class DocumentTest extends TestCase {
    10 
    12 
    11     const TEST_DOC = <<<EOT
    13     const TEST_INPUT_DOCS = [
    12     @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    14         'TEST' => __DIR__.'/files/DocumentTest/test_doc.ttl',
    13     @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    15         'TEST_NO_GEOINFO' => __DIR__.'/files/DocumentTest/test_no_geoinfo.ttl',
    14     @prefix sesame: <http://www.openrdf.org/schema/sesame#> .
    16     ];
    15     @prefix owl: <http://www.w3.org/2002/07/owl#> .
    17 
    16     @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
    18     private $inputGraphes = [];
    17     @prefix fn: <http://www.w3.org/2005/xpath-functions#> .
       
    18 
       
    19     <%1\$scrdo-CFPP2000_35_SOUND> a <http://www.openarchives.org/ore/terms/Aggregation> ;
       
    20         <http://www.europeana.eu/schemas/edm/aggregatedCHO> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-CFPP2000_35_SOUND> ;
       
    21         <http://www.europeana.eu/schemas/edm/dataProvider> "Langage et langues : description, théorisation, transmission" ;
       
    22         <http://www.europeana.eu/schemas/edm/hasView> <http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml> , <http://cocoon.huma-num.fr/data/cfpp2000/Ozgur_Kilic_H_32_alii_3e-2.mp3> , <http://cocoon.huma-num.fr/data/cfpp2000/Ozgur_Kilic_H_32_alii_3e-2.wav> ;
       
    23         <http://www.europeana.eu/schemas/edm/isShownAt> <http://corpusdelaparole.huma-num.fr/corpus-app#/detail/crdo-CFPP2000_35_SOUND> ;
       
    24         <http://www.europeana.eu/schemas/edm/isShownBy> <http://cocoon.huma-num.fr/data/archi/masters/372593.wav> ;
       
    25         <http://www.europeana.eu/schemas/edm/provider> "Corpus de la Parole"@fr ;
       
    26         <http://www.europeana.eu/schemas/edm/rights> <http://creativecommons.org/licenses/by-nc-sa/4.0/> .
       
    27 
       
    28     <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-CFPP2000_35_SOUND> a <http://www.europeana.eu/schemas/edm/ProvidedCHO> ;
       
    29         <http://purl.org/dc/terms/accessRights> "Freely available for non-commercial use" ;
       
    30         <http://purl.org/dc/terms/created> "2010-11-17"^^<http://purl.org/dc/terms/W3CDTF> ;
       
    31         <http://purl.org/dc/terms/extent> "PT48M26S" ;
       
    32         <http://purl.org/dc/terms/issued> "2013-10-12T14:35:57+02:00"^^<http://purl.org/dc/terms/W3CDTF> ;
       
    33         <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-sa/3.0/> ;
       
    34         <http://purl.org/dc/elements/1.1/contributor> <http://viaf.org/viaf/93752300> , "Tanguy, Noalig" , "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ;
       
    35         <http://purl.org/dc/elements/1.1/description> "Enregistrement issu du Corpus de Français Parlé Parisien des années 2000 (CFPP2000)"@fr , "Quartier(s) concerné(s) : Paris 3e, et 20e (pour l'âge adulte); Anonymisation : Noalig TANGUY;"@fr ;
       
    36         <http://purl.org/dc/elements/1.1/identifier> "ark:/87895/1.17-375004" , "%2\$scrdo-CFPP2000_35_SOUNDid" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35" , "Cote producteur: [03-01] Ozgur_Kilic_H_32_alii_3e"@fr , "ark:/87895/1.17-372593" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35_SOUND" ;
       
    37         <http://purl.org/dc/elements/1.1/language> <http://lexvo.org/id/iso639-3/fra> ;
       
    38         <http://purl.org/dc/elements/1.1/publisher> <http://viaf.org/viaf/142432638>;
       
    39         <http://purl.org/dc/elements/1.1/subject> <http://ark.bnf.fr/ark:/12148/cb13318415c> , "anthropological_linguistics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "lexicography"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "phonetics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , <http://lexvo.org/id/iso639-3/fra> , <http://ark.bnf.fr/ark:/12148/cb133188907> , <http://ark.bnf.fr/ark:/12148/cb11932762f> , "general_linguistics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , <http://ark.bnf.fr/ark:/12148/cb133183660> , "text_and_corpus_linguistics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "Français"@fr , <http://ark.bnf.fr/ark:/12148/cb122368540> , "phonology"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "semantics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "sociolinguistics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "syntax"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "typology"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , <http://ark.bnf.fr/ark:/12148/cb119418302> , <http://ark.bnf.fr/ark:/12148/cb135540729> , "discourse_analysis"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "historical_linguistics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "language_documentation"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , <http://ark.bnf.fr/ark:/12148/cb133192210> , <http://ark.bnf.fr/ark:/12148/cb119377452> , <http://ark.bnf.fr/ark:/12148/cb13320451h> , <http://ark.bnf.fr/ark:/12148/cb13318422n> , <http://ark.bnf.fr/ark:/12148/cb11975823c> , "mathematical_linguistics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> ;
       
    40         <http://purl.org/dc/elements/1.1/title> "Entretien de Ozgur Kiliç 2"@fr ;
       
    41         <http://purl.org/dc/elements/1.1/type> <http://ark.bnf.fr/ark:/12148/cb11932135w> , <http://ark.bnf.fr/ark:/12148/cb12481481z> , <http://purl.org/dc/dcmitype/Sound> , "primary_text"^^<http://www.language-archives.org/OLAC/1.1/linguistic-type> , <http://purl.org/dc/dcmitype/Text> , "narrative"^^<http://www.language-archives.org/OLAC/1.1/discourse-type> , "report"^^<http://www.language-archives.org/OLAC/1.1/discourse-type> , "unintelligible_speech"^^<http://www.language-archives.org/OLAC/1.1/discourse-type> ;
       
    42         <http://purl.org/dc/terms/available> "2013-10-12"^^<http://purl.org/dc/terms/W3CDTF> ;
       
    43         <http://purl.org/dc/terms/spatial> [
       
    44             a <http://www.europeana.eu/schemas/edm/Place> ;
       
    45             owl:sameAs <http://sws.geonames.org/6618626/> ;
       
    46             <http://www.w3.org/2004/02/skos/core#note> "FR"^^<http://purl.org/dc/terms/ISO3166> , "France, Île-de-France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier"@fr , "Domicile de Ozgur Kiliç"@fr , "France, Île-de-France, Paris 20"@fr
       
    47         ];
       
    48         <http://www.europeana.eu/schemas/edm/isGatheredInto> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_LANGUESDEFRANCE> , <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_CFPP2000> ;
       
    49         <http://www.language-archives.org/OLAC/1.1/depositor> <http://viaf.org/viaf/93752300> ;
       
    50         <http://www.language-archives.org/OLAC/1.1/interviewer> <http://viaf.org/viaf/93752300> ;
       
    51         <http://www.language-archives.org/OLAC/1.1/transcriber> "Tanguy, Noalig" ;
       
    52         <http://purl.org/dc/elements/1.1/coverage> "Quartier concerné : 3e"@fr ;
       
    53         <http://www.language-archives.org/OLAC/1.1/responder> "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ;
       
    54         <http://purl.org/dc/elements/1.1/relation> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-CFPP2000_31_SOUND> .
       
    55 
       
    56 
       
    57     <http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml> a <http://www.europeana.eu/schemas/edm/WebResource> ;
       
    58         <http://purl.org/dc/elements/1.1/format> "application/xml"^^<http://purl.org/dc/terms/IMT> ;
       
    59         <http://purl.org/dc/terms/accessRights> "Freely available for non-commercial use" ;
       
    60         <http://purl.org/dc/terms/created> "2010-11-17"^^<http://purl.org/dc/terms/W3CDTF> ;
       
    61         <http://purl.org/dc/terms/issued> "2013-11-04T22:20:07+01:00"^^<http://purl.org/dc/terms/W3CDTF> ;
       
    62         <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-sa/3.0/> ;
       
    63         <http://purl.org/dc/terms/conformsTo> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-dtd_transcriber> .
       
    64 
       
    65     <http://cocoon.huma-num.fr/data/archi/masters/372593.wav> a <http://www.europeana.eu/schemas/edm/WebResource> ;
       
    66         <http://purl.org/dc/elements/1.1/format> "audio/x-wav"^^<http://purl.org/dc/terms/IMT> ;
       
    67         <http://purl.org/dc/terms/accessRights> "Freely available for non-commercial use" ;
       
    68         <http://purl.org/dc/terms/created> "2010-11-17"^^<http://purl.org/dc/terms/W3CDTF> ;
       
    69         <http://purl.org/dc/terms/extent> "PT48M26S" ;
       
    70         <http://purl.org/dc/terms/issued> "2013-10-12T14:35:57+02:00"^^<http://purl.org/dc/terms/W3CDTF> ;
       
    71         <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-sa/3.0/> .
       
    72 
       
    73     <http://cocoon.huma-num.fr/data/cfpp2000/Ozgur_Kilic_H_32_alii_3e-2.mp3> a <http://www.europeana.eu/schemas/edm/WebResource> ;
       
    74         <http://purl.org/dc/elements/1.1/format> "audio/mpeg"^^<http://purl.org/dc/terms/IMT> ;
       
    75         <http://purl.org/dc/terms/accessRights> "Freely available for non-commercial use" ;
       
    76         <http://purl.org/dc/terms/created> "2010-11-17"^^<http://purl.org/dc/terms/W3CDTF> ;
       
    77         <http://purl.org/dc/terms/extent> "PT48M26S" ;
       
    78         <http://purl.org/dc/terms/issued> "2013-10-12T14:35:57+02:00"^^<http://purl.org/dc/terms/W3CDTF> ;
       
    79         <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-sa/3.0/> ;
       
    80         <http://www.europeana.eu/schemas/edm/isDerivativeOf> <http://cocoon.huma-num.fr/data/archi/masters/372593.wav> .
       
    81 
       
    82     <http://cocoon.huma-num.fr/data/cfpp2000/Ozgur_Kilic_H_32_alii_3e-2.wav> a <http://www.europeana.eu/schemas/edm/WebResource> ;
       
    83         <http://purl.org/dc/elements/1.1/format> "audio/x-wav"^^<http://purl.org/dc/terms/IMT> ;
       
    84         <http://purl.org/dc/terms/accessRights> "Freely available for non-commercial use" ;
       
    85         <http://purl.org/dc/terms/created> "2010-11-17"^^<http://purl.org/dc/terms/W3CDTF> ;
       
    86         <http://purl.org/dc/terms/extent> "PT48M26S" ;
       
    87         <http://purl.org/dc/terms/issued> "2013-10-12T14:35:57+02:00"^^<http://purl.org/dc/terms/W3CDTF> ;
       
    88         <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-sa/3.0/> ;
       
    89         <http://www.europeana.eu/schemas/edm/isDerivativeOf> <http://cocoon.huma-num.fr/data/archi/masters/372593.wav> .
       
    90 EOT;
       
    91 
       
    92 
    19 
    93     public function setUp() {
    20     public function setUp() {
    94 
       
    95         parent::setup();
    21         parent::setup();
    96         $this->graph = new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", sprintf(DocumentTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme')));
    22 
       
    23         foreach(self::TEST_INPUT_DOCS as $key => $inputDoc) {
       
    24             $this->inputGraphes[$key] =  new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", sprintf(file_get_contents($inputDoc), config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme')));
       
    25         }
       
    26 
    97 
    27 
    98     }
    28     }
    99 
    29 
   100     public function testConstructor() {
    30     public function testConstructor() {
   101         $this->assertNotNull($this->graph, 'Graph shoud not be null');
    31         $this->assertNotNull($this->inputGraphes['TEST'], 'Graph shoud not be null');
   102 
    32 
   103         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
    33         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   104 
    34 
   105         $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-CFPP2000_35_SOUNDid',$doc->getId(),'Must have the correct id');
    35         $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-CFPP2000_35_SOUNDid',$doc->getId(),'Must have the correct id');
   106     }
    36     }
   107 
    37 
   108     public function testTitle() {
    38     public function testTitle() {
   109         $this->assertNotNull($this->graph, 'Graph shoud not be null');
    39         $this->assertNotNull($this->inputGraphes['TEST'], 'Graph shoud not be null');
   110 
    40 
   111         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
    41         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   112 
    42 
   113         $this->assertEquals("Entretien de Ozgur Kiliç 2",$doc->getTitle(),'Must have correct title');
    43         $this->assertEquals("Entretien de Ozgur Kiliç 2",$doc->getTitle(),'Must have correct title');
   114         $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getTitle(), "Title must be a literal");
    44         $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getTitle(), "Title must be a literal");
   115         $this->assertEquals('fr', $doc->getTitle()->getLang(), "Language title must be fr");
    45         $this->assertEquals('fr', $doc->getTitle()->getLang(), "Language title must be fr");
   116     }
    46     }
   117 
    47 
       
    48 
   118     public function testModified() {
    49     public function testModified() {
   119         $this->assertNotNull($this->graph, 'Graph shoud not be null');
    50         $this->assertNotNull($this->inputGraphes['TEST'], 'Graph shoud not be null');
   120 
    51 
   121         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
    52         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   122         $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getModified(), "Modified must be a literal");
    53         $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getModified(), "Modified must be a literal");
   123         $this->assertEquals("http://purl.org/dc/terms/W3CDTF", $doc->getModified()->getDatatypeURI(), "type must be http://purl.org/dc/terms/W3CDTF");
    54         $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");
    55         $this->assertEquals("2013-10-12T14:35:57+02:00", $doc->getModified(), "modified must be 2013-10-12T14:35:57+02:00");
   125 
    56 
   126     }
    57     }
   127 
    58 
   128     public function testSetModified() {
    59     public function testSetModified() {
   129         $currentTime = gmdate(DateTime::ATOM);
    60         $currentTime = gmdate(DateTime::ATOM);
   130         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
    61         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   131         $doc->setModified($currentTime);
    62         $doc->setModified($currentTime);
   132         $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getModified(), "Modified must be a literal");
    63         $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");
    64         $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");
    65         $this->assertEquals(preg_replace('/[\+\-]00(\:?)00$/', 'Z', $currentTime), $doc->getModified()->getValue(), "modified must be $currentTime");
   135     }
    66     }
   136 
    67 
   137     public function testSetModifiedNull() {
    68     public function testSetModifiedNull() {
   138         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
    69         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   139         $doc->setModified();
    70         $doc->setModified();
   140         $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getModified(), "Modified must be a literal");
    71         $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");
    72         $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());
    73         $foundDateTime = \DateTime::createFromFormat(\DateTime::ATOM, $doc->getModified()->getValue());
   143         $nowUTC = new \DateTime('now', new \DateTimeZone("UTC"));
    74         $nowUTC = new \DateTime('now', new \DateTimeZone("UTC"));
   144         $this->assertTrue($nowUTC->getTimestamp() -  $foundDateTime->getTimestamp() < 2, "must have less than 2 seconds diff");
    75         $this->assertTrue($nowUTC->getTimestamp() -  $foundDateTime->getTimestamp() < 2, "must have less than 2 seconds diff");
   145     }
    76     }
   146 
    77 
   147     public function testPublisher() {
    78     public function testPublisher() {
   148 
    79 
   149         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
    80         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   150 
    81 
   151         $this->assertCount(1, $doc->getPublishers(), 'Publisher is an array of size 1');
    82         $this->assertCount(1, $doc->getPublishers(), 'Publisher is an array of size 1');
   152         $this->assertInstanceOf('EasyRdf\Resource', $doc->getPublishers()[0], 'publisher is a resource');
    83         $this->assertInstanceOf('EasyRdf\Resource', $doc->getPublishers()[0], 'publisher is a resource');
   153         $this->assertEquals("http://viaf.org/viaf/142432638", $doc->getPublishers()[0]->getUri(),"");
    84         $this->assertEquals("http://viaf.org/viaf/142432638", $doc->getPublishers()[0]->getUri(),"");
   154     }
    85     }
   155 
    86 
   156     public function testMediaArray() {
    87     public function testMediaArray() {
   157         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
    88         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   158 
    89 
   159         $this->assertCount(3, $doc->getMediaArray(), "Media array must be of size 3");
    90         $this->assertCount(3, $doc->getMediaArray(), "Media array must be of size 3");
   160         //print_r($doc->getMediaArray());
    91         //print_r($doc->getMediaArray());
   161         foreach($doc->getMediaArray() as $media) {
    92         foreach($doc->getMediaArray() as $media) {
   162             $this->assertInstanceOf('CorpusParole\Models\MediaResource', $media, "media msute of type MediaResource");
    93             $this->assertInstanceOf('CorpusParole\Models\MediaResource', $media, "media msute of type MediaResource");
   189             $this->assertStringStartsWith('audio/', $media->getFormat());
   120             $this->assertStringStartsWith('audio/', $media->getFormat());
   190         }
   121         }
   191     }
   122     }
   192 
   123 
   193     public function testGetTypes() {
   124     public function testGetTypes() {
   194         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
   125         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   195 
   126 
   196         $this->assertCount(8, $doc->getTypes(), "types array must be of size 5");
   127         $this->assertCount(8, $doc->getTypes(), "types array must be of size 5");
   197 
   128 
   198         foreach($doc->getTypes() as $type) {
   129         foreach($doc->getTypes() as $type) {
   199             $this->assertThat(
   130             $this->assertThat(
   205             );
   136             );
   206         }
   137         }
   207     }
   138     }
   208 
   139 
   209     public function testGetOtherTypes() {
   140     public function testGetOtherTypes() {
   210         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
   141         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   211 
   142 
   212         $this->assertCount(5, $doc->getOtherTypes(), "types array must be of size 5");
   143         $this->assertCount(5, $doc->getOtherTypes(), "types array must be of size 5");
   213 
   144 
   214         foreach($doc->getTypes() as $type) {
   145         foreach($doc->getTypes() as $type) {
   215             $this->assertThat(
   146             $this->assertThat(
   221             );
   152             );
   222         }
   153         }
   223     }
   154     }
   224 
   155 
   225     public function testGetDiscourseTypes() {
   156     public function testGetDiscourseTypes() {
   226         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
   157         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   227 
   158 
   228         $this->assertCount(3, $doc->getDiscourseTypes(), "types array must be of size 3");
   159         $this->assertCount(3, $doc->getDiscourseTypes(), "types array must be of size 3");
   229 
   160 
   230         $this->assertContainsOnlyInstancesOf("EasyRdf\Literal", $doc->getDiscourseTypes(), "Result contains only literals");
   161         $this->assertContainsOnlyInstancesOf("EasyRdf\Literal", $doc->getDiscourseTypes(), "Result contains only literals");
   231         $type = $doc->getDiscourseTypes()[0];
   162         $type = $doc->getDiscourseTypes()[0];
   232         $this->assertEquals("narrative", $type->getValue(), "discourse type is narrative");
   163         $this->assertEquals("narrative", $type->getValue(), "discourse type is narrative");
   233         $this->assertEquals("http://www.language-archives.org/OLAC/1.1/discourse-type", $type->getDatatypeUri(), "discourse type url");
   164         $this->assertEquals("http://www.language-archives.org/OLAC/1.1/discourse-type", $type->getDatatypeUri(), "discourse type url");
   234     }
   165     }
   235 
   166 
   236     public function testCloneDocument() {
   167     public function testCloneDocument() {
   237         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
   168         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   238 
   169 
   239         $doc2 = clone $doc;
   170         $doc2 = clone $doc;
   240 
   171 
   241         $this->assertNotSame($doc, $doc2, "documents must not be the same");
   172         $this->assertNotSame($doc, $doc2, "documents must not be the same");
   242         $this->assertNotSame($doc->getGraph(), $doc2->getGraph(), "documents must not be the same");
   173         $this->assertNotSame($doc->getGraph(), $doc2->getGraph(), "documents must not be the same");
   243 
   174 
   244         $this->assertTrue(EasyRdf\Isomorphic::isomorphic($doc->getGraph(), $doc2->getGraph()),"graph must be isomorphic");
   175         $this->assertTrue(EasyRdf\Isomorphic::isomorphic($doc->getGraph(), $doc2->getGraph()),"graph must be isomorphic");
   245     }
   176     }
   246 
   177 
   247     public function testIsIsomorphic() {
   178     public function testIsIsomorphic() {
   248         $doc1 = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
   179         $doc1 = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   249         $doc2 = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", sprintf(DocumentTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme'))));
   180         $doc2 = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", sprintf(file_get_contents(DocumentTest::TEST_INPUT_DOCS['TEST']) , config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme'))));
   250 
   181 
   251         $this->assertTrue($doc1->isIsomorphic($doc2),"document must be isomorphic");
   182         $this->assertTrue($doc1->isIsomorphic($doc2),"document must be isomorphic");
   252 
   183 
   253         $doc2->addLiteral('dc11:type', new EasyRdf\Literal("oratory", null, Config::get('OLAC_DISCOURSE_TYPE')['uri']));
   184         $doc2->addLiteral('dc11:type', new EasyRdf\Literal("oratory", null, Config::get('OLAC_DISCOURSE_TYPE')['uri']));
   254 
   185 
   257 
   188 
   258     public function testUpdateDiscourseTypes() {
   189     public function testUpdateDiscourseTypes() {
   259 
   190 
   260         $newDiscourseTypes = ['oratory','dialogue','narrative', 'formulaic', 'ludic'];
   191         $newDiscourseTypes = ['oratory','dialogue','narrative', 'formulaic', 'ludic'];
   261 
   192 
   262         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
   193         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   263         $this->assertCount(3, $doc->getDiscourseTypes(), "types array must be of size 3");
   194         $this->assertCount(3, $doc->getDiscourseTypes(), "types array must be of size 3");
   264 
   195 
   265         $doc->updateDiscourseTypes($newDiscourseTypes);
   196         $doc->updateDiscourseTypes($newDiscourseTypes);
   266 
   197 
   267         $this->assertCount(5, $doc->getDiscourseTypes(), "types array must be of size 5");
   198         $this->assertCount(5, $doc->getDiscourseTypes(), "types array must be of size 5");
   275 
   206 
   276     public function testUpdateDiscourseTypesDelta() {
   207     public function testUpdateDiscourseTypesDelta() {
   277 
   208 
   278         $newDiscourseTypes = ['oratory','dialogue','narrative', 'formulaic', 'ludic'];
   209         $newDiscourseTypes = ['oratory','dialogue','narrative', 'formulaic', 'ludic'];
   279 
   210 
   280         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
   211         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   281 
   212 
   282         $doc->updateDiscourseTypes($newDiscourseTypes);
   213         $doc->updateDiscourseTypes($newDiscourseTypes);
   283 
   214 
   284         $this->assertTrue($doc->isDirty());
   215         $this->assertTrue($doc->isDirty());
   285 
   216 
   303         }
   234         }
   304 
   235 
   305     }
   236     }
   306 
   237 
   307     public function testUpdateTitle() {
   238     public function testUpdateTitle() {
   308         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
   239         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   309 
   240 
   310         $oldTitle = $doc->getTitle();
   241         $oldTitle = $doc->getTitle();
   311 
   242 
   312         $doc->setTitle("new title", "en");
   243         $doc->setTitle("new title", "en");
   313 
   244 
   331 
   262 
   332     public function testUpdateDiscourseTypesIsomorphic() {
   263     public function testUpdateDiscourseTypesIsomorphic() {
   333 
   264 
   334         $newDiscourseTypes = ['oratory','dialogue','narrative'];
   265         $newDiscourseTypes = ['oratory','dialogue','narrative'];
   335 
   266 
   336         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
   267         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   337         $doc->updateDiscourseTypes($newDiscourseTypes);
   268         $doc->updateDiscourseTypes($newDiscourseTypes);
   338 
   269 
   339         $doc2 = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", sprintf(DocumentTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme'))));
   270         $doc2 = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", sprintf(file_get_contents(DocumentTest::TEST_INPUT_DOCS['TEST']), config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme'))));
   340 
   271 
   341         $this->assertFalse($doc->isIsomorphic($doc2),"document must not be isomorphic after adding discourse type");
   272         $this->assertFalse($doc->isIsomorphic($doc2),"document must not be isomorphic after adding discourse type");
   342     }
   273     }
   343 
   274 
   344     public function testGetContributors() {
   275     public function testGetContributors() {
   345         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
   276         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   346 
   277 
   347         $contributors = $doc->getContributors();
   278         $contributors = $doc->getContributors();
   348 
   279 
   349         $this->assertNotEmpty($contributors, "The contributors array should not be empty");
   280         $this->assertNotEmpty($contributors, "The contributors array should not be empty");
   350         $this->assertCount(8, $contributors, "The contributors array should have 8 elements");
   281         $this->assertCount(8, $contributors, "The contributors array should have 8 elements");
   356             $this->assertContains($contribDef['role'], CocoonUtils::OLAC_ROLES, "Role should be in OLAC_ROLES");
   287             $this->assertContains($contribDef['role'], CocoonUtils::OLAC_ROLES, "Role should be in OLAC_ROLES");
   357         }
   288         }
   358     }
   289     }
   359 
   290 
   360     public function testSetContributors() {
   291     public function testSetContributors() {
   361         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
   292         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   362 
   293 
   363         $contributors = $doc->getContributors();
   294         $contributors = $doc->getContributors();
   364 
   295 
   365         $contribList = [[
   296         $contribList = [[
   366             "name"=> "Guylaine Brun-Trigaud",
   297             "name"=> "Guylaine Brun-Trigaud",
   433         $this->assertTrue($foundJaneAusten, "Jane austenn not foud");
   364         $this->assertTrue($foundJaneAusten, "Jane austenn not foud");
   434 
   365 
   435     }
   366     }
   436 
   367 
   437     public function testGetSubjects() {
   368     public function testGetSubjects() {
   438         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
   369         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   439 
   370 
   440         $subjects = $doc->getSubjects();
   371         $subjects = $doc->getSubjects();
   441 
   372 
   442         $this->assertCount(28, $subjects, "Must have 28 subjects");
   373         $this->assertCount(28, $subjects, "Must have 28 subjects");
   443 
   374 
   451             );
   382             );
   452         }
   383         }
   453     }
   384     }
   454 
   385 
   455     public function testSetSubjects() {
   386     public function testSetSubjects() {
   456         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
   387         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   457 
   388 
   458         $newSubjects = [
   389         $newSubjects = [
   459             "http://ark.bnf.fr/ark:/12148/cb13318415c",
   390             "http://ark.bnf.fr/ark:/12148/cb13318415c",
   460             "http://ark.bnf.fr/ark:/12148/cb133188907",
   391             "http://ark.bnf.fr/ark:/12148/cb133188907",
   461             "http://ark.bnf.fr/ark:/12148/cb11932762f",
   392             "http://ark.bnf.fr/ark:/12148/cb11932762f",
   489         $this->assertEmpty($newSubjects, "all subjects must have been removed");
   420         $this->assertEmpty($newSubjects, "all subjects must have been removed");
   490     }
   421     }
   491 
   422 
   492     //TODO: test null transcript + null media array
   423     //TODO: test null transcript + null media array
   493     public function testJsonSerialize() {
   424     public function testJsonSerialize() {
   494         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph);
   425         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
   495 
   426 
   496         $json = $doc->jsonSerialize();
   427         $json = $doc->jsonSerialize();
   497 
   428 
   498         $this->assertTrue(is_array($json), 'Returned json must be an array');
   429         $this->assertTrue(is_array($json), 'Returned json must be an array');
   499         $this->assertEquals(
   430         $this->assertEquals(
   504         $this->assertTrue(is_array($json['transcript']));
   435         $this->assertTrue(is_array($json['transcript']));
   505         $this->assertTrue(is_array($json['mediaArray']));
   436         $this->assertTrue(is_array($json['mediaArray']));
   506 
   437 
   507     }
   438     }
   508 
   439 
       
   440     public function testAddGeoInfo() {
       
   441 
       
   442         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST_NO_GEOINFO']);
       
   443         //$doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
       
   444 
       
   445         $res = $doc->addGeoInfo();
       
   446         $res->commit();
       
   447 
       
   448         $this->assertNotNull($res, "A new georesource object must have been created");
       
   449 
       
   450         $this->assertInstanceOf('CorpusParole\Models\GeoResource', $res, "the object created must be a geo resource");
       
   451 
       
   452         $allSpatials = $doc->getProvidedCHO()->allResources("<http://purl.org/dc/terms/spatial>");
       
   453 
       
   454         $this->assertCount(1, $allSpatials, "Must have only one spatial node");
       
   455 
       
   456         $spatial = $allSpatials[0];
       
   457 
       
   458         $this->assertTrue($spatial->isBNode(), "Spatial node must be a blank node");
       
   459         $this->assertEquals($spatial->typeAsResource(), "http://www.europeana.eu/schemas/edm/Place", "type must be a http://www.europeana.eu/schemas/edm/Place");
       
   460 
       
   461         $this->assertTrue($doc->isDirty(), "Document must be dirty");
       
   462         $this->assertEquals(1, $doc->deltaCount(), "Must have only one delta.");
       
   463 
       
   464         $this->assertNotNull($res->getCurrentDelta(), "CurrentDelta is not null");
       
   465         $this->assertTrue($res->getCurrentDelta()->getDeletedGraph()->isEmpty(), "deleted graph must be empty");
       
   466         $this->assertEmpty($res->getCurrentDelta()->getDeleteWhere(), "Delete where must be empty");
       
   467         $this->assertNotNull($res->getCurrentDelta()->getAddedGraph(), "Added graph is not null");
       
   468         $this->assertEquals(2, $res->getCurrentDelta()->getAddedGraph()->countTriples(), "Added graph must have 2 triples");
       
   469 
       
   470     }
       
   471 
       
   472 
       
   473     public function testAddGeoInfoNotEmpty() {
       
   474 
       
   475         $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
       
   476 
       
   477         $res = $doc->addGeoInfo();
       
   478         $res->commit();
       
   479 
       
   480         $this->assertNotNull($res, "A new georesource object must have been created");
       
   481 
       
   482         $this->assertInstanceOf('CorpusParole\Models\GeoResource', $res, "the object created must be a geo resource");
       
   483 
       
   484         $allSpatials = $doc->getProvidedCHO()->allResources("<http://purl.org/dc/terms/spatial>");
       
   485 
       
   486         $this->assertCount(1, $allSpatials, "Must have only one spatial node");
       
   487 
       
   488         $spatial = $allSpatials[0];
       
   489 
       
   490         $this->assertTrue($spatial->isBNode(), "Spatial node must be a blank node");
       
   491         $this->assertEquals($spatial->typeAsResource(), "http://www.europeana.eu/schemas/edm/Place", "type must be a http://www.europeana.eu/schemas/edm/Place");
       
   492 
       
   493         $this->assertTrue($doc->isDirty(), "Document must not be dirty");
       
   494         $this->assertEquals(1, $doc->deltaCount(), "Must have only one delta.");
       
   495 
       
   496         $this->assertNotNull($res->getCurrentDelta(), "CurrentDelta is not null");
       
   497         $this->assertTrue($res->getCurrentDelta()->getDeletedGraph()->isEmpty(), "deleted graph must be empty");
       
   498         $this->assertCount(1, $res->getCurrentDelta()->getDeleteWhere(), "Delete where must have one element");
       
   499         $this->assertNotNull($res->getCurrentDelta()->getAddedGraph(), "Added graph is not null");
       
   500         $this->assertEquals(9, $res->getCurrentDelta()->getAddedGraph()->countTriples(), "Added graph must have 7 triples");
       
   501     }
       
   502 
   509 
   503 
   510 }
   504 }