/** * 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.'); }
/** * Tests route filtering on POST form submission requests. */ public function testPostForm() { $collection = $this->fixtures->sampleRouteCollection(); $collection->addCollection($this->fixtures->contentRouteCollection()); // Test that all XML and JSON restricted routes get filtered out on a POST // form submission. $request = Request::create('path/two', 'POST'); $request->headers->set('Content-type', 'application/www-form-urlencoded'); $routes = $this->matcher->filter($collection, $request); $this->assertEquals(count($routes), 5, 'The correct number of routes was found.'); $this->assertNull($routes->get('route_f'), 'The json route was found.'); $this->assertNull($routes->get('route_g'), 'The xml route was not found.'); }
/** * Test RouteProvider::getRouteByName() and RouteProvider::getRoutesByNames(). */ protected function testRouteByName() { $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(); $route = $provider->getRouteByName('route_a'); $this->assertEqual($route->getPath(), '/path/one', 'The right route pattern was found.'); $this->assertEqual($route->getRequirement('_method'), 'GET', 'The right route method was found.'); $route = $provider->getRouteByName('route_b'); $this->assertEqual($route->getPath(), '/path/one', 'The right route pattern was found.'); $this->assertEqual($route->getRequirement('_method'), 'PUT', 'The right route method was found.'); $exception_thrown = FALSE; try { $provider->getRouteByName('invalid_name'); } catch (RouteNotFoundException $e) { $exception_thrown = TRUE; } $this->assertTrue($exception_thrown, 'Random route was not found.'); $routes = $provider->getRoutesByNames(array('route_c', 'route_d', $this->randomName())); $this->assertEqual(count($routes), 2, 'Only two valid routes found.'); $this->assertEqual($routes['route_c']->getPath(), '/path/two'); $this->assertEqual($routes['route_d']->getPath(), '/path/three'); }
/** * 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()); }