You are here

public function WebformHandlerEmailRenderingTest::testEmailRendering in Webform 8.5

Same name and namespace in other branches
  1. 6.x tests/src/Functional/Handler/WebformHandlerEmailRenderingTest.php \Drupal\Tests\webform\Functional\Handler\WebformHandlerEmailRenderingTest::testEmailRendering()

Test email handler rendering.

File

tests/src/Functional/Handler/WebformHandlerEmailRenderingTest.php, line 36

Class

WebformHandlerEmailRenderingTest
Tests for email webform handler rendering functionality.

Namespace

Drupal\Tests\webform\Functional\Handler

Code

public function testEmailRendering() {
  $this
    ->drupalLogin($this->rootUser);

  /** @var \Drupal\webform\WebformInterface $webform */
  $webform = Webform::load('contact');

  // Check that we are currently using the bartik.theme.
  $this
    ->drupalGet('/webform/contact');
  $this
    ->assertRaw('core/themes/bartik/css/base/elements.css');

  // Post submission and send emails.
  $edit = [
    'name' => 'Dixisset',
    'email' => 'test@test.com',
    'subject' => 'Testing contact webform from [site:name]',
    'message' => 'Please ignore this email.',
  ];
  $this
    ->postSubmission($webform, $edit);

  // Check submitting contact form and sending emails using the
  // default bartik.theme.
  $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']);

  // Disable dedicated page which will cause the form to now use the
  // seven.theme.
  // @see \Drupal\webform\Theme\WebformThemeNegotiator
  $webform
    ->setSetting('page', FALSE);
  $webform
    ->save();

  // Check that we are now using the seven.theme.
  $this
    ->drupalGet('/webform/contact');
  $this
    ->assertNoRaw('core/themes/bartik/css/base/elements.css');

  // Post submission and send emails.
  $this
    ->postSubmission($webform, $edit);

  // Check submitting contact form and sending emails using the
  // seven.theme but the rendered the emails still use the default
  // bartik.theme.
  // @see \Drupal\webform\Plugin\WebformHandler\EmailWebformHandler::getMessage
  $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']);
}