Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / rdf / tests / src / Kernel / Migrate / d7 / MigrateRdfMappingTest.php
1 <?php
2
3 namespace Drupal\Tests\rdf\Kernel\Migrate\d7;
4
5 use Drupal\rdf\RdfMappingInterface;
6 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
7
8 /**
9  * Tests RDF mappings migration from Drupal 7 to 8.
10  *
11  * @group rdf
12  */
13 class MigrateRdfMappingTest extends MigrateDrupal7TestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = [
19     'menu_ui',
20     'node',
21     'rdf',
22     'taxonomy',
23     'text',
24   ];
25
26   /**
27    * {@inheritdoc}
28    */
29   protected function setUp() {
30     parent::setUp();
31
32     $this->installConfig(static::$modules);
33
34     $this->executeMigrations([
35       'd7_node_type',
36       'd7_taxonomy_vocabulary',
37       'd7_rdf_mapping',
38     ]);
39   }
40
41   /**
42    * Asserts various aspects of a RDF mapping.
43    *
44    * @param string $entity_type
45    *   The entity type.
46    * @param string $bundle
47    *   The bundle.
48    * @param string[] $types
49    *   The expected RDF types.
50    * @param array[] $field_mappings
51    *   The expected RDF field mappings.
52    */
53   protected function assertRdfMapping($entity_type, $bundle, $types, $field_mappings) {
54     $rdf_mapping = rdf_get_mapping($entity_type, $bundle);
55     $this->assertInstanceOf(RdfMappingInterface::class, $rdf_mapping);
56     $this->assertSame($types, $rdf_mapping->getBundleMapping());
57     foreach ($field_mappings as $field => $mapping) {
58       $this->assertSame($mapping, $rdf_mapping->getFieldMapping($field));
59     }
60   }
61
62   /**
63    * Tests RDF mappings migration from Drupal 7 to 8.
64    */
65   public function testRdfMappingMigration() {
66     $this->assertRdfMapping(
67       'node',
68       'article',
69       [
70         'types' => [
71           'sioc:Item',
72           'foaf:Document',
73         ],
74       ],
75       [
76         'field_image' => [
77           'properties' => [
78             'og:image',
79             'rdfs:seeAlso',
80           ],
81           'mapping_type' => 'rel',
82         ],
83         'field_tags' => [
84           'properties' => [
85             'dc:subject',
86           ],
87           'mapping_type' => 'rel',
88         ],
89         'title' => [
90           'properties' => [
91             'dc:title',
92           ],
93         ],
94         'created' => [
95           'properties' => [
96             'dc:date',
97             'dc:created',
98           ],
99           'datatype' => 'xsd:dateTime',
100           'datatype_callback' => [
101             'callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value',
102           ],
103         ],
104         'changed' => [
105           'properties' => [
106             'dc:modified',
107           ],
108           'datatype' => 'xsd:dateTime',
109           'datatype_callback' => [
110             'callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value',
111           ],
112         ],
113         'body' => [
114           'properties' => [
115             'content:encoded',
116           ],
117         ],
118         'uid' => [
119           'properties' => [
120             'sioc:has_creator',
121           ],
122           'mapping_type' => 'rel',
123         ],
124         'name' => [
125           'properties' => [
126             'foaf:name',
127           ],
128         ],
129         'comment_count' => [
130           'properties' => [
131             'sioc:num_replies',
132           ],
133           'datatype' => 'xsd:integer',
134         ],
135         'last_activity' => [
136           'properties' => [
137             'sioc:last_activity_date',
138           ],
139           'datatype' => 'xsd:dateTime',
140           'datatype_callback' => [
141             'callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value',
142           ],
143         ],
144       ]
145     );
146     $this->assertRdfMapping(
147       'node',
148       'blog',
149       [
150         'types' => [
151           'sioc:Post',
152           'sioct:BlogPost',
153         ],
154       ],
155       [
156         'title' => [
157           'properties' => [
158             'dc:title',
159           ],
160         ],
161         'created' => [
162           'properties' => [
163             'dc:date',
164             'dc:created',
165           ],
166           'datatype' => 'xsd:dateTime',
167           'datatype_callback' => [
168             'callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value',
169           ],
170         ],
171         'changed' => [
172           'properties' => [
173             'dc:modified',
174           ],
175           'datatype' => 'xsd:dateTime',
176           'datatype_callback' => [
177             'callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value',
178           ],
179         ],
180         'body' => [
181           'properties' => [
182             'content:encoded',
183           ],
184         ],
185         'uid' => [
186           'properties' => [
187             'sioc:has_creator',
188           ],
189           'mapping_type' => 'rel',
190         ],
191         'name' => [
192           'properties' => [
193             'foaf:name',
194           ],
195         ],
196         'comment_count' => [
197           'properties' => [
198             'sioc:num_replies',
199           ],
200           'datatype' => 'xsd:integer',
201         ],
202         'last_activity' => [
203           'properties' => [
204             'sioc:last_activity_date',
205           ],
206           'datatype' => 'xsd:dateTime',
207           'datatype_callback' => [
208             'callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value',
209           ],
210         ],
211       ]
212     );
213     $this->assertRdfMapping(
214       'node',
215       'forum',
216       [
217         'types' => [
218           'sioc:Post',
219           'sioct:BoardPost',
220         ],
221       ],
222       [
223         'taxonomy_forums' => [
224           'properties' => [
225             'sioc:has_container',
226           ],
227           'mapping_type' => 'rel',
228         ],
229         'title' => [
230           'properties' => [
231             'dc:title',
232           ],
233         ],
234         'created' => [
235           'properties' => [
236             'dc:date',
237             'dc:created',
238           ],
239           'datatype' => 'xsd:dateTime',
240           'datatype_callback' => [
241             'callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value',
242           ],
243         ],
244         'changed' => [
245           'properties' => [
246             'dc:modified',
247           ],
248           'datatype' => 'xsd:dateTime',
249           'datatype_callback' => [
250             'callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value',
251           ],
252         ],
253         'body' => [
254           'properties' => [
255             'content:encoded',
256           ],
257         ],
258         'uid' => [
259           'properties' => [
260             'sioc:has_creator',
261           ],
262           'mapping_type' => 'rel',
263         ],
264         'name' => [
265           'properties' => [
266             'foaf:name',
267           ],
268         ],
269         'comment_count' => [
270           'properties' => [
271             'sioc:num_replies',
272           ],
273           'datatype' => 'xsd:integer',
274         ],
275         'last_activity' => [
276           'properties' => [
277             'sioc:last_activity_date',
278           ],
279           'datatype' => 'xsd:dateTime',
280           'datatype_callback' => [
281             'callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value',
282           ],
283         ],
284       ]
285     );
286     $this->assertRdfMapping(
287       'node',
288       'page',
289       [
290         'types' => [
291           'foaf:Document',
292         ],
293       ],
294       [
295         'title' => [
296           'properties' => [
297             'dc:title',
298           ],
299         ],
300         'created' => [
301           'properties' => [
302             'dc:date',
303             'dc:created',
304           ],
305           'datatype' => 'xsd:dateTime',
306           'datatype_callback' => [
307             'callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value',
308           ],
309         ],
310         'changed' => [
311           'properties' => [
312             'dc:modified',
313           ],
314           'datatype' => 'xsd:dateTime',
315           'datatype_callback' => [
316             'callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value',
317           ],
318         ],
319         'body' => [
320           'properties' => [
321             'content:encoded',
322           ],
323         ],
324         'uid' => [
325           'properties' => [
326             'sioc:has_creator',
327           ],
328           'mapping_type' => 'rel',
329         ],
330         'name' => [
331           'properties' => [
332             'foaf:name',
333           ],
334         ],
335         'comment_count' => [
336           'properties' => [
337             'sioc:num_replies',
338           ],
339           'datatype' => 'xsd:integer',
340         ],
341         'last_activity' => [
342           'properties' => [
343             'sioc:last_activity_date',
344           ],
345           'datatype' => 'xsd:dateTime',
346           'datatype_callback' => [
347             'callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value',
348           ],
349         ],
350       ]
351     );
352     $this->assertRdfMapping(
353       'taxonomy_term',
354       'forums',
355       [
356         'types' => [
357           'sioc:Container',
358           'sioc:Forum',
359         ],
360       ],
361       [
362         'name' => [
363           'properties' => [
364             'rdfs:label',
365             'skos:prefLabel',
366           ],
367         ],
368         'description' => [
369           'properties' => [
370             'skos:definition',
371           ],
372         ],
373         'vid' => [
374           'properties' => [
375             'skos:inScheme',
376           ],
377           'mapping_type' => 'rel',
378         ],
379         'parent' => [
380           'properties' => [
381             'skos:broader',
382           ],
383           'mapping_type' => 'rel',
384         ],
385       ]
386     );
387
388     // Clear the map table and check that the migration runs successfully when
389     // the rdf mappings already exist.
390     $id_map = $this->getMigration('d7_rdf_mapping')->getIdMap();
391     $id_map->destroy();
392     $this->executeMigration('d7_rdf_mapping');
393   }
394
395 }