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