3 namespace Drupal\Tests\contact\Functional;
5 use Drupal\contact\Entity\Message;
6 use Drupal\user\RoleInterface;
9 * Tests storing contact messages.
11 * Note that the various test methods in ContactSitewideTest are also run by
12 * this test. This is by design to ensure that regular contact.module functions
13 * continue to work when a storage handler other than ContentEntityNullStorage
14 * is enabled for contact Message entities.
18 class ContactStorageTest extends ContactSitewideTest {
25 public static $modules = [
30 'contact_storage_test',
35 * Tests configuration options and the site-wide contact form.
37 public function testContactStorage() {
38 // Create and log in administrative user.
39 $admin_user = $this->drupalCreateUser([
40 'access site-wide contact form',
41 'administer contact forms',
43 'administer account settings',
44 'administer contact_message fields',
46 $this->drupalLogin($admin_user);
47 // Create first valid contact form.
48 $mail = 'simpletest@example.com';
49 $this->addContactForm($id = mb_strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$mail]), '', TRUE, 'Your message has been sent.', [
52 $this->assertText(t('Contact form @label has been added.', ['@label' => $label]));
54 // Ensure that anonymous can submit site-wide contact form.
55 user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access site-wide contact form']);
56 $this->drupalLogout();
57 $this->drupalGet('contact');
58 $this->assertText(t('Your email address'));
59 $this->assertNoText(t('Form'));
60 $this->submitContact($name = $this->randomMachineName(16), $mail, $subject = $this->randomMachineName(16), $id, $message = $this->randomMachineName(64));
61 $this->assertText(t('Your message has been sent.'));
63 $messages = Message::loadMultiple();
64 /** @var \Drupal\contact\Entity\Message $message */
65 $message = reset($messages);
66 $this->assertEqual($message->getContactForm()->id(), $id);
67 $this->assertTrue($message->getContactForm()->getThirdPartySetting('contact_storage_test', 'send_a_pony', FALSE));
68 $this->assertEqual($message->getSenderName(), $name);
69 $this->assertEqual($message->getSubject(), $subject);
70 $this->assertEqual($message->getSenderMail(), $mail);
72 $config = $this->config("contact.form.$id");
73 $this->assertEqual($config->get('id'), $id);