Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/jsonapi/tests/src/Functional/RdfMappingTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\jsonapi\Functional; | |
4 | |
5 use Drupal\Core\Url; | |
6 use Drupal\node\Entity\NodeType; | |
7 use Drupal\rdf\Entity\RdfMapping; | |
8 | |
9 /** | |
10 * JSON:API integration test for the "RdfMapping" config entity type. | |
11 * | |
12 * @group jsonapi | |
13 */ | |
14 class RdfMappingTest extends ResourceTestBase { | |
15 | |
16 /** | |
17 * {@inheritdoc} | |
18 */ | |
19 public static $modules = ['node', 'rdf']; | |
20 | |
21 /** | |
22 * {@inheritdoc} | |
23 */ | |
24 protected static $entityTypeId = 'rdf_mapping'; | |
25 | |
26 /** | |
27 * {@inheritdoc} | |
28 */ | |
29 protected static $resourceTypeName = 'rdf_mapping--rdf_mapping'; | |
30 | |
31 /** | |
32 * {@inheritdoc} | |
33 * | |
34 * @var \Drupal\rdf\RdfMappingInterface | |
35 */ | |
36 protected $entity; | |
37 | |
38 /** | |
39 * {@inheritdoc} | |
40 */ | |
41 protected function setUpAuthorization($method) { | |
42 $this->grantPermissionsToTestedRole(['administer site configuration']); | |
43 } | |
44 | |
45 /** | |
46 * {@inheritdoc} | |
47 */ | |
48 protected function createEntity() { | |
49 // Create a "Camelids" node type. | |
50 $camelids = NodeType::create([ | |
51 'name' => 'Camelids', | |
52 'type' => 'camelids', | |
53 ]); | |
54 | |
55 $camelids->save(); | |
56 | |
57 // Create the RDF mapping. | |
58 $llama = RdfMapping::create([ | |
59 'targetEntityType' => 'node', | |
60 'bundle' => 'camelids', | |
61 ]); | |
62 $llama->setBundleMapping([ | |
63 'types' => ['sioc:Item', 'foaf:Document'], | |
64 ]) | |
65 ->setFieldMapping('title', [ | |
66 'properties' => ['dc:title'], | |
67 ]) | |
68 ->setFieldMapping('created', [ | |
69 'properties' => ['dc:date', 'dc:created'], | |
70 'datatype' => 'xsd:dateTime', | |
71 'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'], | |
72 ]) | |
73 ->save(); | |
74 | |
75 return $llama; | |
76 } | |
77 | |
78 /** | |
79 * {@inheritdoc} | |
80 */ | |
81 protected function getExpectedDocument() { | |
82 $self_url = Url::fromUri('base:/jsonapi/rdf_mapping/rdf_mapping/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl(); | |
83 return [ | |
84 'jsonapi' => [ | |
85 'meta' => [ | |
86 'links' => [ | |
87 'self' => ['href' => 'http://jsonapi.org/format/1.0/'], | |
88 ], | |
89 ], | |
90 'version' => '1.0', | |
91 ], | |
92 'links' => [ | |
93 'self' => ['href' => $self_url], | |
94 ], | |
95 'data' => [ | |
96 'id' => $this->entity->uuid(), | |
97 'type' => 'rdf_mapping--rdf_mapping', | |
98 'links' => [ | |
99 'self' => ['href' => $self_url], | |
100 ], | |
101 'attributes' => [ | |
102 'bundle' => 'camelids', | |
103 'dependencies' => [ | |
104 'config' => [ | |
105 'node.type.camelids', | |
106 ], | |
107 'module' => [ | |
108 'node', | |
109 ], | |
110 ], | |
111 'fieldMappings' => [ | |
112 'title' => [ | |
113 'properties' => [ | |
114 'dc:title', | |
115 ], | |
116 ], | |
117 'created' => [ | |
118 'properties' => [ | |
119 'dc:date', | |
120 'dc:created', | |
121 ], | |
122 'datatype' => 'xsd:dateTime', | |
123 'datatype_callback' => [ | |
124 'callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value', | |
125 ], | |
126 ], | |
127 ], | |
128 'langcode' => 'en', | |
129 'status' => TRUE, | |
130 'targetEntityType' => 'node', | |
131 'types' => [ | |
132 'sioc:Item', | |
133 'foaf:Document', | |
134 ], | |
135 'drupal_internal__id' => 'node.camelids', | |
136 ], | |
137 ], | |
138 ]; | |
139 } | |
140 | |
141 /** | |
142 * {@inheritdoc} | |
143 */ | |
144 protected function getPostDocument() { | |
145 // @todo Update in https://www.drupal.org/node/2300677. | |
146 } | |
147 | |
148 } |