/**
  * Ensures that the routing system is capable of extreme long patterns.
  */
 public function testGetRoutesByPatternWithLongPatterns()
 {
     $connection = Database::getConnection();
     $provider = new RouteProvider($connection, $this->routeBuilder, $this->state, 'test_routes');
     $this->fixtures->createTables($connection);
     // This pattern has only 3 parts, so we will get candidates, but no routes,
     // even though we have not dumped the routes yet.
     $shortest = '/test/1/test2';
     $result = $provider->getRoutesByPattern($shortest);
     $this->assertEqual($result->count(), 0);
     $candidates = $provider->getCandidateOutlines(explode('/', trim($shortest, '/')));
     $this->assertEqual(count($candidates), 7);
     // A longer patten is not found and returns no candidates
     $path_to_test = '/test/1/test2/2/test3/3/4/5/6/test4';
     $result = $provider->getRoutesByPattern($path_to_test);
     $this->assertEqual($result->count(), 0);
     $candidates = $provider->getCandidateOutlines(explode('/', trim($path_to_test, '/')));
     $this->assertEqual(count($candidates), 0);
     // Add a matching route and dump it.
     $dumper = new MatcherDumper($connection, $this->state, 'test_routes');
     $collection = new RouteCollection();
     $collection->add('long_pattern', new Route('/test/{v1}/test2/{v2}/test3/{v3}/{v4}/{v5}/{v6}/test4'));
     $dumper->addRoutes($collection);
     $dumper->dump();
     $result = $provider->getRoutesByPattern($path_to_test);
     $this->assertEqual($result->count(), 1);
     // We can't compare the values of the routes directly, nor use
     // spl_object_hash() because they are separate instances.
     $this->assertEqual(serialize($result->get('long_pattern')), serialize($collection->get('long_pattern')), 'The right route was found.');
     // We now have a single candidate outline.
     $candidates = $provider->getCandidateOutlines(explode('/', trim($path_to_test, '/')));
     $this->assertEqual(count($candidates), 1);
     // Longer and shorter patterns are not found. Both are longer than 3, so
     // we should not have any candidates either. The fact that we do not
     // get any candidates for a longer path is a security feature.
     $longer = '/test/1/test2/2/test3/3/4/5/6/test4/trailing/more/parts';
     $result = $provider->getRoutesByPattern($longer);
     $this->assertEqual($result->count(), 0);
     $candidates = $provider->getCandidateOutlines(explode('/', trim($longer, '/')));
     $this->assertEqual(count($candidates), 1);
     $shorter = '/test/1/test2/2/test3';
     $result = $provider->getRoutesByPattern($shorter);
     $this->assertEqual($result->count(), 0);
     $candidates = $provider->getCandidateOutlines(explode('/', trim($shorter, '/')));
     $this->assertEqual(count($candidates), 0);
     // This pattern has only 3 parts, so we will get candidates, but no routes.
     // This result is unchanged by running the dumper.
     $result = $provider->getRoutesByPattern($shortest);
     $this->assertEqual($result->count(), 0);
     $candidates = $provider->getCandidateOutlines(explode('/', trim($shortest, '/')));
     $this->assertEqual(count($candidates), 7);
 }
 /**
  * Tests the determination of the masks generation.
  */
 public function testMenuMasksGeneration()
 {
     $connection = Database::getConnection();
     $dumper = new MatcherDumper($connection, $this->state, 'test_routes');
     $collection = new RouteCollection();
     $collection->add('test_route_1', new Route('/test-length-3/{my}/path'));
     $collection->add('test_route_2', new Route('/test-length-3/hello/path'));
     $collection->add('test_route_3', new Route('/test-length-5/{my}/path/marvin/magrathea'));
     $collection->add('test_route_4', new Route('/test-length-7/{my}/path/marvin/magrathea/earth/ursa-minor'));
     $dumper->addRoutes($collection);
     $this->fixtures->createTables($connection);
     $dumper->dump(array('provider' => 'test'));
     // Using binary for readability, we expect a 0 at any wildcard slug. They
     // should be ordered from longest to shortest.
     $expected = array(bindec('1011111'), bindec('10111'), bindec('111'), bindec('101'));
     $this->assertEqual($this->state->get('routing.menu_masks.test_routes'), $expected);
 }
Exemple #3
0
 /**
  * Tests getRoutesPaged().
  */
 public function testGetRoutesPaged()
 {
     $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->dump();
     $fixture_routes = $this->fixtures->staticSampleRouteCollection();
     // Query all the routes.
     $routes = $provider->getRoutesPaged(0);
     $this->assertEqual(array_keys($routes), array_keys($fixture_routes));
     // Query non routes.
     $routes = $provider->getRoutesPaged(0, 0);
     $this->assertEqual(array_keys($routes), []);
     // Query a limited sets of routes.
     $routes = $provider->getRoutesPaged(1, 2);
     $this->assertEqual(array_keys($routes), array_slice(array_keys($fixture_routes), 1, 2));
 }