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