/**
  * Confirms that the AcceptHeaderMatcher throws an exception for no-route.
  *
  * @expectedException \Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException
  * @expectedExceptionMessage No route found for the specified formats application/json text/xml.
  */
 public function testNoRouteFound()
 {
     // Remove the sample routes that would match any method.
     $routes = $this->fixtures->sampleRouteCollection();
     $routes->remove('route_a');
     $routes->remove('route_b');
     $routes->remove('route_c');
     $routes->remove('route_d');
     $request = Request::create('path/two', 'GET');
     $request->headers->set('Accept', 'application/json, text/xml;q=0.9');
     $this->matcher->filter($routes, $request);
     $this->fail('No exception was thrown.');
 }
 /**
  * Confirms that the matcher throws an exception for no-route.
  *
  * @expectedException \Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException
  * @expectedExceptionMessage No route found that matches the Content-Type header.
  */
 public function testNoRouteFound()
 {
     $matcher = new ContentTypeHeaderMatcher();
     $routes = $this->fixtures->contentRouteCollection();
     $request = Request::create('path/two', 'POST');
     $request->headers->set('Content-type', 'application/hal+json');
     $matcher->filter($routes, $request);
     $this->fail('No exception was thrown.');
 }
  /**
   * Confirms that the matcher throws an exception for missing request header.
   *
   * @covers ::filter
   */
  public function testContentTypeRequestHeaderMissing() {
    $matcher = new ContentTypeHeaderMatcher();

    $routes = $this->fixtures->contentRouteCollection();
    $request = Request::create('path/two', 'POST');
    // Delete all request headers that Request::create() sets by default.
    $request->headers = new ParameterBag();
    $this->setExpectedException(UnsupportedMediaTypeHttpException::class, 'No "Content-Type" request header specified');
    $matcher->filter($routes, $request);
  }
Esempio n. 4
0
 /**
  * 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);
 }
Esempio n. 5
0
 /**
  * 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);
 }
Esempio n. 6
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));
 }
 /**
  * Tests that provided routes by a module is put into the dumper/dispatcher.
  *
  * @see \Drupal\Core\Routing\RouteBuilder::rebuild()
  */
 public function testRebuildWithStaticModuleRoutes()
 {
     $this->lock->expects($this->once())->method('acquire')->with('router_rebuild')->will($this->returnValue(TRUE));
     $routing_fixtures = new RoutingFixtures();
     $routes = $routing_fixtures->staticSampleRouteCollection();
     $this->yamlDiscovery->expects($this->once())->method('findAll')->will($this->returnValue(array('test_module' => $routes)));
     $route_collection = $routing_fixtures->sampleRouteCollection();
     $route_build_event = new RouteBuildEvent($route_collection);
     // Ensure that the alter routes events are fired.
     $this->dispatcher->expects($this->at(0))->method('dispatch')->with(RoutingEvents::DYNAMIC, $route_build_event);
     $this->dispatcher->expects($this->at(1))->method('dispatch')->with(RoutingEvents::ALTER, $route_build_event);
     // Ensure that the routes are set to the dumper and dumped.
     $this->dumper->expects($this->at(0))->method('addRoutes')->with($route_collection);
     $this->dumper->expects($this->at(1))->method('dump')->with();
     $this->assertTrue($this->routeBuilder->rebuild());
 }