WebformHandlerEmailRolesTest.php in Webform 8.5
File
tests/src/Functional/Handler/WebformHandlerEmailRolesTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Handler;
use Drupal\webform\Entity\Webform;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
class WebformHandlerEmailRolesTest extends WebformBrowserTestBase {
protected static $testWebforms = [
'test_handler_email_roles',
];
public function testEmailRoles() {
\Drupal::configFactory()
->getEditable('webform.settings')
->set('mail.roles', [
'authenticated',
])
->save();
$this
->drupalCreateRole([], 'administrator');
$webform = Webform::load('test_handler_email_roles');
$authenticated_user = $this
->drupalCreateUser();
$authenticated_user
->set('mail', 'authenticated@example.com');
$authenticated_user
->save();
$blocked_user = $this
->drupalCreateUser();
$blocked_user
->set('mail', 'blocked@example.com');
$blocked_user
->block();
$blocked_user
->save();
$admin_user = $this
->drupalCreateUser();
$admin_user
->set('mail', 'administrator@example.com');
$admin_user
->addRole('administrator');
$admin_user
->save();
$this
->postSubmission($webform, [
'role' => 'authenticated',
]);
$this
->assertRaw('<em class="placeholder">Webform submission from: Test: Handler: Email roles</em> sent to <em class="placeholder">admin@example.com,administrator@example.com,authenticated@example.com</em> from <em class="placeholder">Drupal</em> [<em class="placeholder">simpletest@example.com</em>].');
$this
->assertNoRaw('blocked@example.com');
$blocked_user
->activate()
->save();
$this
->postSubmission($webform, [
'role' => 'authenticated',
]);
$this
->assertRaw('blocked@example.com');
$this
->postSubmission($webform, [
'role' => 'administrator',
]);
$this
->assertRaw('<em class="placeholder">Webform submission from: Test: Handler: Email roles</em> sent to <em class="placeholder">administrator@example.com</em> from <em class="placeholder">Drupal</em> [<em class="placeholder">simpletest@example.com</em>].');
$this
->postSubmission($webform, [
'role' => 'other',
]);
$this
->assertRaw('<em class="placeholder">Test: Handler: Email roles</em>: Email not sent for <em class="placeholder">Email</em> handler because a <em>To</em>, <em>CC</em>, or <em>BCC</em> email was not provided.');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('mail.roles', [
'administrator',
])
->save();
$this
->postSubmission($webform, [
'role' => 'authenticated',
]);
$this
->assertRaw('<em class="placeholder">Test: Handler: Email roles</em>: Email not sent for <em class="placeholder">Email</em> handler because a <em>To</em>, <em>CC</em>, or <em>BCC</em> email was not provided.');
}
}