Chris@18
|
1 <?php
|
Chris@18
|
2
|
Chris@18
|
3 namespace Drupal\Tests\jsonapi\Functional;
|
Chris@18
|
4
|
Chris@18
|
5 use Drupal\Core\Url;
|
Chris@18
|
6 use Drupal\tour\Entity\Tour;
|
Chris@18
|
7
|
Chris@18
|
8 /**
|
Chris@18
|
9 * JSON:API integration test for the "Tour" config entity type.
|
Chris@18
|
10 *
|
Chris@18
|
11 * @group jsonapi
|
Chris@18
|
12 */
|
Chris@18
|
13 class TourTest extends ResourceTestBase {
|
Chris@18
|
14
|
Chris@18
|
15 /**
|
Chris@18
|
16 * {@inheritdoc}
|
Chris@18
|
17 */
|
Chris@18
|
18 public static $modules = ['tour'];
|
Chris@18
|
19
|
Chris@18
|
20 /**
|
Chris@18
|
21 * {@inheritdoc}
|
Chris@18
|
22 */
|
Chris@18
|
23 protected static $entityTypeId = 'tour';
|
Chris@18
|
24
|
Chris@18
|
25 /**
|
Chris@18
|
26 * {@inheritdoc}
|
Chris@18
|
27 */
|
Chris@18
|
28 protected static $resourceTypeName = 'tour--tour';
|
Chris@18
|
29
|
Chris@18
|
30 /**
|
Chris@18
|
31 * {@inheritdoc}
|
Chris@18
|
32 *
|
Chris@18
|
33 * @var \Drupal\tour\TourInterface
|
Chris@18
|
34 */
|
Chris@18
|
35 protected $entity;
|
Chris@18
|
36
|
Chris@18
|
37 /**
|
Chris@18
|
38 * {@inheritdoc}
|
Chris@18
|
39 */
|
Chris@18
|
40 protected function setUpAuthorization($method) {
|
Chris@18
|
41 $this->grantPermissionsToTestedRole(['access tour']);
|
Chris@18
|
42 }
|
Chris@18
|
43
|
Chris@18
|
44 /**
|
Chris@18
|
45 * {@inheritdoc}
|
Chris@18
|
46 */
|
Chris@18
|
47 protected function createEntity() {
|
Chris@18
|
48 $tour = Tour::create([
|
Chris@18
|
49 'id' => 'tour-llama',
|
Chris@18
|
50 'label' => 'Llama tour',
|
Chris@18
|
51 'langcode' => 'en',
|
Chris@18
|
52 'module' => 'tour',
|
Chris@18
|
53 'routes' => [
|
Chris@18
|
54 [
|
Chris@18
|
55 'route_name' => '<front>',
|
Chris@18
|
56 ],
|
Chris@18
|
57 ],
|
Chris@18
|
58 'tips' => [
|
Chris@18
|
59 'tour-llama-1' => [
|
Chris@18
|
60 'id' => 'tour-llama-1',
|
Chris@18
|
61 'plugin' => 'text',
|
Chris@18
|
62 'label' => 'Llama',
|
Chris@18
|
63 'body' => 'Who handle the awesomeness of llamas?',
|
Chris@18
|
64 'weight' => 100,
|
Chris@18
|
65 'attributes' => [
|
Chris@18
|
66 'data-id' => 'tour-llama-1',
|
Chris@18
|
67 ],
|
Chris@18
|
68 ],
|
Chris@18
|
69 ],
|
Chris@18
|
70 ]);
|
Chris@18
|
71 $tour->save();
|
Chris@18
|
72
|
Chris@18
|
73 return $tour;
|
Chris@18
|
74 }
|
Chris@18
|
75
|
Chris@18
|
76 /**
|
Chris@18
|
77 * {@inheritdoc}
|
Chris@18
|
78 */
|
Chris@18
|
79 protected function getExpectedDocument() {
|
Chris@18
|
80 $self_url = Url::fromUri('base:/jsonapi/tour/tour/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl();
|
Chris@18
|
81 return [
|
Chris@18
|
82 'jsonapi' => [
|
Chris@18
|
83 'meta' => [
|
Chris@18
|
84 'links' => [
|
Chris@18
|
85 'self' => ['href' => 'http://jsonapi.org/format/1.0/'],
|
Chris@18
|
86 ],
|
Chris@18
|
87 ],
|
Chris@18
|
88 'version' => '1.0',
|
Chris@18
|
89 ],
|
Chris@18
|
90 'links' => [
|
Chris@18
|
91 'self' => ['href' => $self_url],
|
Chris@18
|
92 ],
|
Chris@18
|
93 'data' => [
|
Chris@18
|
94 'id' => $this->entity->uuid(),
|
Chris@18
|
95 'type' => 'tour--tour',
|
Chris@18
|
96 'links' => [
|
Chris@18
|
97 'self' => ['href' => $self_url],
|
Chris@18
|
98 ],
|
Chris@18
|
99 'attributes' => [
|
Chris@18
|
100 'dependencies' => [],
|
Chris@18
|
101 'label' => 'Llama tour',
|
Chris@18
|
102 'langcode' => 'en',
|
Chris@18
|
103 'module' => 'tour',
|
Chris@18
|
104 'routes' => [
|
Chris@18
|
105 [
|
Chris@18
|
106 'route_name' => '<front>',
|
Chris@18
|
107 ],
|
Chris@18
|
108 ],
|
Chris@18
|
109 'status' => TRUE,
|
Chris@18
|
110 'tips' => [
|
Chris@18
|
111 'tour-llama-1' => [
|
Chris@18
|
112 'id' => 'tour-llama-1',
|
Chris@18
|
113 'plugin' => 'text',
|
Chris@18
|
114 'label' => 'Llama',
|
Chris@18
|
115 'body' => 'Who handle the awesomeness of llamas?',
|
Chris@18
|
116 'weight' => 100,
|
Chris@18
|
117 'attributes' => [
|
Chris@18
|
118 'data-id' => 'tour-llama-1',
|
Chris@18
|
119 ],
|
Chris@18
|
120 ],
|
Chris@18
|
121 ],
|
Chris@18
|
122 'drupal_internal__id' => 'tour-llama',
|
Chris@18
|
123 ],
|
Chris@18
|
124 ],
|
Chris@18
|
125 ];
|
Chris@18
|
126 }
|
Chris@18
|
127
|
Chris@18
|
128 /**
|
Chris@18
|
129 * {@inheritdoc}
|
Chris@18
|
130 */
|
Chris@18
|
131 protected function getPostDocument() {
|
Chris@18
|
132 // @todo Update in https://www.drupal.org/node/2300677.
|
Chris@18
|
133 }
|
Chris@18
|
134
|
Chris@18
|
135 /**
|
Chris@18
|
136 * {@inheritdoc}
|
Chris@18
|
137 */
|
Chris@18
|
138 protected function getExpectedUnauthorizedAccessMessage($method) {
|
Chris@18
|
139 return "The following permissions are required: 'access tour' OR 'administer site configuration'.";
|
Chris@18
|
140 }
|
Chris@18
|
141
|
Chris@18
|
142 }
|