comparison core/modules/contact/tests/src/Functional/ContactSitewideTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php 1 <?php
2 2
3 namespace Drupal\Tests\contact\Functional; 3 namespace Drupal\Tests\contact\Functional;
4 4
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\contact\Entity\ContactForm; 5 use Drupal\contact\Entity\ContactForm;
7 use Drupal\Core\Mail\MailFormatHelper; 6 use Drupal\Core\Mail\MailFormatHelper;
8 use Drupal\Core\Test\AssertMailTrait; 7 use Drupal\Core\Test\AssertMailTrait;
9 use Drupal\field_ui\Tests\FieldUiTestTrait;
10 use Drupal\Tests\BrowserTestBase; 8 use Drupal\Tests\BrowserTestBase;
11 use Drupal\Core\Entity\EntityTypeInterface; 9 use Drupal\Core\Entity\EntityTypeInterface;
10 use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
12 use Drupal\user\RoleInterface; 11 use Drupal\user\RoleInterface;
13 12
14 /** 13 /**
15 * Tests site-wide contact form functionality. 14 * Tests site-wide contact form functionality.
16 * 15 *
99 // User form could not be changed or deleted. 98 // User form could not be changed or deleted.
100 // Cannot use ::assertNoLinkByHref as it does partial url matching and with 99 // Cannot use ::assertNoLinkByHref as it does partial url matching and with
101 // field_ui enabled admin/structure/contact/manage/personal/fields exists. 100 // field_ui enabled admin/structure/contact/manage/personal/fields exists.
102 // @todo: See https://www.drupal.org/node/2031223 for the above. 101 // @todo: See https://www.drupal.org/node/2031223 for the above.
103 $edit_link = $this->xpath('//a[@href=:href]', [ 102 $edit_link = $this->xpath('//a[@href=:href]', [
104 ':href' => \Drupal::url('entity.contact_form.edit_form', ['contact_form' => 'personal']) 103 ':href' => \Drupal::url('entity.contact_form.edit_form', ['contact_form' => 'personal']),
105 ]); 104 ]);
106 $this->assertTrue(empty($edit_link), format_string('No link containing href %href found.', 105 $this->assertTrue(empty($edit_link), format_string('No link containing href %href found.',
107 ['%href' => 'admin/structure/contact/manage/personal'] 106 ['%href' => 'admin/structure/contact/manage/personal']
108 )); 107 ));
109 $this->assertNoLinkByHref('admin/structure/contact/manage/personal/delete'); 108 $this->assertNoLinkByHref('admin/structure/contact/manage/personal/delete');
147 146
148 // Test validation of max_length machine name. 147 // Test validation of max_length machine name.
149 $recipients = ['simpletest&@example.com', 'simpletest2@example.com', 'simpletest3@example.com']; 148 $recipients = ['simpletest&@example.com', 'simpletest2@example.com', 'simpletest3@example.com'];
150 $max_length = EntityTypeInterface::BUNDLE_MAX_LENGTH; 149 $max_length = EntityTypeInterface::BUNDLE_MAX_LENGTH;
151 $max_length_exceeded = $max_length + 1; 150 $max_length_exceeded = $max_length + 1;
152 $this->addContactForm($id = Unicode::strtolower($this->randomMachineName($max_length_exceeded)), $label = $this->randomMachineName($max_length_exceeded), implode(',', [$recipients[0]]), '', TRUE); 151 $this->addContactForm($id = mb_strtolower($this->randomMachineName($max_length_exceeded)), $label = $this->randomMachineName($max_length_exceeded), implode(',', [$recipients[0]]), '', TRUE);
153 $this->assertText(format_string('Machine-readable name cannot be longer than @max characters but is currently @exceeded characters long.', ['@max' => $max_length, '@exceeded' => $max_length_exceeded])); 152 $this->assertText(format_string('Machine-readable name cannot be longer than @max characters but is currently @exceeded characters long.', ['@max' => $max_length, '@exceeded' => $max_length_exceeded]));
154 $this->addContactForm($id = Unicode::strtolower($this->randomMachineName($max_length)), $label = $this->randomMachineName($max_length), implode(',', [$recipients[0]]), '', TRUE); 153 $this->addContactForm($id = mb_strtolower($this->randomMachineName($max_length)), $label = $this->randomMachineName($max_length), implode(',', [$recipients[0]]), '', TRUE);
155 $this->assertText(t('Contact form @label has been added.', ['@label' => $label])); 154 $this->assertText(t('Contact form @label has been added.', ['@label' => $label]));
156 155
157 // Verify that the creation message contains a link to a contact form. 156 // Verify that the creation message contains a link to a contact form.
158 $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'contact/']); 157 $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'contact/']);
159 $this->assert(isset($view_link), 'The message area contains a link to a contact form.'); 158 $this->assert(isset($view_link), 'The message area contains a link to a contact form.');
160 159
161 // Create first valid form. 160 // Create first valid form.
162 $this->addContactForm($id = Unicode::strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$recipients[0]]), '', TRUE); 161 $this->addContactForm($id = mb_strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$recipients[0]]), '', TRUE);
163 $this->assertText(t('Contact form @label has been added.', ['@label' => $label])); 162 $this->assertText(t('Contact form @label has been added.', ['@label' => $label]));
164 163
165 // Verify that the creation message contains a link to a contact form. 164 // Verify that the creation message contains a link to a contact form.
166 $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'contact/']); 165 $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'contact/']);
167 $this->assert(isset($view_link), 'The message area contains a link to a contact form.'); 166 $this->assert(isset($view_link), 'The message area contains a link to a contact form.');
200 $this->assertText(t('Your email address')); 199 $this->assertText(t('Your email address'));
201 $this->assertNoText(t('Form')); 200 $this->assertNoText(t('Form'));
202 $this->drupalLogin($admin_user); 201 $this->drupalLogin($admin_user);
203 202
204 // Add more forms. 203 // Add more forms.
205 $this->addContactForm(Unicode::strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$recipients[0], $recipients[1]]), '', FALSE); 204 $this->addContactForm(mb_strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$recipients[0], $recipients[1]]), '', FALSE);
206 $this->assertText(t('Contact form @label has been added.', ['@label' => $label])); 205 $this->assertText(t('Contact form @label has been added.', ['@label' => $label]));
207 206
208 $this->addContactForm($name = Unicode::strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$recipients[0], $recipients[1], $recipients[2]]), '', FALSE); 207 $this->addContactForm($name = mb_strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$recipients[0], $recipients[1], $recipients[2]]), '', FALSE);
209 $this->assertText(t('Contact form @label has been added.', ['@label' => $label])); 208 $this->assertText(t('Contact form @label has been added.', ['@label' => $label]));
210 209
211 // Try adding a form that already exists. 210 // Try adding a form that already exists.
212 $this->addContactForm($name, $label, '', '', FALSE); 211 $this->addContactForm($name, $label, '', '', FALSE);
213 $this->assertNoText(t('Contact form @label has been added.', ['@label' => $label])); 212 $this->assertNoText(t('Contact form @label has been added.', ['@label' => $label]));
268 267
269 $this->deleteContactForms(); 268 $this->deleteContactForms();
270 269
271 $label = $this->randomMachineName(16); 270 $label = $this->randomMachineName(16);
272 $recipients = implode(',', [$recipients[0], $recipients[1], $recipients[2]]); 271 $recipients = implode(',', [$recipients[0], $recipients[1], $recipients[2]]);
273 $contact_form = Unicode::strtolower($this->randomMachineName(16)); 272 $contact_form = mb_strtolower($this->randomMachineName(16));
274 $this->addContactForm($contact_form, $label, $recipients, '', FALSE); 273 $this->addContactForm($contact_form, $label, $recipients, '', FALSE);
275 $this->drupalGet('admin/structure/contact'); 274 $this->drupalGet('admin/structure/contact');
276 $this->clickLink(t('Edit')); 275 $this->clickLink(t('Edit'));
277 $this->assertResponse(200); 276 $this->assertResponse(200);
278 $this->assertFieldByName('label', $label); 277 $this->assertFieldByName('label', $label);
298 $this->assertResponse(200); 297 $this->assertResponse(200);
299 $this->clickLink(t('Add field')); 298 $this->clickLink(t('Add field'));
300 $this->assertResponse(200); 299 $this->assertResponse(200);
301 300
302 // Create a simple textfield. 301 // Create a simple textfield.
303 $field_name = Unicode::strtolower($this->randomMachineName()); 302 $field_name = mb_strtolower($this->randomMachineName());
304 $field_label = $this->randomMachineName(); 303 $field_label = $this->randomMachineName();
305 $this->fieldUIAddNewField(NULL, $field_name, $field_label, 'text'); 304 $this->fieldUIAddNewField(NULL, $field_name, $field_label, 'text');
306 $field_name = 'field_' . $field_name; 305 $field_name = 'field_' . $field_name;
307 306
308 // Check preview field can be ordered. 307 // Check preview field can be ordered.
404 $admin_user = $this->drupalCreateUser([ 403 $admin_user = $this->drupalCreateUser([
405 'access site-wide contact form', 404 'access site-wide contact form',
406 'administer contact forms', 405 'administer contact forms',
407 'administer permissions', 406 'administer permissions',
408 'administer users', 407 'administer users',
409 'access site reports' 408 'access site reports',
410 ]); 409 ]);
411 $this->drupalLogin($admin_user); 410 $this->drupalLogin($admin_user);
412 411
413 // Set up three forms, 2 with an auto-reply and one without. 412 // Set up three forms, 2 with an auto-reply and one without.
414 $foo_autoreply = $this->randomMachineName(40); 413 $foo_autoreply = $this->randomMachineName(40);