View source
<?php
namespace Drupal\Tests\contact\Functional\Rest;
use Drupal\contact\Entity\ContactForm;
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
abstract class ContactFormResourceTestBase extends EntityResourceTestBase {
use BcTimestampNormalizerUnixTestTrait;
public static $modules = [
'contact',
];
protected static $entityTypeId = 'contact_form';
protected static $patchProtectedFieldNames = [];
protected $entity;
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
$this
->grantPermissionsToTestedRole([
'access site-wide contact form',
]);
default:
$this
->grantPermissionsToTestedRole([
'administer contact forms',
]);
}
}
protected function createEntity() {
$contact_form = ContactForm::create([
'id' => 'llama',
'label' => 'Llama',
'message' => 'Let us know what you think about llamas',
'reply' => 'Llamas are indeed awesome!',
'recipients' => [
'llama@example.com',
'contact@example.com',
],
]);
$contact_form
->save();
return $contact_form;
}
protected function getExpectedNormalizedEntity() {
return [
'dependencies' => [],
'id' => 'llama',
'label' => 'Llama',
'langcode' => 'en',
'message' => 'Let us know what you think about llamas',
'recipients' => [
'llama@example.com',
'contact@example.com',
],
'redirect' => NULL,
'reply' => 'Llamas are indeed awesome!',
'status' => TRUE,
'uuid' => $this->entity
->uuid(),
'weight' => 0,
];
}
protected function getNormalizedPostEntity() {
}
protected function getExpectedUnauthorizedAccessMessage($method) {
if ($this
->config('rest.settings')
->get('bc_entity_resource_permissions')) {
return parent::getExpectedUnauthorizedAccessMessage($method);
}
return "The 'access site-wide contact form' permission is required.";
}
}