WebformHandlerEmailRenderingTest.php in Webform 8.5
File
tests/src/Functional/Handler/WebformHandlerEmailRenderingTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Handler;
use Drupal\Core\Test\AssertMailTrait;
use Drupal\webform\Entity\Webform;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
class WebformHandlerEmailRenderingTest extends WebformBrowserTestBase {
use AssertMailTrait;
protected function setUp() {
parent::setUp();
\Drupal::service('theme_installer')
->install([
'webform_test_bartik',
'seven',
]);
$this
->config('system.theme')
->set('default', 'webform_test_bartik')
->set('admin', 'seven')
->save();
}
public function testEmailRendering() {
$this
->drupalLogin($this->rootUser);
$webform = Webform::load('contact');
$this
->drupalGet('/webform/contact');
$this
->assertRaw('core/themes/bartik/css/base/elements.css');
$edit = [
'name' => 'Dixisset',
'email' => 'test@test.com',
'subject' => 'Testing contact webform from [site:name]',
'message' => 'Please ignore this email.',
];
$this
->postSubmission($webform, $edit);
$sent_emails = $this
->getMails();
$this
->assertStringContainsStringIgnoringCase('HEADER 1 (CONTACT_EMAIL_CONFIRMATION)', $sent_emails[0]['body']);
$this
->assertStringContainsString('Please ignore this email.', $sent_emails[0]['body']);
$this
->assertStringContainsString('address (contact_email_confirmation)', $sent_emails[0]['body']);
$this
->assertStringContainsStringIgnoringCase('HEADER 1 (GLOBAL)', $sent_emails[1]['body']);
$this
->assertStringContainsString('Please ignore this email.', $sent_emails[1]['body']);
$this
->assertStringContainsString('address (global)', $sent_emails[1]['body']);
$webform
->setSetting('page', FALSE);
$webform
->save();
$this
->drupalGet('/webform/contact');
$this
->assertNoRaw('core/themes/bartik/css/base/elements.css');
$this
->postSubmission($webform, $edit);
$sent_emails = $this
->getMails();
$this
->assertStringContainsStringIgnoringCase('HEADER 1 (CONTACT_EMAIL_CONFIRMATION)', $sent_emails[2]['body']);
$this
->assertStringContainsString('Please ignore this email.', $sent_emails[2]['body']);
$this
->assertStringContainsString('address (contact_email_confirmation)', $sent_emails[2]['body']);
$this
->assertStringContainsStringIgnoringCase('HEADER 1 (GLOBAL)', $sent_emails[3]['body']);
$this
->assertStringContainsString('Please ignore this email.', $sent_emails[3]['body']);
$this
->assertStringContainsString('address (global)', $sent_emails[3]['body']);
}
}