51e297a7b83e5c0d6420b6f768c2036b43ec9839
[yaffs-website] / web / core / modules / rest / tests / src / Functional / EntityResource / ContactForm / ContactFormResourceTestBase.php
1 <?php
2
3 namespace Drupal\Tests\rest\Functional\EntityResource\ContactForm;
4
5 use Drupal\contact\Entity\ContactForm;
6 use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
7 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
8
9 abstract class ContactFormResourceTestBase extends EntityResourceTestBase {
10
11   use BcTimestampNormalizerUnixTestTrait;
12
13   /**
14    * {@inheritdoc}
15    */
16   public static $modules = ['contact'];
17
18   /**
19    * {@inheritdoc}
20    */
21   protected static $entityTypeId = 'contact_form';
22
23   /**
24    * {@inheritdoc}
25    */
26   protected static $patchProtectedFieldNames = [];
27
28   /**
29    * @var \Drupal\contact\Entity\ContactForm
30    */
31   protected $entity;
32
33   /**
34    * {@inheritdoc}
35    */
36   protected function setUpAuthorization($method) {
37     switch ($method) {
38       case 'GET':
39         $this->grantPermissionsToTestedRole(['access site-wide contact form']);
40       default:
41         $this->grantPermissionsToTestedRole(['administer contact forms']);
42     }
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   protected function createEntity() {
49     $contact_form = ContactForm::create([
50       'id' => 'llama',
51       'label' => 'Llama',
52       'message' => 'Let us know what you think about llamas',
53       'reply' => 'Llamas are indeed awesome!',
54       'recipients' => [
55         'llama@example.com',
56         'contact@example.com',
57       ],
58     ]);
59     $contact_form->save();
60
61     return $contact_form;
62   }
63
64   /**
65    * {@inheritdoc}
66    */
67   protected function getExpectedNormalizedEntity() {
68     return [
69       'dependencies' => [],
70       'id' => 'llama',
71       'label' => 'Llama',
72       'langcode' => 'en',
73       'message' => 'Let us know what you think about llamas',
74       'recipients' => [
75         'llama@example.com',
76         'contact@example.com',
77       ],
78       'redirect' => NULL,
79       'reply' => 'Llamas are indeed awesome!',
80       'status' => TRUE,
81       'uuid' => $this->entity->uuid(),
82       'weight' => 0,
83     ];
84   }
85
86   /**
87    * {@inheritdoc}
88    */
89   protected function getNormalizedPostEntity() {
90     // @todo Update in https://www.drupal.org/node/2300677.
91   }
92
93   /**
94    * {@inheritdoc}
95    */
96   protected function getExpectedUnauthorizedAccessMessage($method) {
97     if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
98       return parent::getExpectedUnauthorizedAccessMessage($method);
99     }
100
101     return "The 'access site-wide contact form' permission is required.";
102   }
103
104 }