You are here

public function NotifyTest::testPostUpdateMail in Automatic Updates 8

Tests sending post update email notifications.

File

tests/src/Functional/NotifyTest.php, line 92

Class

NotifyTest
Tests notification emails for PSAs.

Namespace

Drupal\Tests\automatic_updates\Functional

Code

public function testPostUpdateMail() {

  // Success email.
  $metadata = new UpdateMetadata('drupal', 'core', '8.7.0', '8.8.0');
  $post_update = new PostUpdateEvent($metadata, TRUE);
  $notify = $this->container
    ->get('automatic_updates.post_update_subscriber');
  $notify
    ->onPostUpdate($post_update);
  $this
    ->assertCount(1, $this
    ->getMails());
  $this
    ->assertMailString('subject', 'Automatic update of "drupal" succeeded', 1);
  $this
    ->assertMailString('body', 'The project "drupal" was updated from "8.7.0" to "8.8.0" with success.', 1);

  // Failure email.
  $this->container
    ->get('state')
    ->set('system.test_mail_collector', []);
  $post_update = new PostUpdateEvent($metadata, FALSE);
  $notify = $this->container
    ->get('automatic_updates.post_update_subscriber');
  $notify
    ->onPostUpdate($post_update);
  $this
    ->assertCount(1, $this
    ->getMails());
  $this
    ->assertMailString('subject', 'Automatic update of "drupal" failed', 1);
  $this
    ->assertMailString('body', 'The project "drupal" was updated from "8.7.0" to "8.8.0" with failures.', 1);
}