function ContactStorageTest::testContactStorage
Same name in other branches
- 9 core/modules/contact/tests/src/Functional/ContactStorageTest.php \Drupal\Tests\contact\Functional\ContactStorageTest::testContactStorage()
- 10 core/modules/contact/tests/src/Functional/ContactStorageTest.php \Drupal\Tests\contact\Functional\ContactStorageTest::testContactStorage()
- 11.x core/modules/contact/tests/src/Functional/ContactStorageTest.php \Drupal\Tests\contact\Functional\ContactStorageTest::testContactStorage()
Tests configuration options and the site-wide contact form.
File
-
core/
modules/ contact/ tests/ src/ Functional/ ContactStorageTest.php, line 42
Class
- ContactStorageTest
- Tests storing contact messages.
Namespace
Drupal\Tests\contact\FunctionalCode
public function testContactStorage() {
// Create and log in administrative user.
$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);
// Create first valid contact form.
$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->assertText(t('Contact form @label has been added.', [
'@label' => $label,
]));
// Ensure that anonymous can submit site-wide contact form.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
'access site-wide contact form',
]);
$this->drupalLogout();
$this->drupalGet('contact');
$this->assertText(t('Your email address'));
$this->assertNoText(t('Form'));
$this->submitContact($name = $this->randomMachineName(16), $mail, $subject = $this->randomMachineName(16), $id, $message = $this->randomMachineName(64));
$this->assertText(t('Your message has been sent.'));
$messages = Message::loadMultiple();
/** @var \Drupal\contact\Entity\Message $message */
$message = reset($messages);
$this->assertEqual($message->getContactForm()
->id(), $id);
$this->assertTrue($message->getContactForm()
->getThirdPartySetting('contact_storage_test', 'send_a_pony', FALSE));
$this->assertEqual($message->getSenderName(), $name);
$this->assertEqual($message->getSubject(), $subject);
$this->assertEqual($message->getSenderMail(), $mail);
$config = $this->config("contact.form.{$id}");
$this->assertEqual($config->get('id'), $id);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.