You are here

protected function UrlTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/UrlTest.php, line 73
Contains \Drupal\Tests\Core\UrlTest.

Class

UrlTest
@coversDefaultClass \Drupal\Core\Url @group UrlTest

Namespace

Drupal\Tests\Core

Code

protected function setUp() {
  parent::setUp();
  $map = array();
  $map[] = array(
    'view.frontpage.page_1',
    array(),
    array(),
    FALSE,
    '/node',
  );
  $map[] = array(
    'node_view',
    array(
      'node' => '1',
    ),
    array(),
    FALSE,
    '/node/1',
  );
  $map[] = array(
    'node_edit',
    array(
      'node' => '2',
    ),
    array(),
    FALSE,
    '/node/2/edit',
  );
  $this->map = $map;
  $alias_map = array(
    // Set up one proper alias that can be resolved to a system path.
    array(
      'node-alias-test',
      NULL,
      FALSE,
      'node',
    ),
    // Passing in anything else should return the same string.
    array(
      'node',
      NULL,
      FALSE,
      'node',
    ),
    array(
      'node/1',
      NULL,
      FALSE,
      'node/1',
    ),
    array(
      'node/2/edit',
      NULL,
      FALSE,
      'node/2/edit',
    ),
    array(
      'non-existent',
      NULL,
      FALSE,
      'non-existent',
    ),
  );

  // $this->map has $collect_bubbleable_metadata = FALSE; also generate the
  // $collect_bubbleable_metadata = TRUE case for ::generateFromRoute().
  $generate_from_route_map = [];
  foreach ($this->map as $values) {
    $generate_from_route_map[] = $values;
    $generate_from_route_map[] = [
      $values[0],
      $values[1],
      $values[2],
      TRUE,
      (new GeneratedUrl())
        ->setGeneratedUrl($values[4]),
    ];
  }
  $this->urlGenerator = $this
    ->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface');
  $this->urlGenerator
    ->expects($this
    ->any())
    ->method('generateFromRoute')
    ->will($this
    ->returnValueMap($generate_from_route_map));
  $this->pathAliasManager = $this
    ->getMock('Drupal\\Core\\Path\\AliasManagerInterface');
  $this->pathAliasManager
    ->expects($this
    ->any())
    ->method('getPathByAlias')
    ->will($this
    ->returnValueMap($alias_map));
  $this->router = $this
    ->getMock('Drupal\\Tests\\Core\\Routing\\TestRouterInterface');
  $this->pathValidator = $this
    ->getMock('Drupal\\Core\\Path\\PathValidatorInterface');
  $this->container = new ContainerBuilder();
  $this->container
    ->set('router.no_access_checks', $this->router);
  $this->container
    ->set('url_generator', $this->urlGenerator);
  $this->container
    ->set('path.alias_manager', $this->pathAliasManager);
  $this->container
    ->set('path.validator', $this->pathValidator);
  \Drupal::setContainer($this->container);
}