EmailExampleTest.php in Examples for Developers 3.x
File
modules/email_example/tests/src/Functional/EmailExampleTest.php
View source
<?php
namespace Drupal\Tests\email_example\Functional;
use Drupal\Core\Test\AssertMailTrait;
use Drupal\Tests\examples\Functional\ExamplesBrowserTestBase;
class EmailExampleTest extends ExamplesBrowserTestBase {
use AssertMailTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'email_example',
];
protected $profile = 'minimal';
public function testEmailExampleBasic() {
$assert = $this
->assertSession();
$this
->drupalGet('');
$assert
->statusCodeEquals(200);
$assert
->linkByHrefExists('examples/email-example');
$this
->drupalGet('examples/email-example');
$assert
->statusCodeEquals(200);
$assert
->fieldValueEquals('edit-email', NULL);
$assert
->fieldValueEquals('edit-message', NULL);
$edit = [
'email' => 'example@example.com',
'message' => 'test',
];
$this
->drupalPostForm('examples/email-example', $edit, 'Submit');
$assert
->statusCodeEquals(200);
$assert
->pageTextContains('Your message has been sent.');
$this
->assertMailString('to', $edit['email'], 1);
$from = $this
->config('system.site')
->get('mail');
$this
->assertMailString('subject', "E-mail sent from {$from}", 1);
$this
->assertMailString('body', $edit['message'], 1);
$this
->assertMailString('body', "\n--\nMail altered by email_example module.", 1);
}
}