diff -r ef32bf573d9c -r bd4bc1db4f40 server/src/tests/Repositories/DocumentRepositoryIntegrationTest.php --- a/server/src/tests/Repositories/DocumentRepositoryIntegrationTest.php Thu Sep 08 19:15:46 2016 +0200 +++ b/server/src/tests/Repositories/DocumentRepositoryIntegrationTest.php Thu Sep 22 12:38:24 2016 +0200 @@ -15,87 +15,10 @@ class DocumentRepositoryIntegrationTest extends TestCase { - const REPO_CREATION_TTL = <<. - @prefix rep: . - @prefix sr: . - @prefix sail: . - @prefix ms: . - - [] a rep:Repository ; - rep:repositoryID "%1\$s" ; - rdfs:label "%1\$s test repository" ; - rep:repositoryImpl [ - rep:repositoryType "openrdf:SailRepository" ; - sr:sailImpl [ - sail:sailType "openrdf:MemoryStore" ; - ms:persist false ; - ms:syncDelay 0 - ] - ]. -EOT; - - const TEST_DOC = << . - @prefix rdfs: . - @prefix sesame: . - @prefix owl: . - @prefix xsd: . - @prefix fn: . - - _:genid-2267740936ad4d04a567e6787732f0dd-genid1 a ; - owl:sameAs ; - "northlimit=47.431892250000033; southlimit=49.053971250000046;westlimit=6.846186050000028; eastlimit=8.232571550000074;"^^ , "FR"^^ , "France, Alsace"@fr . - - <%1\$scrdo-ALA_738> a ; - ; - "Atlas linguistiques, cultures et parlers régionaux de France" ; - , ; - ; - ; - "Corpus de la Parole"@fr ; - . + const REPO_CREATION_TTL = __DIR__.'/files/DocumentRepositoryIntegrationTest/repo_creation.ttl'; - a ; - "audio/mpeg"^^ ; - "1996"^^ ; - "PT01H11M29S" ; - "2014-11-10T14:27:08+01:00"^^ ; - . - - a ; - "audio/x-wav"^^ ; - "1996"^^ ; - "PT01H11M29S" ; - "2014-11-10T14:27:08+01:00"^^ . - - a ; - "audio/x-wav"^^ ; - "1996"^^ ; - "PT01H11M29S" ; - "2014-11-10T14:27:08+01:00"^^ ; - . - - a ; - "1996"^^ ; - "PT01H11M29S" ; - "2014-11-10T14:27:08+01:00"^^ ; - , ; - "Extrait des enquêtes dialectologiques en vue de constituer un atlas linguistique de l'Alsace."@fr ; - ; - "Atlas linguistiques, cultures et parlers régionaux de France" ; - "Copyright (c) Département de dialectologie alsacienne et mosellane de l'Université de Strasbourg" ; - , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , "anthropological_linguistics"^^ , "lexicography"^^ , "phonetics"^^ ; - "Atlas Linguistique et ethnographique de l'Alsace - Enquetes sur la conscience linguistique - ALA_738"@fr ; - , , , "dialogue"^^ , "primary_text"^^ ; - "Freely available for non-commercial use" ; - "2004-07-03"^^ ; - , ; - ; - _:genid-2267740936ad4d04a567e6787732f0dd-genid1 ; - ; - , . -EOT; + const TEST_DOC = __DIR__.'/files/DocumentRepositoryIntegrationTest/test_doc.ttl'; + const TEST_DOC_NO_GEO = __DIR__.'/files/DocumentRepositoryIntegrationTest/test_doc_no_geo.ttl'; function __construct(string $name = null) { parent::__construct($name); @@ -103,7 +26,7 @@ public function setUp() { parent::setUp(); - $this->graph = new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738", sprintf(DocumentRepositoryIntegrationTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri'))); + $this->graph = new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738", sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC), config('corpusparole.corpus_doc_id_base_uri'))); $this->httpClient = new Client(['base_uri' => config('corpusparole.sesame_base_url')]); $this->sesameRepository = config('corpusparole.sesame_repository'); @@ -111,7 +34,7 @@ $this->documentRepository = $this->app->make('CorpusParole\Repositories\DocumentRepository'); $uniqueid = uniqid('corpusparole', true); - $repoCreateStmt = sprintf(DocumentRepositoryIntegrationTest::REPO_CREATION_TTL, $this->sesameRepository); + $repoCreateStmt = sprintf(file_get_contents(DocumentRepositoryIntegrationTest::REPO_CREATION_TTL), $this->sesameRepository); $this->httpClient->delete("repositories/$this->sesameRepository", ['http_errors' => false]); $this->httpClient->post('repositories/SYSTEM/statements', [ 'headers' => ['Content-type' => 'application/x-turtle;charset=UTF-8'], @@ -120,20 +43,26 @@ ]); $this->httpClient->put("repositories/$this->sesameRepository/statements", [ 'headers' => ['Content-type' => 'text/turtle;charset=UTF-8'], - 'body' => sprintf(DocumentRepositoryIntegrationTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri')), + 'body' => sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC), config('corpusparole.corpus_doc_id_base_uri')), 'query' => ['context' => "<".config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738>"], ]); + $this->httpClient->put("repositories/$this->sesameRepository/statements", [ + 'headers' => ['Content-type' => 'text/turtle;charset=UTF-8'], + 'body' => sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC_NO_GEO), config('corpusparole.corpus_doc_id_base_uri')), + 'query' => ['context' => "<".config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_739>"], + ]); + } public function tearDown() { - //$this->httpClient->delete("repositories/$this->sesameRepository"); + $this->httpClient->delete("repositories/$this->sesameRepository"); parent::tearDown(); } public function testAll() { $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738'; $docList = $this->documentRepository->all(); - $this->assertCount(1, $docList, "Should have one element"); + $this->assertCount(2, $docList, "Should have one element"); $resDoc = $docList[0]; @@ -147,7 +76,7 @@ public function testGet() { $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738'; - $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(DocumentRepositoryIntegrationTest::TEST_DOC,config('corpusparole.corpus_doc_id_base_uri'))); + $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC),config('corpusparole.corpus_doc_id_base_uri'))); $res = $this->documentRepository->get('crdo-ALA_738'); @@ -161,7 +90,7 @@ public function testGetShort() { $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738'; - $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(DocumentRepositoryIntegrationTest::TEST_DOC,config('corpusparole.corpus_doc_id_base_uri'))); + $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC),config('corpusparole.corpus_doc_id_base_uri'))); $res = $this->documentRepository->get('crdo-ALA_738', true); @@ -172,6 +101,111 @@ $this->assertTrue(EasyRdf\Isomorphic::isomorphic($res->getGraph(),$returnedGraph)); } + public function testNoGeo() { + $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_739'; + $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC_NO_GEO),config('corpusparole.corpus_doc_id_base_uri'))); + + $res = $this->documentRepository->get('crdo-ALA_739'); + + $this->assertNull($res->getGeoInfo(), "Must have no geo info"); + + } + + /** + * @expectedException CorpusParole\Libraries\CorpusParoleException + * @expectedExceptionMessage GetDeltaList called when changes are pending + */ + public function testAddGeoNoCommit() { + + $doc = $this->documentRepository->get('crdo-ALA_739'); + + $geoInfo = $doc->addGeoInfo(); + + $res = $this->documentRepository->save($doc); + } + + + public function testAddGeo() { + + $doc = $this->documentRepository->get('crdo-ALA_739'); + + $geoInfo = $doc->addGeoInfo(); + $geoInfo->commit(); + + $res = $this->documentRepository->save($doc); + + $res = $this->documentRepository->get('crdo-ALA_739'); + + $geoInfo = $res->getGeoInfo(); + + $this->assertNotNull($geoInfo, "Must have Geo info"); + + $notes = $geoInfo->getNotes(); + + $this->assertTrue(is_array($notes)); + $this->assertCount(0, $notes); + + $refLocs = $geoInfo->getRefLocs(); + + $this->assertTrue(is_array($refLocs)); + $this->assertCount(0,$refLocs); + + } + + public function testAddGeoExisting() { + + $doc = $this->documentRepository->get('crdo-ALA_738'); + + $geoInfo = $doc->addGeoInfo(); + $geoInfo->commit(); + + $res = $this->documentRepository->save($doc); + + $res = $this->documentRepository->get('crdo-ALA_738'); + + $geoInfo = $res->getGeoInfo(); + + $this->assertNotNull($geoInfo, "Must have Geo info"); + + $notes = $geoInfo->getNotes(); + + $this->assertTrue(is_array($notes)); + $this->assertCount(3, $notes); + + $refLocs = $geoInfo->getRefLocs(); + + $this->assertTrue(is_array($refLocs)); + $this->assertCount(1,$refLocs); + + } + + public function testGeoSetRefLoc() { + + $doc = $this->documentRepository->get('crdo-ALA_738'); + $geoInfo = $doc->addGeoInfo(); + + $newRefLocs = [ 'http://sws.geonames.org/2643743/' ]; + + $geoInfo->setRefLocs($newRefLocs); + + $geoInfo->commit(); + + $res = $this->documentRepository->save($doc); + + $res = $this->documentRepository->get('crdo-ALA_738'); + + $geoInfo = $res->getGeoInfo(); + + $refLocs = $geoInfo->getRefLocs(); + + $this->assertTrue(is_array($refLocs)); + $this->assertCount(1,$refLocs); + + $this->assertEquals(['http://sws.geonames.org/2643743/'], $refLocs); + + } + + public function testSave() { @@ -204,7 +238,7 @@ $res = $this->documentRepository->getCount(); $this->assertNotNull($res, "Res should not be null"); - $this->assertSame(1, $res, "should heve only one document"); + $this->assertSame(2, $res, "should have 2 documents"); }