Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / rest / tests / src / Functional / EntityResource / FieldConfig / FieldConfigResourceTestBase.php
1 <?php
2
3 namespace Drupal\Tests\rest\Functional\EntityResource\FieldConfig;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
7 use Drupal\node\Entity\NodeType;
8 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
9
10 abstract class FieldConfigResourceTestBase extends EntityResourceTestBase {
11
12   /**
13    * {@inheritdoc}
14    */
15   public static $modules = ['field', 'node'];
16
17   /**
18    * {@inheritdoc}
19    */
20   protected static $entityTypeId = 'field_config';
21
22   /**
23    * @var \Drupal\field\FieldConfigInterface
24    */
25   protected $entity;
26
27   /**
28    * {@inheritdoc}
29    */
30   protected function setUpAuthorization($method) {
31     $this->grantPermissionsToTestedRole(['administer node fields']);
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   protected function createEntity() {
38     $camelids = NodeType::create([
39       'name' => 'Camelids',
40       'type' => 'camelids',
41     ]);
42     $camelids->save();
43
44     $field_storage = FieldStorageConfig::create([
45       'field_name' => 'field_llama',
46       'entity_type' => 'node',
47       'type' => 'text',
48     ]);
49     $field_storage->save();
50
51     $entity = FieldConfig::create([
52       'field_storage' => $field_storage,
53       'bundle' => 'camelids',
54     ]);
55     $entity->save();
56
57     return $entity;
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   protected function getExpectedNormalizedEntity() {
64     return [
65       'bundle' => 'camelids',
66       'default_value' => [],
67       'default_value_callback' => '',
68       'dependencies' => [
69         'config' => [
70           'field.storage.node.field_llama',
71           'node.type.camelids',
72         ],
73         'module' => [
74           'text',
75         ],
76       ],
77       'description' => '',
78       'entity_type' => 'node',
79       'field_name' => 'field_llama',
80       'field_type' => 'text',
81       'id' => 'node.camelids.field_llama',
82       'label' => 'field_llama',
83       'langcode' => 'en',
84       'required' => FALSE,
85       'settings' => [],
86       'status' => TRUE,
87       'translatable' => TRUE,
88       'uuid' => $this->entity->uuid(),
89     ];
90   }
91
92   /**
93    * {@inheritdoc}
94    */
95   protected function getNormalizedPostEntity() {
96     // @todo Update in https://www.drupal.org/node/2300677.
97   }
98
99   /**
100    * {@inheritdoc}
101    */
102   protected function getExpectedCacheContexts() {
103     return [
104       'user.permissions',
105     ];
106   }
107
108   /**
109    * {@inheritdoc}
110    */
111   protected function getExpectedUnauthorizedAccessMessage($method) {
112     if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
113       return parent::getExpectedUnauthorizedAccessMessage($method);
114     }
115
116     return "The 'administer node fields' permission is required.";
117   }
118
119 }