Mercurial > hg > isophonics-drupal-site
comparison core/modules/jsonapi/tests/src/Functional/EntityTestMapFieldTest.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\jsonapi\Functional; | |
4 | |
5 use Drupal\Core\Url; | |
6 use Drupal\entity_test\Entity\EntityTestMapField; | |
7 use Drupal\user\Entity\User; | |
8 | |
9 /** | |
10 * JSON:API integration test for the "EntityTestMapField" content entity type. | |
11 * | |
12 * @group jsonapi | |
13 */ | |
14 class EntityTestMapFieldTest extends ResourceTestBase { | |
15 | |
16 /** | |
17 * {@inheritdoc} | |
18 */ | |
19 public static $modules = ['entity_test']; | |
20 | |
21 /** | |
22 * {@inheritdoc} | |
23 */ | |
24 protected static $entityTypeId = 'entity_test_map_field'; | |
25 | |
26 /** | |
27 * {@inheritdoc} | |
28 */ | |
29 protected static $resourceTypeName = 'entity_test_map_field--entity_test_map_field'; | |
30 | |
31 /** | |
32 * {@inheritdoc} | |
33 */ | |
34 protected static $patchProtectedFieldNames = []; | |
35 | |
36 /** | |
37 * {@inheritdoc} | |
38 * | |
39 * @var \Drupal\entity_test\Entity\EntityTestMapField | |
40 */ | |
41 protected $entity; | |
42 | |
43 /** | |
44 * The complex nested value to assign to a @FieldType=map field. | |
45 * | |
46 * @var array | |
47 */ | |
48 protected static $mapValue = [ | |
49 'key1' => 'value', | |
50 'key2' => 'no, val you', | |
51 'π' => 3.14159, | |
52 TRUE => 42, | |
53 'nested' => [ | |
54 'bird' => 'robin', | |
55 'doll' => 'Russian', | |
56 ], | |
57 ]; | |
58 | |
59 /** | |
60 * {@inheritdoc} | |
61 */ | |
62 protected function setUpAuthorization($method) { | |
63 $this->grantPermissionsToTestedRole(['administer entity_test content']); | |
64 } | |
65 | |
66 /** | |
67 * {@inheritdoc} | |
68 */ | |
69 protected function createEntity() { | |
70 $entity = EntityTestMapField::create([ | |
71 'name' => 'Llama', | |
72 'type' => 'entity_test_map_field', | |
73 'data' => [ | |
74 static::$mapValue, | |
75 ], | |
76 ]); | |
77 $entity->setOwnerId(0); | |
78 $entity->save(); | |
79 return $entity; | |
80 } | |
81 | |
82 /** | |
83 * {@inheritdoc} | |
84 */ | |
85 protected function getExpectedDocument() { | |
86 $self_url = Url::fromUri('base:/jsonapi/entity_test_map_field/entity_test_map_field/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl(); | |
87 $author = User::load(0); | |
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' => 'entity_test_map_field--entity_test_map_field', | |
103 'links' => [ | |
104 'self' => ['href' => $self_url], | |
105 ], | |
106 'attributes' => [ | |
107 'created' => (new \DateTime())->setTimestamp($this->entity->get('created')->value)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), | |
108 'langcode' => 'en', | |
109 'name' => 'Llama', | |
110 'data' => static::$mapValue, | |
111 'drupal_internal__id' => 1, | |
112 ], | |
113 'relationships' => [ | |
114 'user_id' => [ | |
115 'data' => [ | |
116 'id' => $author->uuid(), | |
117 'type' => 'user--user', | |
118 ], | |
119 'links' => [ | |
120 'related' => ['href' => $self_url . '/user_id'], | |
121 'self' => ['href' => $self_url . '/relationships/user_id'], | |
122 ], | |
123 ], | |
124 ], | |
125 ], | |
126 ]; | |
127 } | |
128 | |
129 /** | |
130 * {@inheritdoc} | |
131 */ | |
132 protected function getPostDocument() { | |
133 return [ | |
134 'data' => [ | |
135 'type' => 'entity_test_map_field--entity_test_map_field', | |
136 'attributes' => [ | |
137 'name' => 'Dramallama', | |
138 'data' => static::$mapValue, | |
139 ], | |
140 ], | |
141 ]; | |
142 } | |
143 | |
144 /** | |
145 * {@inheritdoc} | |
146 */ | |
147 protected function getExpectedUnauthorizedAccessMessage($method) { | |
148 return "The 'administer entity_test content' permission is required."; | |
149 } | |
150 | |
151 /** | |
152 * {@inheritdoc} | |
153 */ | |
154 protected function getSparseFieldSets() { | |
155 // EntityTestMapField's owner field name is `user_id`, not `uid`, which | |
156 // breaks nested sparse fieldset tests. | |
157 return array_diff_key(parent::getSparseFieldSets(), array_flip([ | |
158 'nested_empty_fieldset', | |
159 'nested_fieldset_with_owner_fieldset', | |
160 ])); | |
161 } | |
162 | |
163 } |