You are here

public function NotifyTest::testPsaMail in Automatic Updates 8

Tests sending PSA email notifications.

File

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

Class

NotifyTest
Tests notification emails for PSAs.

Namespace

Drupal\Tests\automatic_updates\Functional

Code

public function testPsaMail() {

  // Test PSAs on admin pages.
  $this
    ->drupalGet(Url::fromRoute('system.admin'));
  $this
    ->assertSession()
    ->pageTextContains('Critical Release - SA-2019-02-19');

  // Email should be sent.
  $notify = $this->container
    ->get('automatic_updates.psa_notify');
  $notify
    ->send();
  $this
    ->assertCount(1, $this
    ->getMails());
  $this
    ->assertMailString('subject', '3 urgent Drupal announcements require your attention', 1);
  $this
    ->assertMailString('body', 'Critical Release - SA-2019-02-19', 1);

  // No email should be sent if PSA's are disabled.
  $this->container
    ->get('state')
    ->set('system.test_mail_collector', []);
  $this->container
    ->get('state')
    ->delete('automatic_updates.last_check');
  $this
    ->config('automatic_updates.settings')
    ->set('enable_psa', FALSE)
    ->save();
  $notify
    ->send();
  $this
    ->assertCount(0, $this
    ->getMails());
}