You are here

class RouteCompilerTest in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/routing/Tests/RouteCompilerTest.php \Symfony\Component\Routing\Tests\RouteCompilerTest
  2. 8 core/tests/Drupal/Tests/Core/Routing/RouteCompilerTest.php \Drupal\Tests\Core\Routing\RouteCompilerTest
Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Routing/RouteCompilerTest.php \Drupal\Tests\Core\Routing\RouteCompilerTest

@coversDefaultClass \Drupal\Core\Routing\RouteCompiler @group Routing

Hierarchy

Expanded class hierarchy of RouteCompilerTest

File

core/tests/Drupal/Tests/Core/Routing/RouteCompilerTest.php, line 19
Contains \Drupal\Tests\Core\Routing\RouteCompilerTest.

Namespace

Drupal\Tests\Core\Routing
View source
class RouteCompilerTest extends UnitTestCase {

  /**
   * Tests RouteCompiler::getFit().
   *
   * @param string $path
   *   A path whose fit will be calculated in the test.
   * @param int $expected
   *   The expected fit returned by RouteCompiler::getFit()
   *
   * @dataProvider providerTestGetFit
   */
  public function testGetFit($path, $expected) {
    $route_compiler = new RouteCompiler();
    $result = $route_compiler
      ->getFit($path);
    $this
      ->assertSame($expected, $result);
  }

  /**
   * Provides data for RouteCompilerTest::testGetFit()
   *
   * @return array
   *   An array of arrays, where each inner array has the path whose fit is to
   *   be calculated as the first value and the expected fit as the second
   *   value.
   */
  public function providerTestGetFit() {
    return array(
      array(
        'test',
        1,
      ),
      array(
        '/testwithleadingslash',
        1,
      ),
      array(
        'testwithtrailingslash/',
        1,
      ),
      array(
        '/testwithslashes/',
        1,
      ),
      array(
        'test/with/multiple/parts',
        15,
      ),
      array(
        'test/with/{some}/slugs',
        13,
      ),
      array(
        'test/very/long/path/that/drupal/7/could/not/have/handled',
        2047,
      ),
    );
  }

  /**
   * Confirms that a route compiles properly with the necessary data.
   */
  public function testCompilation() {
    $route = new Route('/test/{something}/more');
    $route
      ->setOption('compiler_class', 'Drupal\\Core\\Routing\\RouteCompiler');
    $compiled = $route
      ->compile();
    $this
      ->assertEquals($compiled
      ->getFit(), 5, 'The fit was incorrect.');
    $this
      ->assertEquals($compiled
      ->getPatternOutline(), '/test/%/more', 'The pattern outline was not correct.');
  }

  /**
   * Confirms that a compiled route with default values has the correct outline.
   */
  public function testCompilationDefaultValue() {

    // Because "here" has a default value, it should not factor into the outline
    // or the fitness.
    $route = new Route('/test/{something}/more/{here}', array(
      'here' => 'there',
    ));
    $route
      ->setOption('compiler_class', 'Drupal\\Core\\Routing\\RouteCompiler');
    $compiled = $route
      ->compile();
    $this
      ->assertEquals($compiled
      ->getFit(), 5, 'The fit was not correct.');
    $this
      ->assertEquals($compiled
      ->getPatternOutline(), '/test/%/more', 'The pattern outline was not correct.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteCompilerTest::providerTestGetFit public function Provides data for RouteCompilerTest::testGetFit()
RouteCompilerTest::testCompilation public function Confirms that a route compiles properly with the necessary data.
RouteCompilerTest::testCompilationDefaultValue public function Confirms that a compiled route with default values has the correct outline.
RouteCompilerTest::testGetFit public function Tests RouteCompiler::getFit().
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root.
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName protected function Mocks a block with a block plugin.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in 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 259