You are here

public function CustomQueryParameterNamesAccessCheckTest::testAccess in JSON:API 8

Ensures that query params are properly validated.

@dataProvider providerTestAccess @covers ::access @covers ::validate

File

tests/src/Unit/Access/CustomQueryParameterNamesAccessCheckTest.php, line 24

Class

CustomQueryParameterNamesAccessCheckTest
@coversDefaultClass \Drupal\jsonapi\Access\CustomQueryParameterNamesAccessCheck @group jsonapi

Namespace

Drupal\Tests\jsonapi\Unit\Access

Code

public function testAccess($name, $valid) {
  $access_checker = new CustomQueryParameterNamesAccessCheck();
  $request = new Request();
  $request->attributes
    ->set('_json_api_params', [
    $name => '123',
  ]);
  $result = $access_checker
    ->access($request);
  if ($valid) {
    $this
      ->assertTrue($result
      ->isAllowed());
  }
  else {
    $this
      ->assertFalse($result
      ->isAllowed());
  }
}