class EmailExampleTest
Same name in other branches
- 3.x modules/email_example/tests/src/Functional/EmailExampleTest.php \Drupal\Tests\email_example\Functional\EmailExampleTest
- 4.0.x modules/email_example/tests/src/Functional/EmailExampleTest.php \Drupal\Tests\email_example\Functional\EmailExampleTest
Tests for the email_example module.
@group email_example @group examples
Hierarchy
- class \Drupal\Tests\examples\Functional\ExamplesBrowserTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\email_example\Functional\EmailExampleTest extends \Drupal\Tests\examples\Functional\ExamplesBrowserTestBase uses \Drupal\Core\Test\AssertMailTrait
Expanded class hierarchy of EmailExampleTest
Related topics
File
-
email_example/
tests/ src/ Functional/ EmailExampleTest.php, line 16
Namespace
Drupal\Tests\email_example\FunctionalView source
class EmailExampleTest extends ExamplesBrowserTestBase {
use AssertMailTrait;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'email_example',
];
/**
* The installation profile to use with this test.
*
* @var string
*/
protected $profile = 'minimal';
/**
* Test our new email form.
*
* Tests for the following:
*
* - A link to the email_example in the Tools menu.
* - That you can successfully access the email_example page.
*/
public function testEmailExampleBasic() {
$assert = $this->assertSession();
// Test for a link to the email_example in the Tools menu.
$this->drupalGet('');
$assert->statusCodeEquals(200);
$assert->linkByHrefExists('examples/email-example');
// Verify if we can successfully access the email_example page.
$this->drupalGet('examples/email-example');
$assert->statusCodeEquals(200);
// Verifiy email form has email & message fields.
$assert->fieldValueEquals('edit-email', NULL);
$assert->fieldValueEquals('edit-message', NULL);
// Verifiy email form is submitted.
$edit = [
'email' => 'example@example.com',
'message' => 'test',
];
$this->drupalPostForm('examples/email-example', $edit, 'Submit');
$assert->statusCodeEquals(200);
// Verifiy comfirmation page.
$assert->pageTextContains('Your message has been sent.');
$this->assertMailString('to', $edit['email'], 1);
// Verifiy correct email recieved.
$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);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
EmailExampleTest::$defaultTheme | protected | property | |||
EmailExampleTest::$modules | public static | property | Modules to enable. | Overrides ExamplesBrowserTestBase::$modules | |
EmailExampleTest::$profile | protected | property | The installation profile to use with this test. | ||
EmailExampleTest::testEmailExampleBasic | public | function | Test our new email form. | ||
ExamplesBrowserTestBase::setUp | protected | function | 4 | ||
ExamplesBrowserTestBase::setupExamplesMenus | protected | function | Set up menus and tasks in their regions. |