View source
<?php
namespace Drupal\yamlform\Tests;
use Drupal\yamlform\Entity\YamlForm;
class YamlFormHandlerEmailAdvancedTest extends YamlFormTestBase {
protected static $modules = [
'system',
'block',
'filter',
'node',
'user',
'file',
'yamlform',
'yamlform_test',
];
protected function createUsers() {
$this
->createFilters();
$this->normalUser = $this
->drupalCreateUser([
'access user profiles',
'access content',
$this->basicHtmlFilter
->getPermissionName(),
]);
$this->adminFormUser = $this
->drupalCreateUser([
'access user profiles',
'access content',
'administer yamlform',
'administer blocks',
'administer nodes',
'administer users',
$this->basicHtmlFilter
->getPermissionName(),
]);
$this->adminSubmissionUser = $this
->drupalCreateUser([
'access user profiles',
'access content',
'administer yamlform submission',
$this->basicHtmlFilter
->getPermissionName(),
]);
}
public function testAdvancedEmailHandler() {
$yamlform_email_advanced = YamlForm::load('test_handler_email_advanced');
$this
->drupalLogin($this->adminFormUser);
$edit = [
'first_name' => 'John',
'last_name' => 'Smith',
'email' => 'from@example.com',
'subject' => 'Subject',
'message[value]' => '<p><em>Please enter a message.</em> Test that double "quotes" are not encoded.</p>',
];
$this
->drupalPostForm('yamlform/' . $yamlform_email_advanced
->id() . '/test', $edit, t('Submit'));
$sid = $this
->getLastSubmissionId($yamlform_email_advanced);
$sent_mail = $this
->getLastEmail();
$this
->assertContains($sent_mail['params']['body'], '<b>First name</b><br/>John<br/><br/>');
$this
->assertContains($sent_mail['params']['body'], '<b>Last name</b><br/>Smith<br/><br/>');
$this
->assertContains($sent_mail['params']['body'], '<b>Email</b><br/><a href="mailto:from@example.com">from@example.com</a><br/><br/>');
$this
->assertContains($sent_mail['params']['body'], '<b>Subject</b><br/>Subject<br/><br/>');
$this
->assertContains($sent_mail['params']['body'], '<b>Message</b><br/><p><em>Please enter a message.</em> Test that double "quotes" are not encoded.</p><br/><br/>');
$this
->assertEqual($sent_mail['params']['attachments'][0]['filecontent'], "this is a sample txt file\nit has two lines\n");
$this
->assertEqual($sent_mail['params']['attachments'][0]['filename'], 'file.txt');
$this
->assertEqual($sent_mail['params']['attachments'][0]['filemime'], 'text/plain');
$this
->drupalGet("admin/structure/yamlform/manage/test_handler_email_advanced/submission/{$sid}/resend");
$this
->assertRaw('<span class="file file--mime-text-plain file--text">');
$this
->assertRaw('file.txt');
$this
->drupalPostForm("admin/structure/yamlform/manage/test_handler_email_advanced/submission/{$sid}/resend", [
'message[body]' => 'Testing 123...',
], t('Resend message'));
$sent_mail = $this
->getLastEmail();
$this
->assertNotContains($sent_mail['params']['body'], '<b>First name</b><br/>John<br/><br/>');
$this
->assertEqual($sent_mail['params']['body'], 'Testing 123...');
$this
->assertEqual($sent_mail['params']['attachments'][0]['filecontent'], "this is a sample txt file\nit has two lines\n");
$this
->assertEqual($sent_mail['params']['attachments'][0]['filename'], 'file.txt');
$this
->assertEqual($sent_mail['params']['attachments'][0]['filemime'], 'text/plain');
}
}