comparison core/tests/Drupal/FunctionalTests/Rest/BaseFieldOverrideResourceTestBase.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 namespace Drupal\FunctionalTests\Rest;
4
5 use Drupal\Core\Field\Entity\BaseFieldOverride;
6 use Drupal\node\Entity\NodeType;
7 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
8
9 abstract class BaseFieldOverrideResourceTestBase extends EntityResourceTestBase {
10
11 /**
12 * {@inheritdoc}
13 */
14 public static $modules = ['field', 'node'];
15
16 /**
17 * {@inheritdoc}
18 */
19 protected static $entityTypeId = 'base_field_override';
20
21 /**
22 * @var \Drupal\Core\Field\Entity\BaseFieldOverride
23 */
24 protected $entity;
25
26 /**
27 * {@inheritdoc}
28 */
29 protected function setUpAuthorization($method) {
30 $this->grantPermissionsToTestedRole(['administer node fields']);
31 }
32
33 /**
34 * {@inheritdoc}
35 */
36 protected function createEntity() {
37 $camelids = NodeType::create([
38 'name' => 'Camelids',
39 'type' => 'camelids',
40 ]);
41 $camelids->save();
42
43 $entity = BaseFieldOverride::create([
44 'field_name' => 'promote',
45 'entity_type' => 'node',
46 'bundle' => 'camelids',
47 ]);
48 $entity->save();
49
50 return $entity;
51 }
52
53 /**
54 * {@inheritdoc}
55 */
56 protected function getExpectedNormalizedEntity() {
57 return [
58 'bundle' => 'camelids',
59 'default_value' => [],
60 'default_value_callback' => '',
61 'dependencies' => [
62 'config' => [
63 'node.type.camelids',
64 ],
65 ],
66 'description' => '',
67 'entity_type' => 'node',
68 'field_name' => 'promote',
69 'field_type' => 'boolean',
70 'id' => 'node.camelids.promote',
71 'label' => NULL,
72 'langcode' => 'en',
73 'required' => FALSE,
74 'settings' => [
75 'on_label' => 'On',
76 'off_label' => 'Off',
77 ],
78 'status' => TRUE,
79 'translatable' => TRUE,
80 'uuid' => $this->entity->uuid(),
81 ];
82 }
83
84 /**
85 * {@inheritdoc}
86 */
87 protected function getNormalizedPostEntity() {
88 // @todo Update in https://www.drupal.org/node/2300677.
89 }
90
91 /**
92 * {@inheritdoc}
93 */
94 protected function getExpectedCacheContexts() {
95 return [
96 'user.permissions',
97 ];
98 }
99
100 /**
101 * {@inheritdoc}
102 */
103 protected function getExpectedUnauthorizedAccessMessage($method) {
104 if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
105 return parent::getExpectedUnauthorizedAccessMessage($method);
106 }
107
108 return "The 'administer node fields' permission is required.";
109 }
110
111 }