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