3 namespace Drupal\system\Tests\Routing;
5 use Symfony\Component\HttpFoundation\Request;
6 use Symfony\Component\Routing\Exception\RouteNotFoundException;
7 use Symfony\Component\Routing\RouteCollection;
8 use Drupal\Core\Routing\RouteProviderInterface;
11 * Easily configurable mock route provider.
13 class MockRouteProvider implements RouteProviderInterface {
16 * A collection of routes for this route provider.
18 * @var RouteCollection
23 * Constructs a new MockRouteProvider.
25 * @param \Symfony\Component\Routing\RouteCollection $routes
26 * The route collection to use for this provider.
28 public function __construct(RouteCollection $routes) {
29 $this->routes = $routes;
33 * Implements \Symfony\Cmf\Component\Routing\RouteProviderInterface::getRouteCollectionForRequest().
35 * Simply return all routes to prevent
36 * \Symfony\Component\Routing\Exception\ResourceNotFoundException.
38 public function getRouteCollectionForRequest(Request $request) {
45 public function getRouteByName($name) {
46 $routes = $this->getRoutesByNames([$name]);
48 throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
51 return reset($routes);
57 public function preLoadRoutes($names) {
64 public function getRoutesByNames($names) {
66 foreach ($names as $name) {
67 $routes[] = $this->routes->get($name);
76 public function getRoutesByPattern($pattern) {
77 return new RouteCollection();
83 public function getAllRoutes() {
84 return $this->routes->all();
90 public function reset() {