fbd938bb8a55d1e347bc3af6862174163a17aaa9
[yaffs-website] / web / core / modules / contact / tests / src / Functional / ContactStorageTest.php
1 <?php
2
3 namespace Drupal\Tests\contact\Functional;
4
5 use Drupal\contact\Entity\Message;
6 use Drupal\user\RoleInterface;
7
8 /**
9  * Tests storing contact messages.
10  *
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.
15  *
16  * @group contact
17  */
18 class ContactStorageTest extends ContactSitewideTest {
19
20   /**
21    * Modules to enable.
22    *
23    * @var array
24    */
25   public static $modules = [
26     'block',
27     'text',
28     'contact',
29     'field_ui',
30     'contact_storage_test',
31     'contact_test',
32   ];
33
34   /**
35    * Tests configuration options and the site-wide contact form.
36    */
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',
42       'administer users',
43       'administer account settings',
44       'administer contact_message fields',
45     ]);
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.', [
50       'send_a_pony' => 1,
51     ]);
52     $this->assertText(t('Contact form @label has been added.', ['@label' => $label]));
53
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.'));
62
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);
71
72     $config = $this->config("contact.form.$id");
73     $this->assertEqual($config->get('id'), $id);
74   }
75
76 }