You are here

protected function SiteAlertTestTrait::assertAlert in Site Alert 8

Checks that the given site alert entity contains the given data.

Parameters

\Drupal\site_alert\Entity\SiteAlert $alert: The site alert entity to check.

string $label: The expected label.

string $message: The expected message.

string $severity: The expected severity.

bool $active: The expected status.

array $scheduling: The expected start and end time, or an empty array if the site alert is not scheduled.

3 calls to SiteAlertTestTrait::assertAlert()
CliCommandsTest::testCreateSiteAlert in tests/src/Kernel/CliCommandsTest.php
Test site alert creation with message and severity.
CliCommandsTest::testCreateSiteAlertWithOptions in tests/src/Kernel/CliCommandsTest.php
Test site alert creation with severity and scheduling options.
SiteAlertTestTrait::assertAlertByLabel in tests/src/Traits/SiteAlertTestTrait.php
Checks that the site alert with the given label contains the given data.

File

tests/src/Traits/SiteAlertTestTrait.php, line 32

Class

SiteAlertTestTrait
Helper methods for testing the Site Alert module.

Namespace

Drupal\Tests\site_alert\Traits

Code

protected function assertAlert(SiteAlert $alert, string $label, string $message, string $severity = 'medium', bool $active = TRUE, array $scheduling = [
  'start' => '',
  'end' => '',
]) : void {
  $this
    ->assertEquals($label, $alert
    ->label());
  $this
    ->assertEquals($message, $alert
    ->getMessage());
  $this
    ->assertEquals($severity, $alert
    ->getSeverity());
  $this
    ->assertEquals($active, (bool) $alert
    ->getActive());

  // Convert start and end times to the default time zone.
  foreach ([
    'start',
    'end',
  ] as $source) {
    $date =& $scheduling[$source];
    if (!empty($date)) {
      $date = (new DrupalDateTime($date, 'UTC'))
        ->format('Y-m-d H:i:s', [
        'timezone' => date_default_timezone_get(),
      ]);
    }
  }
  $this
    ->assertEquals($scheduling['start'], $alert
    ->getStartTime(), 'Start date is not as expected.');
  $this
    ->assertEquals($scheduling['end'], $alert
    ->getEndTime(), 'End date is not as expected.');
}