You are here

public function JsonApiParamEnhancerTest::testEnhancePage in JSON:API 8

@covers ::enhance

File

tests/src/Unit/Routing/JsonApiParamEnhancerTest.php, line 47

Class

JsonApiParamEnhancerTest
@coversDefaultClass \Drupal\jsonapi\Routing\JsonApiParamEnhancer @group jsonapi @group jsonapi_param_enhancer @group legacy

Namespace

Drupal\Tests\jsonapi\Unit\Routing

Code

public function testEnhancePage() {
  list($filter_normalizer, $sort_normalizer, $page_normalizer) = $this
    ->getMockNormalizers();
  $object = new JsonApiParamEnhancer($filter_normalizer, $sort_normalizer, $page_normalizer);
  $defaults = $object
    ->enhance([
    RouteObjectInterface::CONTROLLER_NAME => Routes::FRONT_CONTROLLER,
    Routes::RESOURCE_TYPE_KEY => new ResourceType('foo', 'bar', NULL),
    Routes::JSON_API_ROUTE_FLAG_KEY => TRUE,
  ], Request::create('/jsonapi/foo/bar', 'GET', [
    'page' => [
      'cursor' => 'lorem',
    ],
  ]));
  $this
    ->assertInstanceOf(OffsetPage::class, $defaults['_json_api_params']['page']);
  $this
    ->assertTrue(empty($defaults['_json_api_params']['filter']));
  $this
    ->assertTrue(empty($defaults['_json_api_params']['sort']));
}