You are here

public function CliCommandsTest::testDisableSiteAlertByLabel in Site Alert 8

Checks that a site alert can be disabled by passing the label.

@covers ::disable

File

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

Class

CliCommandsTest
Tests for the site alert CLI Commands service.

Namespace

Drupal\Tests\site_alert\Kernel

Code

public function testDisableSiteAlertByLabel() : void {

  // Create an active alert.
  $label = 'phpunit_test_disable';
  $message = 'This alert is active, for now.';
  $this->cliCommands
    ->create($label, $message, []);

  // There should be 1 active alert.
  $this
    ->assertActiveAlertCount(1);

  // Disable the alert. This should return the number of alerts that were
  // disabled.
  $count = $this->cliCommands
    ->disable('phpunit_test_disable');
  $this
    ->assertEquals(1, $count);
  $this
    ->assertActiveAlertCount(0);

  // Try to disable the alert again. This should throw an exception indicating
  // that no alerts were disabled.
  $this
    ->expectException(\InvalidArgumentException::class);
  $this
    ->expectExceptionMessage("No active site alerts found with the label 'phpunit_test_disable'.");
  $this->cliCommands
    ->disable('phpunit_test_disable');
}