You are here

public function ResourceRoutesTest::testMissingBasePathPlaceholder in JSON:API Resources 8

Tests for an exception when the %jsonapi% base path placeholder is missing.

File

tests/src/Unit/Routing/ResourceRoutesTest.php, line 60

Class

ResourceRoutesTest
Tests the JSON:API resource route subscriber.

Namespace

Drupal\Tests\jsonapi_resources\Unit\Routing

Code

public function testMissingBasePathPlaceholder() {
  $route_collection = new RouteCollection();
  $route_defaults = [
    '_jsonapi_resource' => '\\Drupal\\jsonapi_resources_test\\Resource\\AuthorArticles',
    '_jsonapi_resource_types' => [
      'node--article',
    ],
  ];
  $route_collection
    ->add('jsonapi_resource_route', new Route('/missing-base-path', $route_defaults));
  $route_rebuild_event = new RouteBuildEvent($route_collection);
  $resource_type_repository = $this
    ->prophesize(ResourceTypeRepositoryInterface::class);
  $container = $this
    ->prophesize(ContainerInterface::class);
  $resource_routes = new ResourceRoutes($resource_type_repository
    ->reveal(), [
    'basic_auth' => 'basic_auth',
  ], '/custom-base-path', $container
    ->reveal());
  $this
    ->expectExceptionObject(new RouteDefinitionException("The jsonapi_resource_route route definition's path, `/missing-base-path`, must begin with `/%jsonapi%` so that the JSON:API base path can be substituted in its place."));
  $resource_routes
    ->decorateJsonapiResourceRoutes($route_rebuild_event);
}