DrevOps\BehatSteps\Steps\Drupal\EmailTrait - Source, Example, Helpers
Test Drupal email functionality with content verification.
- Capture and examine outgoing emails with header and body validation.
- Follow links and test attachments within email content.
- Configure mail handler systems for proper test isolation.
Skip processing with tag:
@behat-steps-skip:EmailTrait.
Special tags:
@email:{type}- enable email tracking using a{type}handler@debug(enable detailed logs)
Prerequisites
| Prerequisite | Capability |
|---|---|
| A backend in the scenario's list provides "MailCapabilityInterface" | MailCapabilityInterface |
Options
| Option | Type | Default | Tag | Description |
|---|---|---|---|---|
email.enabled | boolean | TRUE | @behat-steps-skip:EmailTrait | Collect email for an @email scenario and clear the queue around it. |
Steps
@When the test email system queue is cleared
Clear test email system queue
When the test email system queue is cleared
@When I follow the link with the index :index in the email with the subject :subject
Follow the link at the 1-based index in an email with the given subject
When I follow the link with the index "1" in the email with the subject "Account Verification"
@When I follow the link with a URL containing :partial_url in the email
Follow the first link whose URL contains a fragment in an email
When I follow the link with a URL containing "user/reset" in the email
@When I follow the link with the index :index in the email with a subject containing :partial_subject
Follow the link at the 1-based index in an email whose subject contains the given substring
When I follow the link with the index "1" in the email with a subject containing "Verification"
@When the test email system is enabled
Enable the test email system
When the test email system is enabled
@When the test email system is disabled
Disable test email system
When the test email system is disabled
@Then an email should have been sent to the address :address
Assert that an email was sent to an address
Then an email should have been sent to the address "user@example.com"
@Then the number of emails sent should be :count
Assert the number of emails sent
Then the number of emails sent should be 2
@Then the number of emails sent to the address :address should be :count
Assert the number of emails sent to an address
Then the number of emails sent to the address "user@example.com" should be 2
@Then the number of emails sent with the subject :subject should be :count
Assert the number of emails sent with a subject
Then the number of emails sent with the subject "Welcome" should be 1
@Then no emails should have been sent
Assert that no email was sent
Then no emails should have been sent
@Then no emails should have been sent to the address :address
Assert that no email was sent to an address
Then no emails should have been sent to the address "user@example.com"
@Then the email header :header should contain:
Assert that the email message header should contain specified content
Then the email header "Subject" should contain:
"""
Account details
"""
@Then the email header :header should be:
Assert that the email message header should be the exact specified content
Then the email header "Subject" should be:
"""
Your Account Details
"""
@Then an email should have been sent to the address :address with the content:
Assert that an email was sent to an address with the exact content in the body
Then an email should have been sent to the address "user@example.com" with the content:
"""
Welcome to our site!
Click the link below to verify your account.
"""
@Then an email should have been sent to the address :address with the content containing:
Assert that an email was sent to an address with the body containing specific content
Then an email should have been sent to the address "user@example.com" with the content containing:
"""
verification link
"""
@Then an email should have been sent to the address :address with the content not containing:
Assert that an email was sent to an address with the body not containing specific content
Then an email should have been sent to the address "user@example.com" with the content not containing:
"""
password
"""
@Then no emails should have been sent to the address :address with the content:
Assert that no email was sent to an address with the exact content in the body
Then no emails should have been sent to the address "wrong@example.com" with the content:
"""
Welcome to our site!
"""
@Then no emails should have been sent to the address :address with the content containing:
Assert that no email was sent to an address with the body containing specific content
Then no emails should have been sent to the address "wrong@example.com" with the content containing:
"""
verification link
"""
@Then the email field :field should contain:
Assert that the email field should contain a value
Then the email field "body" should contain:
"""
Please verify your account
"""
@Then the email field :field should be:
Assert that the email field should exactly match a value
Then the email field "subject" should be:
"""
Account Verification
"""
@Then the email field :field should not contain:
Assert that the email field should not contain a value
Then the email field "body" should not contain:
"""
password
"""
@Then the email field :field should not be:
Assert that the email field should not exactly match a value
Then the email field "subject" should not be:
"""
Password Reset
"""
@Then the file :filename should be attached to the email with the subject :subject
Assert that a file is attached to an email message with specified subject
Then the file "document.pdf" should be attached to the email with the subject "Your document"
@Then the file :filename should be attached to the email with a subject containing :partial_subject
Assert that a file is attached to an email message with a subject containing the specified substring
Then the file "report.xlsx" should be attached to the email with a subject containing "Monthly Report"