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