public function GetAlertsTest::testGetActiveAlerts in Site Alert 8
Tests the retrieval of active alerts.
@covers ::getActiveAlerts @dataProvider getActiveAlertsProvider
Parameters
array $alerts_to_create: An array of identifiers for the site alerts that should be created at the start of the test.
array $expected_alerts: An array of identifiers for the site alerts that are expected to be returned by the method under test.
File
- tests/src/ Kernel/ GetAlertsTest.php, line 72 
Class
- GetAlertsTest
- Tests retrieving of currently active alerts.
Namespace
Drupal\Tests\site_alert\KernelCode
public function testGetActiveAlerts(array $alerts_to_create, array $expected_alerts) {
  // Populate the database with the alerts as specified in the test case.
  $this
    ->createAlerts($alerts_to_create);
  // Retrieve the active alerts.
  $actual_alerts = $this->getAlerts
    ->getActiveAlerts();
  // Get the entity IDs of the actual and expected alerts so we can compare.
  $actual_alert_ids = array_keys($actual_alerts);
  $expected_alert_ids = array_map(function ($alert_id) {
    return $this->alerts[$alert_id]
      ->id();
  }, $expected_alerts);
  sort($actual_alert_ids);
  sort($expected_alert_ids);
  $this
    ->assertEquals($actual_alert_ids, $expected_alert_ids);
}