assertMailPattern example

    $captured_emails = $this->getMails();
    $this->assertCount(0, $captured_emails, 'The captured emails queue is empty.');

    // Send the email.     $mail_service->getInstance(['module' => 'simpletest', 'key' => 'drupal_mail_test'])->mail($message);

    // Ensure that there is one email in the captured emails array.     $captured_emails = $this->getMails();
    $this->assertCount(1, $captured_emails, 'One email was captured.');

    // Asserts that the message fields have the pattern in it.     $this->assertMailPattern('id', $message['id']);
    $this->assertMailPattern('subject', "^.{64}$");
    $this->assertMailPattern('to', "[a-z]{6}@example\.com$");
    $this->assertMailPattern('body', "^.{128}$");

    // Assert that the email was sent by iterating over the message properties     // and ensuring that they are captured intact.     foreach ($message as $field => $value) {
      $this->assertMail($field$value, "The email was sent and the value for property $field is intact.");
    }

    // Send additional emails so more than one email is captured.
Home | Imprint | This part of the site doesn't use cookies.