You are here

public function ResourceEnhancerTest::testEnhance in JSON:API Resources 8

Test route enhancement.

File

tests/src/Kernel/Routing/ResourceEnhancerTest.php, line 28

Class

ResourceEnhancerTest
@coversDefaultClass \Drupal\jsonapi_resources\Unstable\Routing\Enhancer\ResourceEnhancer @group jsonapi_resources

Namespace

Drupal\Tests\jsonapi_resources\Kernel

Code

public function testEnhance() {
  $resource_enhancer = new ResourceEnhancer($this->container
    ->get('class_resolver'), $this->container
    ->get('current_route_match'));
  $route_object = new Route('/resource');
  $route_defaults = [
    '_jsonapi_resource' => '\\Drupal\\jsonapi_resources_test\\Resource\\AuthorArticles',
    '_route_object' => $route_object,
    '_route' => 'jsonapi_resource_test_route',
  ];
  $enhanced_defaults = $resource_enhancer
    ->enhance($route_defaults, Request::createFromGlobals());
  $this
    ->assertSame($enhanced_defaults['_controller'], 'controller.jsonapi_resource:processRequest');

  // Ensure that the enhancer ignores routes that already have a controller
  // defined.
  $route_defaults = [
    '_controller' => '\\Drupal\\mymodule\\Controller\\Doesnt::exist',
  ];
  $enhanced_defaults = $resource_enhancer
    ->enhance($route_defaults, Request::createFromGlobals());
  $this
    ->assertSame($enhanced_defaults['_controller'], $route_defaults['_controller']);
}