class MessageEntityTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/contact/tests/src/Kernel/MessageEntityTest.php \Drupal\Tests\contact\Kernel\MessageEntityTest
- 9 core/modules/contact/tests/src/Kernel/MessageEntityTest.php \Drupal\Tests\contact\Kernel\MessageEntityTest
Tests the message entity class.
@group contact
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, AssertContentTrait, ConfigTestTrait, ExtensionListTestTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses UserCreationTrait
- class \Drupal\Tests\contact\Kernel\MessageEntityTest
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses UserCreationTrait
Expanded class hierarchy of MessageEntityTest
See also
\Drupal\contact\Entity\Message
File
- core/
modules/ contact/ tests/ src/ Kernel/ MessageEntityTest.php, line 13
Namespace
Drupal\Tests\contact\KernelView source
class MessageEntityTest extends EntityKernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'system',
'contact',
'field',
'user',
'contact_test',
];
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'contact',
'contact_test',
]);
}
/**
* Tests some of the methods.
*/
public function testMessageMethods() {
$message_storage = $this->container
->get('entity_type.manager')
->getStorage('contact_message');
$message = $message_storage
->create([
'contact_form' => 'feedback',
]);
// Check for empty values first.
$this
->assertEquals('', $message
->getMessage());
$this
->assertEquals('', $message
->getSenderName());
$this
->assertEquals('', $message
->getSenderMail());
$this
->assertFalse($message
->copySender());
// Check for default values.
$this
->assertEquals('feedback', $message
->getContactForm()
->id());
$this
->assertFalse($message
->isPersonal());
// Set some values and check for them afterwards.
$message
->setMessage('welcome_message');
$message
->setSenderName('sender_name');
$message
->setSenderMail('sender_mail');
$message
->setCopySender(TRUE);
$this
->assertEquals('welcome_message', $message
->getMessage());
$this
->assertEquals('sender_name', $message
->getSenderName());
$this
->assertEquals('sender_mail', $message
->getSenderMail());
$this
->assertTrue($message
->copySender());
$no_access_user = $this
->createUser([
'uid' => 2,
]);
$access_user = $this
->createUser([
'uid' => 3,
], [
'access site-wide contact form',
]);
$admin = $this
->createUser([
'uid' => 4,
], [
'administer contact forms',
]);
$this
->assertFalse(\Drupal::entityTypeManager()
->getAccessControlHandler('contact_message')
->createAccess(NULL, $no_access_user));
$this
->assertTrue(\Drupal::entityTypeManager()
->getAccessControlHandler('contact_message')
->createAccess(NULL, $access_user));
$this
->assertTrue($message
->access('update', $admin));
$this
->assertFalse($message
->access('update', $access_user));
}
}