class CustomQueryParameterNamesAccessCheckTest in JSON:API 8
@coversDefaultClass \Drupal\jsonapi\Access\CustomQueryParameterNamesAccessCheck @group jsonapi
@internal
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\jsonapi\Unit\Access\CustomQueryParameterNamesAccessCheckTest
Expanded class hierarchy of CustomQueryParameterNamesAccessCheckTest
File
- tests/
src/ Unit/ Access/ CustomQueryParameterNamesAccessCheckTest.php, line 15
Namespace
Drupal\Tests\jsonapi\Unit\AccessView source
class CustomQueryParameterNamesAccessCheckTest extends UnitTestCase {
/**
* Ensures that query params are properly validated.
*
* @dataProvider providerTestAccess
* @covers ::access
* @covers ::validate
*/
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());
}
}
/**
* Data provider for testAccess.
*/
public function providerTestAccess() {
$data = [];
$data['Official query parameter: sort'] = [
'sort',
TRUE,
];
$data['Official query parameter: page'] = [
'page',
TRUE,
];
$data['Official query parameter: filter'] = [
'filter',
TRUE,
];
$data['Valid member, but invalid custom query parameter'] = [
'foobar',
FALSE,
];
$data['Valid custom query parameter: dash'] = [
'foo-bar',
TRUE,
];
$data['Valid custom query parameter: underscore'] = [
'foo_bar',
TRUE,
];
$data['Valid custom query parameter: camelcase'] = [
'fooBar',
TRUE,
];
return $data;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CustomQueryParameterNamesAccessCheckTest:: |
public | function | Data provider for testAccess. | |
CustomQueryParameterNamesAccessCheckTest:: |
public | function | Ensures that query params are properly validated. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |