diff -r ef32bf573d9c -r bd4bc1db4f40 server/src/tests/Models/GeoResourceTest.php --- a/server/src/tests/Models/GeoResourceTest.php Thu Sep 08 19:15:46 2016 +0200 +++ b/server/src/tests/Models/GeoResourceTest.php Thu Sep 22 12:38:24 2016 +0200 @@ -1,6 +1,7 @@ << . - @prefix rdfs: . - @prefix sesame: . - @prefix owl: . - @prefix xsd: . - @prefix fn: . - - <%1\$scrdo-CFPP2000_35_SOUND> a ; - ; - "Langage et langues : description, théorisation, transmission" ; - , , ; - ; - ; - "Corpus de la Parole"@fr ; - . - - a ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - ; - , "Tanguy, Noalig" , "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ; - "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 ; - "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" ; - ; - ; - , "anthropological_linguistics"^^ , "lexicography"^^ , "phonetics"^^ , , , , "general_linguistics"^^ , , "text_and_corpus_linguistics"^^ , "Français"@fr , , "phonology"^^ , "semantics"^^ , "sociolinguistics"^^ , "syntax"^^ , "typology"^^ , , , "discourse_analysis"^^ , "historical_linguistics"^^ , "language_documentation"^^ , , , , , , "mathematical_linguistics"^^ ; - "Entretien de Ozgur Kiliç 2"@fr ; - , , , "primary_text"^^ , , "narrative"^^ , "report"^^ , "unintelligible_speech"^^ ; - "2013-10-12"^^ ; - [ - a ; - owl:sameAs ; - "FR"^^ , "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 - ]; - , ; - ; - ; - "Tanguy, Noalig" ; - "Quartier concerné : 3e"@fr ; - "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ; - . - - - a ; - "application/xml"^^ ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "2013-11-04T22:20:07+01:00"^^ ; - ; - . - - a ; - "audio/x-wav"^^ ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - . - - a ; - "audio/mpeg"^^ ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - ; - . - - a ; - "audio/x-wav"^^ ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - ; - . -EOT - , - "LOC2" => << . - @prefix rdfs: . - @prefix sesame: . - @prefix owl: . - @prefix xsd: . - @prefix fn: . - - a ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - ; - "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 ; - "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" ; - ; - ; - "Entretien de Ozgur Kiliç 2"@fr ; - "2013-10-12"^^ ; - [ - a ; - "FR"^^ , "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 - ] . -EOT - , - "LOC3" => << . - @prefix rdfs: . - @prefix sesame: . - @prefix owl: . - @prefix xsd: . - @prefix fn: . - - a ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - ; - "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 ; - "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" ; - ; - ; - "Entretien de Ozgur Kiliç 2"@fr ; - "2013-10-12"^^ ; - [ - a ; - owl:sameAs ; - owl:sameAs ; - "FR"^^ , "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 - ] . -EOT + "LOC1" => __DIR__.'/files/GeoResourceTest/loc1.ttl', + "LOC2" => __DIR__.'/files/GeoResourceTest/loc2.ttl', + "LOC3" => __DIR__.'/files/GeoResourceTest/loc3.ttl', ]; public function setUp() { @@ -152,18 +22,27 @@ $this->graphUrl = sprintf("%1\$scrdo-CFPP2000_35_SOUND", config('corpusparole.corpus_doc_id_base_uri')); foreach(self::TEST_DOCS as $k => $ttl) { - $this->graphs[$k] = new EasyRdf\Graph($this->graphUrl, sprintf($ttl, config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme'))); + $this->graphs[$k] = new EasyRdf\Graph($this->graphUrl, sprintf(file_get_contents($ttl), config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme'))); } } public function getGeoResource($key) { $graph = $this->graphs[$key]; + $providedCHO = $graph->get("<".config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND>", ""); $places = $graph->allOfType(""); assert(count($places)>0); $place = $places[0]; - return new GeoResource($place->getUri(), $graph); + return new GeoResource($place->getUri(), $graph, $providedCHO); + + } + + public function getGeoResourceEdit($key) { + $graph = $this->graphs[$key]; + $doc = new Document($this->graphUrl, $graph); + + return $doc->addGeoInfo(); } @@ -218,13 +97,32 @@ } + public function testLatitude() { + + $geoInfo = $this->getGeoResource("LOC1"); + + $this->assertEquals(48.73194, $geoInfo->getLatitude()->getValue(),'Must have correct latitude'); + $this->assertInstanceOf(EasyRdf\Literal::class, $geoInfo->getLatitude(), "Latitude must be a literal"); + $this->assertEquals('http://www.w3.org/2001/XMLSchema#float', $geoInfo->getLatitude()->getDatatypeUri(), "Datatype title must be 'http://www.w3.org/2001/XMLSchema#float'"); + } + + public function testLongitude() { + + $geoInfo = $this->getGeoResource("LOC1"); + + $this->assertEquals(7.70833, $geoInfo->getLongitude()->getValue(),'Must have correct longitude'); + $this->assertInstanceOf(EasyRdf\Literal::class, $geoInfo->getLongitude(), "Longitude must be a literal"); + $this->assertEquals('http://www.w3.org/2001/XMLSchema#float', $geoInfo->getLongitude()->getDatatypeUri(), "Datatype title must be 'http://www.w3.org/2001/XMLSchema#float'"); + } + + public function testJsonSerialize() { $geoResource = $this->getGeoResource("LOC1"); $json = $geoResource->jsonSerialize(); - $this->assertEquals(["ref-locs", "notes"], array_keys($json)); + $this->assertEquals(["ref-locs", "notes", "latitude", "longitude"], array_keys($json)); $this->assertEquals(["http://sws.geonames.org/6618626/"], $json['ref-locs']); $notes = $json['notes']; @@ -248,10 +146,50 @@ $json = $geoResource->jsonSerialize(); - $this->assertEquals(["ref-locs", "notes"], array_keys($json)); + $this->assertEquals(["ref-locs", "notes", "latitude", "longitude"], array_keys($json)); $this->assertEquals(["http://sws.geonames.org/6618626/", "http://fr.dbpedia.org/resource/Gramazie"], $json['ref-locs']); } + public function testSetRefLocs() { + + $geoResource = $this->getGeoResourceEdit("LOC1"); + + + + $oldRefLocs = $geoResource->getRefLocs(); + sort($oldRefLocs); + + $newRefLocs = [ 'http://sws.geonames.org/2643743/' ]; + + $geoResource->setRefLocs($newRefLocs); + + $refLoc = $geoResource->getRefLocs(); + + $this->assertEquals(['http://sws.geonames.org/2643743/'], $refLoc); + + $geoResource->commit(); + + $deltaList = $geoResource->getDeltaList(); + + $this->assertNotNull($deltaList); + $this->assertCount(1, $deltaList, "Must have one delta"); + + + $delta = $deltaList[0]; + + $this->assertTrue($delta->getDeletedGraph()->isEmpty(), "deleted graph must be empty"); + $this->assertCount(1, $delta->getDeleteWhere(), "Delete where must have one element"); + $this->assertNotNull($delta->getAddedGraph(), "Added graph is not null"); + $this->assertEquals(9, $delta->getAddedGraph()->countTriples(), "Added graph must have 7 triples"); + $places = $delta->getAddedGraph()->allOfType("http://www.europeana.eu/schemas/edm/Place"); + $this->assertCount(1, $places); + $place = $places[0]; + $sames = $places[0]->all(''); + $this->assertCount(1, $sames); + $this->assertEquals('http://sws.geonames.org/2643743/', $sames[0]->getUri()); + + } + }