You are here

class PathMappingTest in Gatsby Live Preview & Incremental Builds 8

Same name in this branch
  1. 8 tests/src/Unit/PathMappingTest.php \Drupal\Tests\gatsby\Unit\PathMappingTest
  2. 8 tests/src/Kernel/PathMappingTest.php \Drupal\Tests\gatsby\Kernel\PathMappingTest
Same name and namespace in other branches
  1. 2.0.x tests/src/Unit/PathMappingTest.php \Drupal\Tests\gatsby\Unit\PathMappingTest

Defines a test for GatsbyPathMapping.

@group gatsby

@covers \Drupal\gatsby\PathMapping

Hierarchy

Expanded class hierarchy of PathMappingTest

File

tests/src/Unit/PathMappingTest.php, line 15

Namespace

Drupal\Tests\gatsby\Unit
View source
class PathMappingTest extends UnitTestCase {

  /**
   * {@inheritdoc}
   */
  protected $pathmapping;

  /**
   * Tests GatsbyPathMapping::parsePathMapping.
   *
   * @dataProvider providerParsePathMapping
   */
  public function testParsePathMapping(string $mapping, array $expected) {
    $this
      ->assertEquals($expected, PathMapping::parsePathMapping($mapping));
  }

  /**
   * Data provider for testParsePathMapping.
   *
   * @return array
   *   Test cases.
   */
  public function providerParsePathMapping() : array {
    return [
      'empty' => [
        '',
        [],
      ],
      'single value' => [
        '/foo|/bar',
        [
          '/foo' => '/bar',
        ],
      ],
      'complex nested path' => [
        '/foo/bar/whizz|/bar/biz/bang',
        [
          '/foo/bar/whizz' => '/bar/biz/bang',
        ],
      ],
      'multiple values' => [
        "/foo|/bar\n/biz|/bang",
        [
          '/foo' => '/bar',
          '/biz' => '/bang',
        ],
      ],
      'empty line in middle' => [
        "/foo|/bar\n\n/biz|/bang",
        [
          '/foo' => '/bar',
          '/biz' => '/bang',
        ],
      ],
      'empty line at end' => [
        "/foo|/bar\n/biz|/bang\n",
        [
          '/foo' => '/bar',
          '/biz' => '/bang',
        ],
      ],
      'empty line at start' => [
        "\n/foo|/bar\n/biz|/bang",
        [
          '/foo' => '/bar',
          '/biz' => '/bang',
        ],
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PathMappingTest::$pathmapping protected property
PathMappingTest::providerParsePathMapping public function Data provider for testParsePathMapping.
PathMappingTest::testParsePathMapping public function Tests GatsbyPathMapping::parsePathMapping.
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