|
1 <?php |
|
2 |
|
3 use CorpusParole\Models\Document; |
|
4 |
|
5 /** |
|
6 * |
|
7 */ |
|
8 class DocumentTest extends TestCase { |
|
9 |
|
10 const TEST_DOC = <<<EOT |
|
11 <http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> . |
|
12 <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> . |
|
13 <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 . |
|
14 <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> . |
|
15 <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> . |
|
16 <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> . |
|
17 <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> . |
|
18 <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> . |
|
19 <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> . |
|
20 <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> . |
|
21 <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> . |
|
22 <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> . |
|
23 <http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/contributor> <http://viaf.org/viaf/9122216> . |
|
24 <http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/contributor> _:genid2d6c3879d9d2484bd98bb0bcb9dd0364fc2dgenid1 . |
|
25 <http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/elements/1.1/contributor> _:genid2d6c3879d9d2484bd98bb0bcb9dd0364fc2dgenid2 . |
|
26 <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" . |
|
27 <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" . |
|
28 <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 . |
|
29 <http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/accessRights> "Freely available for non-commercial use" . |
|
30 <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/> . |
|
31 <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> . |
|
32 <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> . |
|
33 <http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/extent> "PT02H04M16S" . |
|
34 <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> . |
|
35 <http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/spatial> "France, Alsace"@fr . |
|
36 <http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://purl.org/dc/terms/spatial> "FR"^^<http://purl.org/dc/terms/ISO3166> . |
|
37 <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> . |
|
38 <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> . |
|
39 <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> . |
|
40 <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> . |
|
41 <http://cocoon.huma-num.fr/data/ala/ALA_608_22km.wav> <http://www.openrdf.org/schema/sesame#directType> <http://xmlns.com/foaf/0.1/Document> . |
|
42 _:genid2d6c3879d9d2484bd98bb0bcb9dd0364fc2dgenid1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> . |
|
43 _:genid2d6c3879d9d2484bd98bb0bcb9dd0364fc2dgenid1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Agent> . |
|
44 _:genid2d6c3879d9d2484bd98bb0bcb9dd0364fc2dgenid1 <http://xmlns.com/foaf/0.1/name> "Bothorel-Witz, Arlette" . |
|
45 _:genid2d6c3879d9d2484bd98bb0bcb9dd0364fc2dgenid1 <http://xmlns.com/foaf/0.1/status> "interviewer"^^<http://www.language-archives.org/OLAC/1.1/role> . |
|
46 _:genid2d6c3879d9d2484bd98bb0bcb9dd0364fc2dgenid1 <http://www.openrdf.org/schema/sesame#directType> <http://xmlns.com/foaf/0.1/Agent> . |
|
47 _:genid2d6c3879d9d2484bd98bb0bcb9dd0364fc2dgenid2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> . |
|
48 _:genid2d6c3879d9d2484bd98bb0bcb9dd0364fc2dgenid2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Agent> . |
|
49 _:genid2d6c3879d9d2484bd98bb0bcb9dd0364fc2dgenid2 <http://xmlns.com/foaf/0.1/name> "Huck, Dominique" . |
|
50 _:genid2d6c3879d9d2484bd98bb0bcb9dd0364fc2dgenid2 <http://xmlns.com/foaf/0.1/status> "interviewer"^^<http://www.language-archives.org/OLAC/1.1/role> . |
|
51 _:genid2d6c3879d9d2484bd98bb0bcb9dd0364fc2dgenid2 <http://www.openrdf.org/schema/sesame#directType> <http://xmlns.com/foaf/0.1/Agent> . |
|
52 <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> . |
|
53 EOT; |
|
54 |
|
55 private $testGraph; |
|
56 |
|
57 public function setUp() { |
|
58 |
|
59 parent::setup(); |
|
60 $this->graph = new \EasyRdf_Graph("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", DocumentTest::TEST_DOC); |
|
61 |
|
62 } |
|
63 |
|
64 public function testConstructor() { |
|
65 $this->assertNotNull($this->graph, 'Graph shoud not be null'); |
|
66 |
|
67 $doc = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", $this->graph); |
|
68 |
|
69 $this->assertEquals('crdo-ALA_608',$doc->getId(),'Must have the correct id'); |
|
70 } |
|
71 |
|
72 public function testTitle() { |
|
73 $this->assertNotNull($this->graph, 'Graph shoud not be null'); |
|
74 |
|
75 $doc = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", $this->graph); |
|
76 |
|
77 $this->assertEquals("Atlas Linguistique et ethnographique de l'Alsace - Enquetes sur la conscience linguistique - ALA_608",$doc->getTitle(),'Must have correct title'); |
|
78 $this->assertInstanceOf(\EasyRdf_Literal::class, $doc->getTitle(), "Title must be a literal"); |
|
79 $this->assertEquals('fr', $doc->getTitle()->getLang(), "Language title must be fr"); |
|
80 } |
|
81 |
|
82 public function testPublisher() { |
|
83 |
|
84 $doc = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", $this->graph); |
|
85 |
|
86 $this->assertCount(1, $doc->getPublishers(), 'Publisher is an array of size 1'); |
|
87 $this->assertEquals(new \EasyRdf_Literal("Atlas linguistiques, cultures et parlers régionaux de France",null,null), $doc->getPublishers()[0], "Must contains correct publisher"); |
|
88 |
|
89 } |
|
90 |
|
91 public function testMediaArray() { |
|
92 $doc = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", $this->graph); |
|
93 |
|
94 $this->assertCount(3, $doc->getMediaArray(), "Media array must be of size 3"); |
|
95 foreach($doc->getMediaArray() as $media) { |
|
96 $this->assertCount(2, $media, "media is a 2 element array"); |
|
97 $this->assertArrayHasKey('format', $media, "media has 'format key'"); |
|
98 $this->assertArrayHasKey('url', $media, "media has url"); |
|
99 } |
|
100 } |
|
101 |
|
102 public function testGetTypes() { |
|
103 $doc = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", $this->graph); |
|
104 |
|
105 $this->assertCount(3, $doc->getTypes(), "types array must be of size 3"); |
|
106 |
|
107 foreach($doc->getTypes() as $type) { |
|
108 $this->assertThat( |
|
109 $type, |
|
110 $this->logicalXor( |
|
111 $this->isInstanceOf(\EasyRdf_Literal::class), |
|
112 $this->isInstanceOf(\EasyRdf_Resource::class) |
|
113 ) |
|
114 ); |
|
115 } |
|
116 } |
|
117 |
|
118 public function testGetOtherTypes() { |
|
119 $doc = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", $this->graph); |
|
120 |
|
121 $this->assertCount(2, $doc->getOtherTypes(), "types array must be of size 3"); |
|
122 |
|
123 foreach($doc->getTypes() as $type) { |
|
124 $this->assertThat( |
|
125 $type, |
|
126 $this->logicalXor( |
|
127 $this->isInstanceOf(\EasyRdf_Literal::class), |
|
128 $this->isInstanceOf(\EasyRdf_Resource::class) |
|
129 ) |
|
130 ); |
|
131 } |
|
132 } |
|
133 |
|
134 public function testGetDiscourseTypes() { |
|
135 $doc = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", $this->graph); |
|
136 |
|
137 $this->assertCount(1, $doc->getDiscourseTypes(), "types array must be of size 1"); |
|
138 |
|
139 $this->assertContainsOnlyInstancesOf("EasyRdf_Literal", $doc->getDiscourseTypes(), "Result contains only literals"); |
|
140 $type = $doc->getDiscourseTypes()[0]; |
|
141 $this->assertEquals("dialogue", $type, "discourse type is dialogue"); |
|
142 $this->assertEquals("http://www.language-archives.org/OLAC/1.1/discourse-type", $type->getDatatypeUri(), "discourse type url"); |
|
143 } |
|
144 |
|
145 public function testCloneDocument() { |
|
146 $doc = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", $this->graph); |
|
147 |
|
148 $doc2 = clone $doc; |
|
149 |
|
150 $this->assertNotSame($doc, $doc2, "documents must not be the same"); |
|
151 $this->assertNotSame($doc->getGraph(), $doc2->getGraph(), "documents must not be the same"); |
|
152 |
|
153 $this->assertTrue(\EasyRdf_Isomorphic::isomorphic($doc->getGraph(), $doc2->getGraph()),"graph must be isomorphic"); |
|
154 } |
|
155 |
|
156 public function testIsIsomorphic() { |
|
157 $doc1 = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", $this->graph); |
|
158 $doc2 = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", new \EasyRdf_Graph("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", DocumentTest::TEST_DOC)); |
|
159 |
|
160 $this->assertTrue($doc1->isIsomorphic($doc2),"document must be isomorphic"); |
|
161 |
|
162 $doc2->addLiteral('dc11:type', new \EasyRdf_Literal("oratory", null, Config::get('OLAC_DISCOURSE_TYPE')['uri'])); |
|
163 |
|
164 $this->assertFalse($doc1->isIsomorphic($doc2),"document must not be isomorphic"); |
|
165 } |
|
166 |
|
167 public function testUpdateDiscourseTypes() { |
|
168 |
|
169 $newDiscourseTypes = ['oratory','dialogue','narrative']; |
|
170 |
|
171 $doc = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", $this->graph); |
|
172 $this->assertCount(1, $doc->getDiscourseTypes(), "types array must be of size 1"); |
|
173 |
|
174 $doc->updateDiscourseTypes($newDiscourseTypes); |
|
175 |
|
176 $this->assertCount(3, $doc->getDiscourseTypes(), "types array must be of size 3"); |
|
177 |
|
178 $discourseTypes = $doc->getDiscourseTypes(); |
|
179 foreach($newDiscourseTypes as $dt) { |
|
180 $this->assertContains($dt, $discourseTypes, "all discourse types must be in result list"); |
|
181 } |
|
182 |
|
183 } |
|
184 |
|
185 public function testUpdateDiscourseTypesIsomorphic() { |
|
186 |
|
187 $newDiscourseTypes = ['oratory','dialogue','narrative']; |
|
188 |
|
189 $doc = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", $this->graph); |
|
190 $doc->updateDiscourseTypes($newDiscourseTypes); |
|
191 |
|
192 $doc2 = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", new \EasyRdf_Graph("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", DocumentTest::TEST_DOC)); |
|
193 |
|
194 $this->assertFalse($doc->isIsomorphic($doc2),"document must not be isomorphic after adding discourse type"); |
|
195 } |
|
196 } |