You are here

public function SiteAlertTimeoutTest::testSiteAlertTimeoutsDisabled in Site Alert 8

Tests that automatic refreshing of site alerts can be disabled.

File

tests/src/FunctionalJavascript/SiteAlertTimeoutTest.php, line 105

Class

SiteAlertTimeoutTest
Tests refreshing site alerts at regular intervals by setting a timeout.

Namespace

Drupal\Tests\site_alert\FunctionalJavascript

Code

public function testSiteAlertTimeoutsDisabled() {

  // Place the Site Alerts block but disable the refreshing by setting the
  // timeout to 0.
  $this
    ->drupalPlaceBlock('site_alert_block', [
    'id' => 'site_alert_block',
    'timeout' => 0,
  ]);

  // There are no alerts yet. The block should not be present on the page.
  $this
    ->drupalGet('<front>');
  $this
    ->assertSiteAlertBlockNotPresent();

  // The JavaScript code to refresh the alerts should not be included.
  $this
    ->assertJavaScriptNotPresent();

  // Create an active and an inactive site alert.
  SiteAlert::create([
    'active' => TRUE,
    'severity' => 'low',
    'message' => [
      'value' => 'Active alert',
      'format' => 'plain_text',
    ],
    'label' => 'Active',
  ])
    ->save();
  SiteAlert::create([
    'active' => FALSE,
    'severity' => 'medium',
    'message' => [
      'value' => 'Inactive alert',
      'format' => 'plain_text',
    ],
    'label' => 'Inactive',
  ])
    ->save();

  // The alert should appear when we manually refresh the page.
  $this
    ->drupalGet('<front>');
  $this
    ->assertSiteAlertBlockPresent();
  $this
    ->assertSiteAlertVisible('Active alert');
  $this
    ->assertSiteAlertNotVisible('Inactive alert');
  $this
    ->assertSiteAlertCount(1);

  // The JavaScript code to refresh the alerts should still not be present.
  $this
    ->assertJavaScriptNotPresent();
}