function EmailExampleTest::testEmailExampleBasic

Same name in other branches
  1. 4.0.x modules/email_example/tests/src/Functional/EmailExampleTest.php \Drupal\Tests\email_example\Functional\EmailExampleTest::testEmailExampleBasic()

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.

File

modules/email_example/tests/src/Functional/EmailExampleTest.php, line 47

Class

EmailExampleTest
Tests for the email_example module.

Namespace

Drupal\Tests\email_example\Functional

Code

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->fieldExists('edit-email');
    $assert->fieldExists('edit-message');
    // Verifiy email form is submitted.
    $edit = [
        'email' => 'example@example.com',
        'message' => 'test',
    ];
    $this->drupalGet('examples/email-example');
    $this->submitForm($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);
}