/** * Confirms that an exception is thrown when no matching path is found. */ function testOutlinePathNoMatch() { $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->complexRouteCollection()); $dumper->dump(); $path = '/no/such/path'; $request = Request::create($path, 'GET'); $routes = $provider->getRoutesByPattern($path); $this->assertFalse(count($routes), 'No path found with this pattern.'); $collection = $provider->getRouteCollectionForRequest($request); $this->assertTrue(count($collection) == 0, 'Empty route collection found with this pattern.'); }
/** * 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'])); }