You are here

public function SiteAlertStorageTest::testGetMaxAge in Site Alert 8

Tests the retrieval of the cache max age.

@covers ::getCacheMaxAge @dataProvider getCacheMaxAgeProvider

Parameters

array $alerts_to_create: An array of identifiers for the site alerts that should be created at the start of the test.

int $expected_max_age: The max age that is expected to be returned by the method under test.

File

tests/src/Kernel/SiteAlertStorageTest.php, line 43

Class

SiteAlertStorageTest
Tests for the site alert entity storage handler.

Namespace

Drupal\Tests\site_alert\Kernel

Code

public function testGetMaxAge(array $alerts_to_create, int $expected_max_age) {

  // Populate the database with the alerts as specified in the test case.
  $this
    ->createAlerts($alerts_to_create);

  // Retrieve the cache max age.
  $actual_max_age = $this->siteAlertStorage
    ->getCacheMaxAge();

  // Because of possible delays incurred during the setup of the test we allow
  // for a grace period of a few seconds, except in the case where the cache
  // is expected to be permanent.
  if ($expected_max_age === CacheBackendInterface::CACHE_PERMANENT) {
    $this
      ->assertEquals($expected_max_age, $actual_max_age);
  }
  else {
    $this
      ->assertTrue(abs($expected_max_age - $actual_max_age) < 2);
  }
}