13 |
13 |
14 use GuzzleHttp\Client; |
14 use GuzzleHttp\Client; |
15 |
15 |
16 class DocumentRepositoryIntegrationTest extends TestCase { |
16 class DocumentRepositoryIntegrationTest extends TestCase { |
17 |
17 |
18 const REPO_CREATION_TTL = <<<EOT |
18 const REPO_CREATION_TTL = __DIR__.'/files/DocumentRepositoryIntegrationTest/repo_creation.ttl'; |
19 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. |
19 |
20 @prefix rep: <http://www.openrdf.org/config/repository#>. |
20 const TEST_DOC = __DIR__.'/files/DocumentRepositoryIntegrationTest/test_doc.ttl'; |
21 @prefix sr: <http://www.openrdf.org/config/repository/sail#>. |
21 const TEST_DOC_NO_GEO = __DIR__.'/files/DocumentRepositoryIntegrationTest/test_doc_no_geo.ttl'; |
22 @prefix sail: <http://www.openrdf.org/config/sail#>. |
|
23 @prefix ms: <http://www.openrdf.org/config/sail/memory#>. |
|
24 |
|
25 [] a rep:Repository ; |
|
26 rep:repositoryID "%1\$s" ; |
|
27 rdfs:label "%1\$s test repository" ; |
|
28 rep:repositoryImpl [ |
|
29 rep:repositoryType "openrdf:SailRepository" ; |
|
30 sr:sailImpl [ |
|
31 sail:sailType "openrdf:MemoryStore" ; |
|
32 ms:persist false ; |
|
33 ms:syncDelay 0 |
|
34 ] |
|
35 ]. |
|
36 EOT; |
|
37 |
|
38 const TEST_DOC = <<<EOT |
|
39 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . |
|
40 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . |
|
41 @prefix sesame: <http://www.openrdf.org/schema/sesame#> . |
|
42 @prefix owl: <http://www.w3.org/2002/07/owl#> . |
|
43 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . |
|
44 @prefix fn: <http://www.w3.org/2005/xpath-functions#> . |
|
45 |
|
46 _:genid-2267740936ad4d04a567e6787732f0dd-genid1 a <http://www.europeana.eu/schemas/edm/Place> ; |
|
47 owl:sameAs <http://sws.geonames.org/3038033/> ; |
|
48 <http://www.w3.org/2004/02/skos/core#note> "northlimit=47.431892250000033; southlimit=49.053971250000046;westlimit=6.846186050000028; eastlimit=8.232571550000074;"^^<http://purl.org/dc/terms/Box> , "FR"^^<http://purl.org/dc/terms/ISO3166> , "France, Alsace"@fr . |
|
49 |
|
50 <%1\$scrdo-ALA_738> a <http://www.openarchives.org/ore/terms/Aggregation> ; |
|
51 <http://www.europeana.eu/schemas/edm/aggregatedCHO> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_738> ; |
|
52 <http://www.europeana.eu/schemas/edm/dataProvider> "Atlas linguistiques, cultures et parlers régionaux de France" ; |
|
53 <http://www.europeana.eu/schemas/edm/hasView> <http://cocoon.huma-num.fr/data/ala/ALA_738.mp3> , <http://cocoon.huma-num.fr/data/ala/ALA_738_22km.wav> ; |
|
54 <http://www.europeana.eu/schemas/edm/isShownAt> <http://corpusdelaparole.huma-num.fr/corpus-app#/detail/crdo-ALA_738> ; |
|
55 <http://www.europeana.eu/schemas/edm/isShownBy> <http://cocoon.huma-num.fr/data/ala/masters/ALA_738.wav> ; |
|
56 <http://www.europeana.eu/schemas/edm/provider> "Corpus de la Parole"@fr ; |
|
57 <http://www.europeana.eu/schemas/edm/rights> <http://creativecommons.org/licenses/by-nc-nd/4.0/> . |
|
58 |
|
59 <http://cocoon.huma-num.fr/data/ala/ALA_738.mp3> a <http://www.europeana.eu/schemas/edm/WebResource> ; |
|
60 <http://purl.org/dc/elements/1.1/format> "audio/mpeg"^^<http://purl.org/dc/terms/IMT> ; |
|
61 <http://purl.org/dc/terms/created> "1996"^^<http://purl.org/dc/terms/Period> ; |
|
62 <http://purl.org/dc/terms/extent> "PT01H11M29S" ; |
|
63 <http://purl.org/dc/terms/issued> "2014-11-10T14:27:08+01:00"^^<http://purl.org/dc/terms/W3CDTF> ; |
|
64 <http://www.europeana.eu/schemas/edm/isDerivativeOf> <http://cocoon.huma-num.fr/data/ala/masters/ALA_738.wav> . |
|
65 |
|
66 <http://cocoon.huma-num.fr/data/ala/masters/ALA_738.wav> a <http://www.europeana.eu/schemas/edm/WebResource> ; |
|
67 <http://purl.org/dc/elements/1.1/format> "audio/x-wav"^^<http://purl.org/dc/terms/IMT> ; |
|
68 <http://purl.org/dc/terms/created> "1996"^^<http://purl.org/dc/terms/Period> ; |
|
69 <http://purl.org/dc/terms/extent> "PT01H11M29S" ; |
|
70 <http://purl.org/dc/terms/issued> "2014-11-10T14:27:08+01:00"^^<http://purl.org/dc/terms/W3CDTF> . |
|
71 |
|
72 <http://cocoon.huma-num.fr/data/ala/ALA_738_22km.wav> a <http://www.europeana.eu/schemas/edm/WebResource> ; |
|
73 <http://purl.org/dc/elements/1.1/format> "audio/x-wav"^^<http://purl.org/dc/terms/IMT> ; |
|
74 <http://purl.org/dc/terms/created> "1996"^^<http://purl.org/dc/terms/Period> ; |
|
75 <http://purl.org/dc/terms/extent> "PT01H11M29S" ; |
|
76 <http://purl.org/dc/terms/issued> "2014-11-10T14:27:08+01:00"^^<http://purl.org/dc/terms/W3CDTF> ; |
|
77 <http://www.europeana.eu/schemas/edm/isDerivativeOf> <http://cocoon.huma-num.fr/data/ala/masters/ALA_738.wav> . |
|
78 |
|
79 <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_738> a <http://www.europeana.eu/schemas/edm/ProvidedCHO> ; |
|
80 <http://purl.org/dc/terms/created> "1996"^^<http://purl.org/dc/terms/Period> ; |
|
81 <http://purl.org/dc/terms/extent> "PT01H11M29S" ; |
|
82 <http://purl.org/dc/terms/issued> "2014-11-10T14:27:08+01:00"^^<http://purl.org/dc/terms/W3CDTF> ; |
|
83 <http://purl.org/dc/elements/1.1/contributor> <http://viaf.org/viaf/61542329> , <http://viaf.org/viaf/9122216> ; |
|
84 <http://purl.org/dc/elements/1.1/description> "Extrait des enquêtes dialectologiques en vue de constituer un atlas linguistique de l'Alsace."@fr ; |
|
85 <http://purl.org/dc/elements/1.1/language> <http://lexvo.org/id/iso639-3/gsw> ; |
|
86 <http://purl.org/dc/elements/1.1/publisher> "Atlas linguistiques, cultures et parlers régionaux de France" ; |
|
87 <http://purl.org/dc/elements/1.1/rights> "Copyright (c) Département de dialectologie alsacienne et mosellane de l'Université de Strasbourg" ; |
|
88 <http://purl.org/dc/elements/1.1/subject> <http://lexvo.org/id/iso639-3/gsw> , <http://ark.bnf.fr/ark:/12148/cb11931472p> , <http://ark.bnf.fr/ark:/12148/cb11931564b> , <http://ark.bnf.fr/ark:/12148/cb11932194d> , <http://ark.bnf.fr/ark:/12148/cb11933029x> , <http://ark.bnf.fr/ark:/12148/cb11933281k> , <http://ark.bnf.fr/ark:/12148/cb11934740m> , <http://ark.bnf.fr/ark:/12148/cb11935375d> , <http://ark.bnf.fr/ark:/12148/cb11935986q> , <http://ark.bnf.fr/ark:/12148/cb11936549n> , <http://ark.bnf.fr/ark:/12148/cb11937931x> , <http://ark.bnf.fr/ark:/12148/cb119392962> , <http://ark.bnf.fr/ark:/12148/cb119458243> , <http://ark.bnf.fr/ark:/12148/cb11946662b> , <http://ark.bnf.fr/ark:/12148/cb11947332t> , <http://ark.bnf.fr/ark:/12148/cb119481497> , <http://ark.bnf.fr/ark:/12148/cb119591726> , <http://ark.bnf.fr/ark:/12148/cb119756721> , <http://ark.bnf.fr/ark:/12148/cb119757609> , <http://ark.bnf.fr/ark:/12148/cb11975806s> , <http://ark.bnf.fr/ark:/12148/cb119759527> , <http://ark.bnf.fr/ark:/12148/cb12032030g> , <http://ark.bnf.fr/ark:/12148/cb12042429k> , <http://ark.bnf.fr/ark:/12148/cb12099148r> , <http://ark.bnf.fr/ark:/12148/cb12148936v> , <http://ark.bnf.fr/ark:/12148/cb12289036m> , <http://ark.bnf.fr/ark:/12148/cb13318335q> , <http://ark.bnf.fr/ark:/12148/cb133183540> , <http://ark.bnf.fr/ark:/12148/cb13318415c> , <http://ark.bnf.fr/ark:/12148/cb13318491g> , "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> ; |
|
89 <http://purl.org/dc/elements/1.1/title> "Atlas Linguistique et ethnographique de l'Alsace - Enquetes sur la conscience linguistique - ALA_738"@fr ; |
|
90 <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> , "dialogue"^^<http://www.language-archives.org/OLAC/1.1/discourse-type> , "primary_text"^^<http://www.language-archives.org/OLAC/1.1/linguistic-type> ; |
|
91 <http://purl.org/dc/terms/accessRights> "Freely available for non-commercial use" ; |
|
92 <http://purl.org/dc/terms/available> "2004-07-03"^^<http://purl.org/dc/terms/W3CDTF> ; |
|
93 <http://purl.org/dc/terms/isPartOf> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_ALA_CL> , <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_LANGUESDEFRANCE> ; |
|
94 <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-nd/2.5/> ; |
|
95 <http://purl.org/dc/terms/spatial> _:genid-2267740936ad4d04a567e6787732f0dd-genid1 ; |
|
96 <http://www.language-archives.org/OLAC/1.1/depositor> <http://viaf.org/viaf/9122216> ; |
|
97 <http://www.language-archives.org/OLAC/1.1/interviewer> <http://viaf.org/viaf/61542329> , <http://viaf.org/viaf/9122216> . |
|
98 EOT; |
|
99 |
22 |
100 function __construct(string $name = null) { |
23 function __construct(string $name = null) { |
101 parent::__construct($name); |
24 parent::__construct($name); |
102 } |
25 } |
103 |
26 |
104 public function setUp() { |
27 public function setUp() { |
105 parent::setUp(); |
28 parent::setUp(); |
106 $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'))); |
29 $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'))); |
107 |
30 |
108 $this->httpClient = new Client(['base_uri' => config('corpusparole.sesame_base_url')]); |
31 $this->httpClient = new Client(['base_uri' => config('corpusparole.sesame_base_url')]); |
109 $this->sesameRepository = config('corpusparole.sesame_repository'); |
32 $this->sesameRepository = config('corpusparole.sesame_repository'); |
110 $this->corpusDocIdBaseUri = config('corpusparole.corpus_doc_id_base_uri'); |
33 $this->corpusDocIdBaseUri = config('corpusparole.corpus_doc_id_base_uri'); |
111 |
34 |
112 $this->documentRepository = $this->app->make('CorpusParole\Repositories\DocumentRepository'); |
35 $this->documentRepository = $this->app->make('CorpusParole\Repositories\DocumentRepository'); |
113 $uniqueid = uniqid('corpusparole', true); |
36 $uniqueid = uniqid('corpusparole', true); |
114 $repoCreateStmt = sprintf(DocumentRepositoryIntegrationTest::REPO_CREATION_TTL, $this->sesameRepository); |
37 $repoCreateStmt = sprintf(file_get_contents(DocumentRepositoryIntegrationTest::REPO_CREATION_TTL), $this->sesameRepository); |
115 $this->httpClient->delete("repositories/$this->sesameRepository", ['http_errors' => false]); |
38 $this->httpClient->delete("repositories/$this->sesameRepository", ['http_errors' => false]); |
116 $this->httpClient->post('repositories/SYSTEM/statements', [ |
39 $this->httpClient->post('repositories/SYSTEM/statements', [ |
117 'headers' => ['Content-type' => 'application/x-turtle;charset=UTF-8'], |
40 'headers' => ['Content-type' => 'application/x-turtle;charset=UTF-8'], |
118 'query' => ['context' => "_:$uniqueid"], |
41 'query' => ['context' => "_:$uniqueid"], |
119 'body' => $repoCreateStmt, |
42 'body' => $repoCreateStmt, |
120 ]); |
43 ]); |
121 $this->httpClient->put("repositories/$this->sesameRepository/statements", [ |
44 $this->httpClient->put("repositories/$this->sesameRepository/statements", [ |
122 'headers' => ['Content-type' => 'text/turtle;charset=UTF-8'], |
45 'headers' => ['Content-type' => 'text/turtle;charset=UTF-8'], |
123 'body' => sprintf(DocumentRepositoryIntegrationTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri')), |
46 'body' => sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC), config('corpusparole.corpus_doc_id_base_uri')), |
124 'query' => ['context' => "<".config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738>"], |
47 'query' => ['context' => "<".config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738>"], |
125 ]); |
48 ]); |
|
49 $this->httpClient->put("repositories/$this->sesameRepository/statements", [ |
|
50 'headers' => ['Content-type' => 'text/turtle;charset=UTF-8'], |
|
51 'body' => sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC_NO_GEO), config('corpusparole.corpus_doc_id_base_uri')), |
|
52 'query' => ['context' => "<".config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_739>"], |
|
53 ]); |
|
54 |
126 } |
55 } |
127 |
56 |
128 public function tearDown() { |
57 public function tearDown() { |
129 //$this->httpClient->delete("repositories/$this->sesameRepository"); |
58 $this->httpClient->delete("repositories/$this->sesameRepository"); |
130 parent::tearDown(); |
59 parent::tearDown(); |
131 } |
60 } |
132 |
61 |
133 public function testAll() { |
62 public function testAll() { |
134 $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738'; |
63 $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738'; |
135 $docList = $this->documentRepository->all(); |
64 $docList = $this->documentRepository->all(); |
136 $this->assertCount(1, $docList, "Should have one element"); |
65 $this->assertCount(2, $docList, "Should have one element"); |
137 |
66 |
138 $resDoc = $docList[0]; |
67 $resDoc = $docList[0]; |
139 |
68 |
140 $this->assertInstanceOf(DocumentResult::class, $resDoc, "Res doc must be a Document"); |
69 $this->assertInstanceOf(DocumentResult::class, $resDoc, "Res doc must be a Document"); |
141 $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-ALA_738', $resDoc->getId(), "id must be crdo..."); |
70 $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-ALA_738', $resDoc->getId(), "id must be crdo..."); |
159 } |
88 } |
160 |
89 |
161 public function testGetShort() { |
90 public function testGetShort() { |
162 |
91 |
163 $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738'; |
92 $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738'; |
164 $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(DocumentRepositoryIntegrationTest::TEST_DOC,config('corpusparole.corpus_doc_id_base_uri'))); |
93 $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC),config('corpusparole.corpus_doc_id_base_uri'))); |
165 |
94 |
166 $res = $this->documentRepository->get('crdo-ALA_738', true); |
95 $res = $this->documentRepository->get('crdo-ALA_738', true); |
167 |
96 |
168 $this->assertInstanceOf(DocumentResult::class, $res, "Result must be of type DocumentResult"); |
97 $this->assertInstanceOf(DocumentResult::class, $res, "Result must be of type DocumentResult"); |
169 $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-ALA_738', $res->getId(), 'id should be crdo-ALA_738' ); |
98 $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-ALA_738', $res->getId(), 'id should be crdo-ALA_738' ); |
170 $this->assertNotNull($res->getGraph(), "Graph shoul not be null"); |
99 $this->assertNotNull($res->getGraph(), "Graph shoul not be null"); |
171 $this->assertEquals(config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738",$res->getGraph()->getUri(), "uri of graph must be ".config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738"); |
100 $this->assertEquals(config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738",$res->getGraph()->getUri(), "uri of graph must be ".config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738"); |
172 $this->assertTrue(EasyRdf\Isomorphic::isomorphic($res->getGraph(),$returnedGraph)); |
101 $this->assertTrue(EasyRdf\Isomorphic::isomorphic($res->getGraph(),$returnedGraph)); |
173 } |
102 } |
|
103 |
|
104 public function testNoGeo() { |
|
105 $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_739'; |
|
106 $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC_NO_GEO),config('corpusparole.corpus_doc_id_base_uri'))); |
|
107 |
|
108 $res = $this->documentRepository->get('crdo-ALA_739'); |
|
109 |
|
110 $this->assertNull($res->getGeoInfo(), "Must have no geo info"); |
|
111 |
|
112 } |
|
113 |
|
114 /** |
|
115 * @expectedException CorpusParole\Libraries\CorpusParoleException |
|
116 * @expectedExceptionMessage GetDeltaList called when changes are pending |
|
117 */ |
|
118 public function testAddGeoNoCommit() { |
|
119 |
|
120 $doc = $this->documentRepository->get('crdo-ALA_739'); |
|
121 |
|
122 $geoInfo = $doc->addGeoInfo(); |
|
123 |
|
124 $res = $this->documentRepository->save($doc); |
|
125 } |
|
126 |
|
127 |
|
128 public function testAddGeo() { |
|
129 |
|
130 $doc = $this->documentRepository->get('crdo-ALA_739'); |
|
131 |
|
132 $geoInfo = $doc->addGeoInfo(); |
|
133 $geoInfo->commit(); |
|
134 |
|
135 $res = $this->documentRepository->save($doc); |
|
136 |
|
137 $res = $this->documentRepository->get('crdo-ALA_739'); |
|
138 |
|
139 $geoInfo = $res->getGeoInfo(); |
|
140 |
|
141 $this->assertNotNull($geoInfo, "Must have Geo info"); |
|
142 |
|
143 $notes = $geoInfo->getNotes(); |
|
144 |
|
145 $this->assertTrue(is_array($notes)); |
|
146 $this->assertCount(0, $notes); |
|
147 |
|
148 $refLocs = $geoInfo->getRefLocs(); |
|
149 |
|
150 $this->assertTrue(is_array($refLocs)); |
|
151 $this->assertCount(0,$refLocs); |
|
152 |
|
153 } |
|
154 |
|
155 public function testAddGeoExisting() { |
|
156 |
|
157 $doc = $this->documentRepository->get('crdo-ALA_738'); |
|
158 |
|
159 $geoInfo = $doc->addGeoInfo(); |
|
160 $geoInfo->commit(); |
|
161 |
|
162 $res = $this->documentRepository->save($doc); |
|
163 |
|
164 $res = $this->documentRepository->get('crdo-ALA_738'); |
|
165 |
|
166 $geoInfo = $res->getGeoInfo(); |
|
167 |
|
168 $this->assertNotNull($geoInfo, "Must have Geo info"); |
|
169 |
|
170 $notes = $geoInfo->getNotes(); |
|
171 |
|
172 $this->assertTrue(is_array($notes)); |
|
173 $this->assertCount(3, $notes); |
|
174 |
|
175 $refLocs = $geoInfo->getRefLocs(); |
|
176 |
|
177 $this->assertTrue(is_array($refLocs)); |
|
178 $this->assertCount(1,$refLocs); |
|
179 |
|
180 } |
|
181 |
|
182 public function testGeoSetRefLoc() { |
|
183 |
|
184 $doc = $this->documentRepository->get('crdo-ALA_738'); |
|
185 $geoInfo = $doc->addGeoInfo(); |
|
186 |
|
187 $newRefLocs = [ 'http://sws.geonames.org/2643743/' ]; |
|
188 |
|
189 $geoInfo->setRefLocs($newRefLocs); |
|
190 |
|
191 $geoInfo->commit(); |
|
192 |
|
193 $res = $this->documentRepository->save($doc); |
|
194 |
|
195 $res = $this->documentRepository->get('crdo-ALA_738'); |
|
196 |
|
197 $geoInfo = $res->getGeoInfo(); |
|
198 |
|
199 $refLocs = $geoInfo->getRefLocs(); |
|
200 |
|
201 $this->assertTrue(is_array($refLocs)); |
|
202 $this->assertCount(1,$refLocs); |
|
203 |
|
204 $this->assertEquals(['http://sws.geonames.org/2643743/'], $refLocs); |
|
205 |
|
206 } |
|
207 |
174 |
208 |
175 |
209 |
176 public function testSave() { |
210 public function testSave() { |
177 |
211 |
178 $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738", $this->graph); |
212 $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738", $this->graph); |