You are here

class CredentialTestCheckTest in CloudFlare 8

Tests that purge_requirements() passes on our diagnostic checks.

@group cloudflarepurger

Hierarchy

Expanded class hierarchy of CredentialTestCheckTest

File

modules/cloudflarepurger/tests/src/Unit/CredentialTestCheckTest.php, line 13

Namespace

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

  /**
   * Tests that CredentialTestCheck Responds as expected with test purge rates.
   *
   * @param int $cred_status
   *   The current API rate to test.
   * @param int $expected_severity
   *   The expected diagnostic severity.
   *
   * @dataProvider credentialCheckProvider
   *
   * @covers \Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheck\CredentialCheck
   */
  public function testCredentialTestCheck($cred_status, $expected_severity) {
    $config_factory = $this
      ->createMock('\\Drupal\\Core\\Config\\ConfigFactoryInterface');
    $config = $this
      ->getMockBuilder('Drupal\\Core\\Config\\Config')
      ->disableOriginalConstructor()
      ->getMock();
    $config
      ->expects($this
      ->atLeastOnce())
      ->method('get')
      ->with('valid_credentials')
      ->will($this
      ->returnValue($cred_status));
    $config_factory
      ->expects($this
      ->once())
      ->method('get')
      ->will($this
      ->returnValue($config));
    $credential_check = new CredentialCheck([], '23123', 'this is a definition', $config_factory);
    $actual_severity = $credential_check
      ->run();
    $this
      ->assertEquals($expected_severity, $actual_severity);
  }

  /**
   * PhpUnit provider to api rate limits.
   */
  public function credentialCheckProvider() {
    return [
      [
        NULL,
        DiagnosticCheckInterface::SEVERITY_ERROR,
      ],
      [
        TRUE,
        DiagnosticCheckInterface::SEVERITY_OK,
      ],
      [
        FALSE,
        DiagnosticCheckInterface::SEVERITY_ERROR,
      ],
      [
        0,
        DiagnosticCheckInterface::SEVERITY_ERROR,
      ],
      [
        1,
        DiagnosticCheckInterface::SEVERITY_OK,
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CredentialTestCheckTest::credentialCheckProvider public function PhpUnit provider to api rate limits.
CredentialTestCheckTest::testCredentialTestCheck public function Tests that CredentialTestCheck Responds as expected with test purge rates.
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.
DiagnosticCheckTestBase::setUp public function Overrides UnitTestCase::setUp 1
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.