You are here

public function CliCommandsTest::testCreateSiteAlertWithOptions in Site Alert 8

Test site alert creation with severity and scheduling options.

@covers ::create @dataProvider createSiteAlertWithOptionsProvider

Parameters

string|null $severity: Optional severity.

string|null $start: Optional start time.

string|null $end: Optional end time.

File

tests/src/Kernel/CliCommandsTest.php, line 74

Class

CliCommandsTest
Tests for the site alert CLI Commands service.

Namespace

Drupal\Tests\site_alert\Kernel

Code

public function testCreateSiteAlertWithOptions(?string $severity, ?string $start = NULL, ?string $end = NULL) : void {

  // Create a simple alert with a message, and a severity.
  $label = 'phpunit_test_create';
  $message = "A nice bit of message here.";
  $severity = 'low';
  $start = '2022-09-12T15:30:01';
  $end = '2022-09-13T15:45:01';
  $options = [
    'severity' => $severity,
    'start' => $start,
    'end' => $end,
  ];
  $this->cliCommands
    ->create($label, $message, $options);

  // Check that the created alert contains the expected data.
  $expected_severity = $severity ?? 'medium';
  $site_alert = $this
    ->loadAlertByLabel($label);
  $this
    ->assertAlert($site_alert, $label, $message, $expected_severity, TRUE, $options);
}