c374bfb7c0f1b7c2e0942e504099ed5020eec94f
[yaffs-website] / web / core / modules / rest / tests / src / Functional / EntityResource / NodeType / NodeTypeResourceTestBase.php
1 <?php
2
3 namespace Drupal\Tests\rest\Functional\EntityResource\NodeType;
4
5 use Drupal\node\Entity\NodeType;
6 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
7
8 /**
9  * ResourceTestBase for NodeType entity.
10  */
11 abstract class NodeTypeResourceTestBase extends EntityResourceTestBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public static $modules = ['node'];
17
18   /**
19    * {@inheritdoc}
20    */
21   protected static $entityTypeId = 'node_type';
22
23   /**
24    * The NodeType entity.
25    *
26    * @var \Drupal\node\NodeTypeInterface
27    */
28   protected $entity;
29
30   /**
31    * {@inheritdoc}
32    */
33   protected function setUpAuthorization($method) {
34     $this->grantPermissionsToTestedRole(['administer content types', 'access content']);
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   protected function createEntity() {
41     // Create a "Camelids" node type.
42     $camelids = NodeType::create([
43       'name' => 'Camelids',
44       'type' => 'camelids',
45       'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
46     ]);
47
48     $camelids->save();
49
50     return $camelids;
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   protected function getExpectedNormalizedEntity() {
57     return [
58       'dependencies' => [],
59       'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
60       'display_submitted' => TRUE,
61       'help' => NULL,
62       'langcode' => 'en',
63       'name' => 'Camelids',
64       'new_revision' => TRUE,
65       'preview_mode' => 1,
66       'status' => TRUE,
67       'type' => 'camelids',
68       'uuid' => $this->entity->uuid(),
69     ];
70   }
71
72   /**
73    * {@inheritdoc}
74    */
75   protected function getNormalizedPostEntity() {
76     // @todo Update in https://www.drupal.org/node/2300677.
77   }
78
79   /**
80    * {@inheritdoc}
81    */
82   protected function getExpectedUnauthorizedAccessMessage($method) {
83     if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
84       return parent::getExpectedUnauthorizedAccessMessage($method);
85     }
86
87     return "The 'access content' permission is required.";
88   }
89
90 }