class MessageResourceTestBase
Same name and namespace in other branches
- 11.x core/modules/contact/tests/src/Functional/Rest/MessageResourceTestBase.php \Drupal\Tests\contact\Functional\Rest\MessageResourceTestBase
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\rest\Functional\ResourceTestBase implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase implements \Drupal\Tests\rest\Functional\ResourceTestBase
- class \Drupal\Tests\contact\Functional\Rest\MessageResourceTestBase implements \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase
- class \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase implements \Drupal\Tests\rest\Functional\ResourceTestBase
- class \Drupal\Tests\rest\Functional\ResourceTestBase implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of MessageResourceTestBase
1 file declares its use of MessageResourceTestBase
- MessageHalJsonAnonTest.php in core/
modules/ hal/ tests/ src/ Functional/ contact/ MessageHalJsonAnonTest.php
File
-
core/
modules/ contact/ tests/ src/ Functional/ Rest/ MessageResourceTestBase.php, line 11
Namespace
Drupal\Tests\contact\Functional\RestView source
abstract class MessageResourceTestBase extends EntityResourceTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'contact',
];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'contact_message';
/**
* {@inheritdoc}
*/
protected static $labelFieldName = 'subject';
/**
* The Message entity.
*
* @var \Drupal\contact\MessageInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
$this->grantPermissionsToTestedRole([
'access site-wide contact form',
]);
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
if (!ContactForm::load('camelids')) {
// Create a "Camelids" contact form.
ContactForm::create([
'id' => 'camelids',
'label' => 'Llama',
'message' => 'Let us know what you think about llamas',
'reply' => 'Llamas are indeed awesome!',
'recipients' => [
'llama@example.com',
'contact@example.com',
],
])->save();
}
$message = Message::create([
'contact_form' => 'camelids',
'subject' => 'Llama Gabilondo',
'message' => 'Llamas are awesome!',
]);
$message->save();
return $message;
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return [
'subject' => [
[
'value' => 'Dramallama',
],
],
'contact_form' => [
[
'target_id' => 'camelids',
],
],
'message' => [
[
'value' => 'http://www.urbandictionary.com/define.php?term=drama%20llama',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
throw new \Exception('Not yet supported.');
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessMessage($method) {
if ($method === 'POST') {
return "The 'access site-wide contact form' permission is required.";
}
return parent::getExpectedUnauthorizedAccessMessage($method);
}
/**
* {@inheritdoc}
*/
public function testGet() {
// Contact Message entities are not stored, so they cannot be retrieved.
$this->expectException(RouteNotFoundException::class);
$this->expectExceptionMessage('Route "rest.entity.contact_message.GET" does not exist.');
$this->provisionEntityResource();
Url::fromRoute('rest.entity.contact_message.GET')->toString(TRUE);
}
/**
* {@inheritdoc}
*/
public function testPatch() {
// Contact Message entities are not stored, so they cannot be modified.
$this->expectException(RouteNotFoundException::class);
$this->expectExceptionMessage('Route "rest.entity.contact_message.PATCH" does not exist.');
$this->provisionEntityResource();
Url::fromRoute('rest.entity.contact_message.PATCH')->toString(TRUE);
}
/**
* {@inheritdoc}
*/
public function testDelete() {
// Contact Message entities are not stored, so they cannot be deleted.
$this->expectException(RouteNotFoundException::class);
$this->expectExceptionMessage('Route "rest.entity.contact_message.DELETE" does not exist.');
$this->provisionEntityResource();
Url::fromRoute('rest.entity.contact_message.DELETE')->toString(TRUE);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.