You are here

class RouterBaseTest in Drupal 7 to 8/9 Module Upgrader 8

@group DMU.Routing

Hierarchy

Expanded class hierarchy of RouterBaseTest

File

tests/src/Unit/Routing/RouterBaseTest.php, line 14

Namespace

Drupal\Tests\drupalmoduleupgrader\Unit\Routing
View source
class RouterBaseTest extends UnitTestCase {
  private $userEdit, $userView, $userRoot, $routeProvider;
  public function setUp() {
    parent::setUp();
    $this->userEdit = new Route('/user/{user}/edit');
    $this->userView = new Route('/user/{user}');
    $this->userRoot = new Route('/user');
    $route_collection = new RouteCollection();
    $route_collection
      ->add('user', $this->userRoot);
    $this->routeProvider = $this
      ->createMock('\\Drupal\\Core\\Routing\\RouteProviderInterface');
    $this->routeProvider
      ->expects($this
      ->any())
      ->method('getRoutesByPattern')
      ->with('/user')
      ->will($this
      ->returnValue($route_collection));
  }
  public function testAddRoute() {
    $router = new RouterBase();
    $this
      ->assertCount(0, $router);
    $route = new RouteWrapper('user.edit', $this->userEdit, $this->routeProvider);
    $router
      ->addRoute($route);
    $this
      ->assertCount(1, $router);
  }

  /**
   * @depends testAddRoute
   */
  public function testFinalize() {
    $router = new RouterBase();
    $user_edit = new RouteWrapper('user.edit', $this->userEdit, $this->routeProvider);
    $router
      ->addRoute($user_edit);
    $user_view = new RouteWrapper('user.view', $this->userView, $this->routeProvider);
    $router
      ->addRoute($user_view);
    $router
      ->finalize();
    $this
      ->assertTrue($user_edit
      ->hasParent());
    $this
      ->assertSame($user_view, $user_edit
      ->getParent());
    $this
      ->assertTrue($user_view
      ->hasParent());
    $this
      ->assertEquals('/user', $user_view
      ->getParent()
      ->getPath());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
RouterBaseTest::$userEdit private property
RouterBaseTest::setUp public function Overrides UnitTestCase::setUp
RouterBaseTest::testAddRoute public function
RouterBaseTest::testFinalize public function @depends testAddRoute
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.