You are here

class Fast404Test in Fast 404 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/Fast404Test.php \Drupal\Tests\fast404\Unit\Fast404Test

Tests Fast404 methods.

@coversDefaultClass \Drupal\fast404\Fast404 @group fast404

Hierarchy

Expanded class hierarchy of Fast404Test

File

tests/src/Unit/Fast404Test.php, line 13

Namespace

Drupal\Tests\fast404\Unit
View source
class Fast404Test extends UnitTestCase {

  /**
   * Creates a fast404 object to test.
   *
   * @return \Drupal\fast404\Fast404
   *   A mock fast404 object to test.
   */
  protected function getFast404() {
    $requestStub = $this
      ->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Request')
      ->disableOriginalConstructor()
      ->getMock();
    $fast404 = $this
      ->getMockBuilder('\\Drupal\\fast404\\Fast404')
      ->setConstructorArgs([
      $requestStub,
    ])
      ->setMethods([
      'isCli',
    ])
      ->getMock();
    $fast404
      ->method('isCli')
      ->willReturn(FALSE);
    return $fast404;
  }

  /**
   * Tests blocking a path.
   *
   * @covers ::blockPath
   */
  public function testBlockPath() {
    $fast404 = $this
      ->getFast404();

    // Default value is FALSE for respond404.
    $this
      ->assertAttributeEquals(FALSE, 'respond404', $fast404);
    $fast404
      ->blockPath();

    // A block path's value is TRUE for respond404.
    $this
      ->assertAttributeEquals(TRUE, 'respond404', $fast404);
  }

  /**
   * Tests checking if a path is blocked.
   *
   * @covers ::isPathBlocked
   */
  public function testIsPathBlocked() {
    $fast404 = $this
      ->getFast404();
    $this
      ->assertEquals(FALSE, $fast404
      ->isPathBlocked());

    // If CLI, return FALSE regardless.
    $fast404
      ->method('isCli')
      ->willReturn(TRUE);
    $this
      ->assertEquals(FALSE, $fast404
      ->isPathBlocked());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Fast404Test::getFast404 protected function Creates a fast404 object to test.
Fast404Test::testBlockPath public function Tests blocking a path.
Fast404Test::testIsPathBlocked public function Tests checking if a path is blocked.
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.
UnitTestCase::setUp protected function 340