Mercurial > hg > isophonics-drupal-site
comparison core/modules/jsonapi/tests/src/Functional/FieldConfigTest.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\Entity\EntityInterface; | |
6 use Drupal\Core\Session\AccountInterface; | |
7 use Drupal\Core\Url; | |
8 use Drupal\field\Entity\FieldConfig; | |
9 use Drupal\field\Entity\FieldStorageConfig; | |
10 use Drupal\node\Entity\NodeType; | |
11 | |
12 /** | |
13 * JSON:API integration test for the "FieldConfig" config entity type. | |
14 * | |
15 * @group jsonapi | |
16 */ | |
17 class FieldConfigTest extends ResourceTestBase { | |
18 | |
19 /** | |
20 * {@inheritdoc} | |
21 */ | |
22 public static $modules = ['field', 'node']; | |
23 | |
24 /** | |
25 * {@inheritdoc} | |
26 */ | |
27 protected static $entityTypeId = 'field_config'; | |
28 | |
29 /** | |
30 * {@inheritdoc} | |
31 */ | |
32 protected static $resourceTypeName = 'field_config--field_config'; | |
33 | |
34 /** | |
35 * {@inheritdoc} | |
36 * | |
37 * @var \Drupal\field\FieldConfigInterface | |
38 */ | |
39 protected $entity; | |
40 | |
41 /** | |
42 * {@inheritdoc} | |
43 */ | |
44 protected function setUpAuthorization($method) { | |
45 $this->grantPermissionsToTestedRole(['administer node fields']); | |
46 } | |
47 | |
48 /** | |
49 * {@inheritdoc} | |
50 */ | |
51 protected function createEntity() { | |
52 $camelids = NodeType::create([ | |
53 'name' => 'Camelids', | |
54 'type' => 'camelids', | |
55 ]); | |
56 $camelids->save(); | |
57 | |
58 $field_storage = FieldStorageConfig::create([ | |
59 'field_name' => 'field_llama', | |
60 'entity_type' => 'node', | |
61 'type' => 'text', | |
62 ]); | |
63 $field_storage->save(); | |
64 | |
65 $entity = FieldConfig::create([ | |
66 'field_storage' => $field_storage, | |
67 'bundle' => 'camelids', | |
68 ]); | |
69 $entity->save(); | |
70 | |
71 return $entity; | |
72 } | |
73 | |
74 /** | |
75 * {@inheritdoc} | |
76 */ | |
77 protected function getExpectedDocument() { | |
78 $self_url = Url::fromUri('base:/jsonapi/field_config/field_config/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl(); | |
79 return [ | |
80 'jsonapi' => [ | |
81 'meta' => [ | |
82 'links' => [ | |
83 'self' => ['href' => 'http://jsonapi.org/format/1.0/'], | |
84 ], | |
85 ], | |
86 'version' => '1.0', | |
87 ], | |
88 'links' => [ | |
89 'self' => ['href' => $self_url], | |
90 ], | |
91 'data' => [ | |
92 'id' => $this->entity->uuid(), | |
93 'type' => 'field_config--field_config', | |
94 'links' => [ | |
95 'self' => ['href' => $self_url], | |
96 ], | |
97 'attributes' => [ | |
98 'bundle' => 'camelids', | |
99 'default_value' => [], | |
100 'default_value_callback' => '', | |
101 'dependencies' => [ | |
102 'config' => [ | |
103 'field.storage.node.field_llama', | |
104 'node.type.camelids', | |
105 ], | |
106 'module' => [ | |
107 'text', | |
108 ], | |
109 ], | |
110 'description' => '', | |
111 'entity_type' => 'node', | |
112 'field_name' => 'field_llama', | |
113 'field_type' => 'text', | |
114 'label' => 'field_llama', | |
115 'langcode' => 'en', | |
116 'required' => FALSE, | |
117 'settings' => [], | |
118 'status' => TRUE, | |
119 'translatable' => TRUE, | |
120 'drupal_internal__id' => 'node.camelids.field_llama', | |
121 ], | |
122 ], | |
123 ]; | |
124 } | |
125 | |
126 /** | |
127 * {@inheritdoc} | |
128 */ | |
129 protected function getPostDocument() { | |
130 // @todo Update in https://www.drupal.org/node/2300677. | |
131 } | |
132 | |
133 /** | |
134 * {@inheritdoc} | |
135 */ | |
136 protected function getExpectedUnauthorizedAccessMessage($method) { | |
137 return "The 'administer node fields' permission is required."; | |
138 } | |
139 | |
140 /** | |
141 * {@inheritdoc} | |
142 */ | |
143 protected function createAnotherEntity($key) { | |
144 NodeType::create([ | |
145 'name' => 'Pachyderms', | |
146 'type' => 'pachyderms', | |
147 ])->save(); | |
148 | |
149 $field_storage = FieldStorageConfig::create([ | |
150 'field_name' => 'field_pachyderm', | |
151 'entity_type' => 'node', | |
152 'type' => 'text', | |
153 ]); | |
154 $field_storage->save(); | |
155 | |
156 $entity = FieldConfig::create([ | |
157 'field_storage' => $field_storage, | |
158 'bundle' => 'pachyderms', | |
159 ]); | |
160 $entity->save(); | |
161 | |
162 return $entity; | |
163 } | |
164 | |
165 /** | |
166 * {@inheritdoc} | |
167 */ | |
168 protected static function entityAccess(EntityInterface $entity, $operation, AccountInterface $account) { | |
169 // Also clear the 'field_storage_config' entity access handler cache because | |
170 // the 'field_config' access handler delegates access to it. | |
171 // @see \Drupal\field\FieldConfigAccessControlHandler::checkAccess() | |
172 \Drupal::entityTypeManager()->getAccessControlHandler('field_storage_config')->resetCache(); | |
173 return parent::entityAccess($entity, $operation, $account); | |
174 } | |
175 | |
176 } |