You are here

public function JsonApiParamEnhancerTest::testEnhanceSort in JSON:API 8

@covers ::enhance

File

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

Class

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

Namespace

Drupal\Tests\jsonapi\Unit\Routing

Code

public function testEnhanceSort() {
  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', [
    'sort' => '-lorem',
  ]));
  $this
    ->assertInstanceOf(Sort::class, $defaults['_json_api_params']['sort']);
  $this
    ->assertInstanceOf(OffsetPage::class, $defaults['_json_api_params']['page']);
  $this
    ->assertTrue(empty($defaults['_json_api_params']['filter']));
}