You are here

class DailyTagPurgeLimitCheckTest in CloudFlare 8

Tests that purge_requirements() passes on our diagnostic checks.

@group cloudflarepurger

Hierarchy

Expanded class hierarchy of DailyTagPurgeLimitCheckTest

File

modules/cloudflarepurger/tests/src/Unit/DailyTagPurgeLimitCheckTest.php, line 15

Namespace

Drupal\Tests\cloudflarepurger\Unit
View source
class DailyTagPurgeLimitCheckTest extends DiagnosticCheckTestBase {

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    $this->container = new ContainerBuilder();
    $this->container
      ->set('string_translation', $this
      ->getStringTranslationStub());
    \Drupal::setContainer($this->container);
  }

  /**
   * Tests that DailyTagPurgeLimitCheck responds as expected.
   *
   * @param int $api_rate
   *   The currentAPI rate to test.
   * @param int $expected_severity
   *   The expected diagnostic severity.
   *
   * @dataProvider dailyTagPurgeLimitCheckProvider
   */
  public function testDailyTagPurgeLimitCheck($api_rate, $expected_severity) {
    $this->drupalState
      ->set(State::TAG_PURGE_DAILY_COUNT, $api_rate);
    $this->drupalState
      ->set(State::TAG_PURGE_DAILY_COUNT_START, new \DateTime());
    $api_rate_limit_check = new DailyTagPurgeLimitCheck([], '23123', 'this is a definition', $this->cloudflareState, $this->composerDependencyStub);
    $actual_severity = $api_rate_limit_check
      ->run();
    $this
      ->assertEquals($expected_severity, $actual_severity);
  }

  /**
   * Data provider for validating DailyTagPurgeLimitCheck.
   *
   * @return array[]
   *   Returns per data set an array with:
   *     - count of daily tag purge requests
   *     - expected status returned by diagnostic check
   */
  public function dailyTagPurgeLimitCheckProvider() {
    return [
      [
        NULL,
        DiagnosticCheckInterface::SEVERITY_OK,
      ],
      [
        0,
        DiagnosticCheckInterface::SEVERITY_OK,
      ],
      [
        1,
        DiagnosticCheckInterface::SEVERITY_OK,
      ],
      [
        1499,
        DiagnosticCheckInterface::SEVERITY_OK,
      ],
      [
        1500,
        DiagnosticCheckInterface::SEVERITY_WARNING,
      ],
      [
        1501,
        DiagnosticCheckInterface::SEVERITY_WARNING,
      ],
      [
        1502,
        DiagnosticCheckInterface::SEVERITY_WARNING,
      ],
      [
        1999,
        DiagnosticCheckInterface::SEVERITY_WARNING,
      ],
      [
        2000,
        DiagnosticCheckInterface::SEVERITY_ERROR,
      ],
      [
        2001,
        DiagnosticCheckInterface::SEVERITY_ERROR,
      ],
      [
        2002,
        DiagnosticCheckInterface::SEVERITY_ERROR,
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DailyTagPurgeLimitCheckTest::dailyTagPurgeLimitCheckProvider public function Data provider for validating DailyTagPurgeLimitCheck.
DailyTagPurgeLimitCheckTest::setUp public function Overrides DiagnosticCheckTestBase::setUp
DailyTagPurgeLimitCheckTest::testDailyTagPurgeLimitCheck public function Tests that DailyTagPurgeLimitCheck responds as expected.
DiagnosticCheckTestBase::$cloudflareState protected property Tracks rate limits associated with CloudFlare Api.
DiagnosticCheckTestBase::$composerDependencyStub protected property Provides check for composer dependencies.
DiagnosticCheckTestBase::$container protected property The dependency injection container.
DiagnosticCheckTestBase::$drupalState protected property Tracks Drupal states.
DiagnosticCheckTestBase::$timestampStub protected property Provides timestamps.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.