You are here

public function CliCommandsTest::testEnableSiteAlertByLabel in Site Alert 8

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

@covers ::enable

File

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

Class

CliCommandsTest
Tests for the site alert CLI Commands service.

Namespace

Drupal\Tests\site_alert\Kernel

Code

public function testEnableSiteAlertByLabel() : void {

  // Create an inactive alert.
  $label = 'phpunit_test_enable';
  $message = 'This alert is not yet active.';
  $this->cliCommands
    ->create($label, $message, [
    'active' => FALSE,
  ]);

  // There should be 1 inactive alert.
  $this
    ->assertInactiveAlertCount(1);

  // Enable the alert. This should return the number of alerts that were
  // enabled.
  $count = $this->cliCommands
    ->enable('phpunit_test_enable');
  $this
    ->assertEquals(1, $count);
  $this
    ->assertActiveAlertCount(1);
  $this
    ->assertInactiveAlertCount(0);

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