View source
<?php
namespace Drupal\Tests\contact\Functional;
use Drupal\contact\Entity\Message;
use Drupal\user\RoleInterface;
class ContactStorageTest extends ContactSitewideTest {
protected static $modules = [
'block',
'text',
'contact',
'field_ui',
'contact_storage_test',
'contact_test',
];
protected $defaultTheme = 'stark';
public function testContactStorage() {
$admin_user = $this
->drupalCreateUser([
'access site-wide contact form',
'administer contact forms',
'administer users',
'administer account settings',
'administer contact_message fields',
]);
$this
->drupalLogin($admin_user);
$mail = 'simpletest@example.com';
$this
->addContactForm($id = mb_strtolower($this
->randomMachineName(16)), $label = $this
->randomMachineName(16), implode(',', [
$mail,
]), '', TRUE, 'Your message has been sent.', [
'send_a_pony' => 1,
]);
$this
->assertSession()
->pageTextContains('Contact form ' . $label . ' has been added.');
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
'access site-wide contact form',
]);
$this
->drupalLogout();
$this
->drupalGet('contact');
$this
->assertSession()
->pageTextContains('Your email address');
$this
->assertSession()
->pageTextNotContains('Form');
$this
->submitContact($name = $this
->randomMachineName(16), $mail, $subject = $this
->randomMachineName(16), $id, $message = $this
->randomMachineName(64));
$this
->assertSession()
->pageTextContains('Your message has been sent.');
$messages = Message::loadMultiple();
$message = reset($messages);
$this
->assertEquals($id, $message
->getContactForm()
->id());
$this
->assertTrue($message
->getContactForm()
->getThirdPartySetting('contact_storage_test', 'send_a_pony', FALSE));
$this
->assertEquals($name, $message
->getSenderName());
$this
->assertEquals($subject, $message
->getSubject());
$this
->assertEquals($mail, $message
->getSenderMail());
$config = $this
->config("contact.form.{$id}");
$this
->assertEquals($id, $config
->get('id'));
}
}