class DailyTagPurgeLimitCheckTest in CloudFlare 8
Tests that purge_requirements() passes on our diagnostic checks.
@group cloudflarepurger
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\cloudflarepurger\Unit\DiagnosticCheckTestBase
- class \Drupal\Tests\cloudflarepurger\Unit\DailyTagPurgeLimitCheckTest
- class \Drupal\Tests\cloudflarepurger\Unit\DiagnosticCheckTestBase
Expanded class hierarchy of DailyTagPurgeLimitCheckTest
File
- modules/
cloudflarepurger/ tests/ src/ Unit/ DailyTagPurgeLimitCheckTest.php, line 15
Namespace
Drupal\Tests\cloudflarepurger\UnitView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DailyTagPurgeLimitCheckTest:: |
public | function | Data provider for validating DailyTagPurgeLimitCheck. | |
DailyTagPurgeLimitCheckTest:: |
public | function |
Overrides DiagnosticCheckTestBase:: |
|
DailyTagPurgeLimitCheckTest:: |
public | function | Tests that DailyTagPurgeLimitCheck responds as expected. | |
DiagnosticCheckTestBase:: |
protected | property | Tracks rate limits associated with CloudFlare Api. | |
DiagnosticCheckTestBase:: |
protected | property | Provides check for composer dependencies. | |
DiagnosticCheckTestBase:: |
protected | property | The dependency injection container. | |
DiagnosticCheckTestBase:: |
protected | property | Tracks Drupal states. | |
DiagnosticCheckTestBase:: |
protected | property | Provides timestamps. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |