Mercurial > hg > isophonics-drupal-site
comparison core/modules/rdf/tests/src/Kernel/CrudTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\rdf\Kernel; | |
4 | |
5 use Drupal\KernelTests\KernelTestBase; | |
6 | |
7 /** | |
8 * Tests the RDF mapping CRUD functions. | |
9 * | |
10 * @group rdf | |
11 */ | |
12 class CrudTest extends KernelTestBase { | |
13 | |
14 /** | |
15 * Modules to enable. | |
16 * | |
17 * @var array | |
18 */ | |
19 public static $modules = ['entity_test', 'rdf', 'system']; | |
20 | |
21 /** | |
22 * @var string | |
23 */ | |
24 protected $prefix; | |
25 | |
26 /** | |
27 * @var string | |
28 */ | |
29 protected $entityType; | |
30 | |
31 /** | |
32 * @var string | |
33 */ | |
34 protected $bundle; | |
35 | |
36 protected function setUp() { | |
37 parent::setUp(); | |
38 $this->prefix = 'rdf.mapping'; | |
39 $this->entityType = $this->bundle = 'entity_test'; | |
40 } | |
41 | |
42 /** | |
43 * Tests creation of RDF mapping. | |
44 */ | |
45 public function testMappingCreation() { | |
46 $mapping_config_name = "{$this->prefix}.{$this->entityType}.{$this->bundle}"; | |
47 | |
48 // Save bundle mapping config. | |
49 rdf_get_mapping($this->entityType, $this->bundle)->save(); | |
50 // Test that config file was saved. | |
51 $mapping_config = \Drupal::configFactory()->listAll('rdf.mapping.'); | |
52 $this->assertTrue(in_array($mapping_config_name, $mapping_config), 'Rdf mapping config saved.'); | |
53 } | |
54 | |
55 /** | |
56 * Test the handling of bundle mappings. | |
57 */ | |
58 public function testBundleMapping() { | |
59 // Test that the bundle mapping can be saved. | |
60 $types = ['sioc:Post', 'foaf:Document']; | |
61 rdf_get_mapping($this->entityType, $this->bundle) | |
62 ->setBundleMapping(['types' => $types]) | |
63 ->save(); | |
64 $bundle_mapping = rdf_get_mapping($this->entityType, $this->bundle) | |
65 ->getBundleMapping(); | |
66 $this->assertEqual($types, $bundle_mapping['types'], 'Bundle mapping saved.'); | |
67 | |
68 // Test that the bundle mapping can be edited. | |
69 $types = ['schema:BlogPosting']; | |
70 rdf_get_mapping($this->entityType, $this->bundle) | |
71 ->setBundleMapping(['types' => $types]) | |
72 ->save(); | |
73 $bundle_mapping = rdf_get_mapping($this->entityType, $this->bundle) | |
74 ->getBundleMapping(); | |
75 $this->assertEqual($types, $bundle_mapping['types'], 'Bundle mapping updated.'); | |
76 } | |
77 | |
78 /** | |
79 * Test the handling of field mappings. | |
80 */ | |
81 public function testFieldMapping() { | |
82 $field_name = 'created'; | |
83 | |
84 // Test that the field mapping can be saved. | |
85 $mapping = [ | |
86 'properties' => ['dc:created'], | |
87 'datatype' => 'xsd:dateTime', | |
88 'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'], | |
89 ]; | |
90 rdf_get_mapping($this->entityType, $this->bundle) | |
91 ->setFieldMapping($field_name, $mapping) | |
92 ->save(); | |
93 $field_mapping = rdf_get_mapping($this->entityType, $this->bundle) | |
94 ->getFieldMapping($field_name); | |
95 $this->assertEqual($mapping, $field_mapping, 'Field mapping saved.'); | |
96 | |
97 // Test that the field mapping can be edited. | |
98 $mapping = [ | |
99 'properties' => ['dc:date'], | |
100 'datatype' => 'foo:bar', | |
101 'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'], | |
102 ]; | |
103 rdf_get_mapping($this->entityType, $this->bundle) | |
104 ->setFieldMapping($field_name, $mapping) | |
105 ->save(); | |
106 $field_mapping = rdf_get_mapping($this->entityType, $this->bundle) | |
107 ->getFieldMapping($field_name); | |
108 $this->assertEqual($mapping, $field_mapping, 'Field mapping updated.'); | |
109 } | |
110 | |
111 } |