4
|
1 |
<?php |
|
2 |
|
|
3 |
use Illuminate\Support\Facades\Facade; |
|
4 |
use Illuminate\Support\Facades\Config; |
|
5 |
|
|
6 |
use CorpusParole\Repositories\DocumentRepository; |
|
7 |
use CorpusParole\Repositories\RdfDocumentRepository; |
|
8 |
use CorpusParole\Models\Document; |
|
9 |
|
|
10 |
use SebastianBergmann\Diff\Differ; |
|
11 |
|
|
12 |
use GuzzleHttp\Client; |
|
13 |
|
|
14 |
class DocumentRepositoryIntegrationTest extends TestCase { |
|
15 |
|
|
16 |
const REPO_CREATION_TTL = <<<EOT |
|
17 |
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. |
|
18 |
@prefix rep: <http://www.openrdf.org/config/repository#>. |
|
19 |
@prefix sr: <http://www.openrdf.org/config/repository/sail#>. |
|
20 |
@prefix sail: <http://www.openrdf.org/config/sail#>. |
|
21 |
@prefix ms: <http://www.openrdf.org/config/sail/memory#>. |
|
22 |
|
|
23 |
[] a rep:Repository ; |
|
24 |
rep:repositoryID "%1\$s" ; |
|
25 |
rdfs:label "%1\$s test repository" ; |
|
26 |
rep:repositoryImpl [ |
|
27 |
rep:repositoryType "openrdf:SailRepository" ; |
|
28 |
sr:sailImpl [ |
|
29 |
sail:sailType "openrdf:MemoryStore" ; |
|
30 |
ms:persist false ; |
|
31 |
ms:syncDelay 0 |
|
32 |
] |
|
33 |
]. |
|
34 |
EOT; |
|
35 |
|
|
36 |
const TEST_DOC = <<<EOT |
|
37 |
<http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608> <http://xmlns.com/foaf/0.1/primaryTopic> <http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> . |
|
38 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Document> . |
|
39 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/description> "Extrait des enqu\u00EAtes dialectologiques en vue de constituer un atlas linguistique de l'Alsace."@fr . |
|
40 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/format> "audio/x-wav"^^<http://purl.org/dc/terms/IMT> . |
|
41 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/type> <http://purl.org/dc/dcmitype/Sound> . |
|
42 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/type> "primary_text"^^<http://www.language-archives.org/OLAC/1.1/linguistic-type> . |
|
43 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/type> "dialogue"^^<http://www.language-archives.org/OLAC/1.1/discourse-type> . |
|
44 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/subject> <http://lexvo.org/id/iso639-3/gsw> . |
|
45 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/subject> "lexicography"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> . |
|
46 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/subject> "phonetics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> . |
|
47 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/subject> "anthropological_linguistics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> . |
|
48 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/language> <http://lexvo.org/id/iso639-3/gsw> . |
|
49 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/contributor> <http://viaf.org/viaf/9122216> . |
|
50 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/contributor> _:genid2d5831d84541df446694586ac2006f96042dgenid1 . |
|
51 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/contributor> _:genid2d5831d84541df446694586ac2006f96042dgenid2 . |
|
52 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/publisher> "Atlas linguistiques, cultures et parlers r\u00E9gionaux de France" . |
|
53 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/rights> "Copyright (c) D\u00E9partement de dialectologie alsacienne et mosellane de l'Universit\u00E9 de Strasbourg" . |
|
54 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/title> "Atlas Linguistique et ethnographique de l'Alsace - Enquetes sur la conscience linguistique - ALA_608"@fr . |
|
55 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/accessRights> "Freely available for non-commercial use" . |
|
56 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-nd/2.5/> . |
|
57 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/isPartOf> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_ALA_CL> . |
|
58 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/isPartOf> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_LANGUESDEFRANCE> . |
|
59 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/extent> "PT02H04M16S" . |
|
60 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/created> "start=1980; end=1989; name=ann\u00E9es 80"^^<http://purl.org/dc/terms/Period> . |
|
61 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/spatial> "France, Alsace"@fr . |
|
62 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/spatial> "FR"^^<http://purl.org/dc/terms/ISO3166> . |
|
63 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/isFormatOf> <http://cocoon.huma-num.fr/data/ala/ALA_608.mp3> . |
|
64 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/isFormatOf> <http://cocoon.huma-num.fr/data/ala/masters/ALA_608.wav> . |
|
65 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/available> "2004-07-03"^^<http://purl.org/dc/terms/W3CDTF> . |
|
66 |
<http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/issued> "2014-11-04T16:25:54+01:00"^^<http://purl.org/dc/terms/W3CDTF> . |
|
67 |
<http://lexvo.org/id/iso639-3/gsw> <http://www.w3.org/2000/01/rdf-schema#label> "Alsacien"@fr . |
|
68 |
<http://viaf.org/viaf/9122216> <http://www.w3.org/2000/01/rdf-schema#label> "Huck, Dominique" . |
|
69 |
<http://viaf.org/viaf/9122216> <http://xmlns.com/foaf/0.1/status> "depositor"^^<http://www.language-archives.org/OLAC/1.1/role> . |
|
70 |
_:genid2d5831d84541df446694586ac2006f96042dgenid1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Agent> . |
|
71 |
_:genid2d5831d84541df446694586ac2006f96042dgenid1 <http://xmlns.com/foaf/0.1/name> "Bothorel-Witz, Arlette" . |
|
72 |
_:genid2d5831d84541df446694586ac2006f96042dgenid1 <http://xmlns.com/foaf/0.1/status> "interviewer"^^<http://www.language-archives.org/OLAC/1.1/role> . |
|
73 |
_:genid2d5831d84541df446694586ac2006f96042dgenid2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Agent> . |
|
74 |
_:genid2d5831d84541df446694586ac2006f96042dgenid2 <http://xmlns.com/foaf/0.1/name> "Huck, Dominique" . |
|
75 |
_:genid2d5831d84541df446694586ac2006f96042dgenid2 <http://xmlns.com/foaf/0.1/status> "interviewer"^^<http://www.language-archives.org/OLAC/1.1/role> . |
|
76 |
EOT; |
|
77 |
|
|
78 |
function __construct(string $name = null) { |
|
79 |
parent::__construct($name); |
|
80 |
$this->graph = new EasyRdf\Graph("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", DocumentRepositoryIntegrationTest::TEST_DOC); |
|
81 |
} |
|
82 |
|
|
83 |
public function setUp() { |
|
84 |
parent::setUp(); |
|
85 |
|
|
86 |
$this->httpClient = new Client(['base_uri' => config('corpusparole.sesame_base_url')]); |
|
87 |
$this->sesameRepository = config('corpusparole.sesame_repository'); |
|
88 |
$this->cocoonDocIdBaseUri = config('corpusparole.cocoon_doc_id_base_uri'); |
|
89 |
|
|
90 |
$this->documentRepository = $this->app->make('CorpusParole\Repositories\DocumentRepository'); |
|
91 |
$uniqueid = uniqid('corpusparole', true); |
|
92 |
$repoCreateStmt = sprintf(DocumentRepositoryIntegrationTest::REPO_CREATION_TTL, $this->sesameRepository); |
|
93 |
$this->httpClient->delete("repositories/$this->sesameRepository", ['http_errors' => false]); |
|
94 |
$this->httpClient->post('repositories/SYSTEM/statements', [ |
|
95 |
'headers' => ['Content-type' => 'application/x-turtle;charset=UTF-8'], |
|
96 |
'query' => ['context' => "_:$uniqueid"], |
|
97 |
'body' => $repoCreateStmt, |
|
98 |
]); |
|
99 |
$this->httpClient->put("repositories/$this->sesameRepository/statements", [ |
|
100 |
'headers' => ['Content-type' => 'text/turtle;charset=UTF-8'], |
|
101 |
'body' => DocumentRepositoryIntegrationTest::TEST_DOC, |
|
102 |
'query' => ['context' => '<http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608>'], |
|
103 |
]); |
|
104 |
} |
|
105 |
|
|
106 |
public function tearDown() { |
|
107 |
$this->httpClient->delete("repositories/$this->sesameRepository"); |
|
108 |
parent::tearDown(); |
|
109 |
} |
|
110 |
|
|
111 |
public function testAll() { |
|
112 |
$expectedId = $this->cocoonDocIdBaseUri.'crdo-ALA_608'; |
|
113 |
$docList = $this->documentRepository->all(); |
|
114 |
$this->assertCount(1, $docList, "Should have one element"); |
|
115 |
|
|
116 |
$resDoc = $docList[0]; |
|
117 |
|
|
118 |
$this->assertInstanceOf(Document::class, $resDoc, "Res doc must be a Document"); |
|
119 |
$this->assertEquals('crdo-ALA_608', $resDoc->getId(), "id must be crdo..."); |
|
120 |
$this->assertEquals($expectedId, $resDoc->getUri(), 'url must be ...'); |
|
121 |
$this->assertNull($resDoc->getGraph(), 'Graph must be null'); |
|
122 |
|
|
123 |
} |
|
124 |
|
|
125 |
public function testGet() { |
|
126 |
|
|
127 |
$expectedId = $this->cocoonDocIdBaseUri.'crdo-ALA_608'; |
|
128 |
$returnedGraph = new EasyRdf\Graph($expectedId, DocumentRepositoryIntegrationTest::TEST_DOC); |
|
129 |
|
|
130 |
$res = $this->documentRepository->get('crdo-ALA_608'); |
|
131 |
|
|
132 |
$this->assertInstanceOf(Document::class, $res, "Result must be of type Document"); |
|
133 |
$this->assertEquals('crdo-ALA_608', $res->getId(), 'id should be crdo-ALA_608' ); |
|
134 |
$this->assertNotNull($res->getGraph(), "Graph shoul not be null"); |
|
135 |
$this->assertTrue(EasyRdf\Isomorphic::isomorphic($res->getGraph(),$returnedGraph)); |
|
136 |
} |
|
137 |
|
|
138 |
public function testSave() { |
|
139 |
|
|
140 |
$doc = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", $this->graph); |
|
141 |
$doc->updateDiscourseTypes(['oratory','drama','narrative']); |
|
142 |
|
|
143 |
$res = $this->documentRepository->save($doc); |
|
144 |
|
|
145 |
$this->assertTrue($res, 'Has started a transaction'); |
|
146 |
|
|
147 |
$res = $this->documentRepository->get('crdo-ALA_608'); |
|
148 |
|
|
149 |
$discoursesTypes = $res->getDiscourseTypes(); |
|
150 |
|
|
151 |
$this->assertCount(3, $discoursesTypes, "types array must be of size 1"); |
|
152 |
|
|
153 |
$this->assertContainsOnlyInstancesOf("EasyRdf\Literal", $discoursesTypes, "Result contains only literals"); |
|
154 |
|
|
155 |
$newDiscoursesTypes = []; |
|
156 |
foreach($discoursesTypes as $dt) { |
|
157 |
array_push($newDiscoursesTypes, $dt->getValue()); |
|
158 |
$this->assertContains($dt->getValue(),['oratory','drama','narrative'],'Value in [oratory,drama,narrative]'); |
|
159 |
$this->assertEquals("http://www.language-archives.org/OLAC/1.1/discourse-type", $dt->getDatatypeUri(), "discourse type url"); |
|
160 |
} |
|
161 |
sort($newDiscoursesTypes); |
|
162 |
$this->assertEquals(['drama', 'narrative', 'oratory'], $newDiscoursesTypes, "array type must the same"); |
|
163 |
} |
|
164 |
|
|
165 |
public function testCount() { |
|
166 |
$res = $this->documentRepository->getCount(); |
|
167 |
|
|
168 |
$this->assertNotNull($res, "Res should not be null"); |
|
169 |
$this->assertSame(1, $res, "should heve only one document"); |
|
170 |
} |
|
171 |
|
|
172 |
|
|
173 |
} |