Beispiel #1
0
 /**
  * Tests that route caching works.
  */
 public function testRouteCaching()
 {
     $connection = Database::getConnection();
     $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, $this->cacheTagsInvalidator, 'test_routes');
     $this->fixtures->createTables($connection);
     $dumper = new MatcherDumper($connection, $this->state, 'test_routes');
     $dumper->addRoutes($this->fixtures->sampleRouteCollection());
     $dumper->addRoutes($this->fixtures->complexRouteCollection());
     $dumper->dump();
     // A simple path.
     $path = '/path/add/one';
     $request = Request::create($path, 'GET');
     $provider->getRouteCollectionForRequest($request);
     $cache = $this->cache->get('route:/path/add/one:');
     $this->assertEqual('/path/add/one', $cache->data['path']);
     $this->assertEqual([], $cache->data['query']);
     $this->assertEqual(3, count($cache->data['routes']));
     // A path with query parameters.
     $path = '/path/add/one?foo=bar';
     $request = Request::create($path, 'GET');
     $provider->getRouteCollectionForRequest($request);
     $cache = $this->cache->get('route:/path/add/one:foo=bar');
     $this->assertEqual('/path/add/one', $cache->data['path']);
     $this->assertEqual(['foo' => 'bar'], $cache->data['query']);
     $this->assertEqual(3, count($cache->data['routes']));
     // A path with placeholders.
     $path = '/path/1/one';
     $request = Request::create($path, 'GET');
     $provider->getRouteCollectionForRequest($request);
     $cache = $this->cache->get('route:/path/1/one:');
     $this->assertEqual('/path/1/one', $cache->data['path']);
     $this->assertEqual([], $cache->data['query']);
     $this->assertEqual(2, count($cache->data['routes']));
     // A path with a path alias.
     /** @var \Drupal\Core\Path\AliasStorageInterface $path_storage */
     $path_storage = \Drupal::service('path.alias_storage');
     $path_storage->save('/path/add/one', '/path/add-one');
     /** @var \Drupal\Core\Path\AliasManagerInterface $alias_manager */
     $alias_manager = \Drupal::service('path.alias_manager');
     $alias_manager->cacheClear();
     $path = '/path/add-one';
     $request = Request::create($path, 'GET');
     $provider->getRouteCollectionForRequest($request);
     $cache = $this->cache->get('route:/path/add-one:');
     $this->assertEqual('/path/add/one', $cache->data['path']);
     $this->assertEqual([], $cache->data['query']);
     $this->assertEqual(3, count($cache->data['routes']));
 }
 /**
  * Confirms that _system_path attribute overrides request path.
  */
 function testSystemPathMatch()
 {
     $connection = Database::getConnection();
     $provider = new RouteProvider($connection, $this->routeBuilder, $this->state, 'test_routes');
     $this->fixtures->createTables($connection);
     $dumper = new MatcherDumper($connection, $this->state, 'test_routes');
     $dumper->addRoutes($this->fixtures->sampleRouteCollection());
     $dumper->dump();
     $request = Request::create('/path/one', 'GET');
     $request->attributes->set('_system_path', 'path/two');
     $routes_by_pattern = $provider->getRoutesByPattern('/path/two');
     $routes = $provider->getRouteCollectionForRequest($request);
     $this->assertEqual(array_keys($routes_by_pattern->all()), array_keys($routes->all()), 'Ensure the expected routes are found.');
     foreach ($routes as $route) {
         $this->assertEqual($route->getPath(), '/path/two', 'Found path has correct pattern');
     }
 }