class JsonApiParamEnhancerTest in JSON:API 8
@coversDefaultClass \Drupal\jsonapi\Routing\JsonApiParamEnhancer @group jsonapi @group jsonapi_param_enhancer @group legacy
@internal
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\jsonapi\Unit\Routing\JsonApiParamEnhancerTest
Expanded class hierarchy of JsonApiParamEnhancerTest
File
- tests/
src/ Unit/ Routing/ JsonApiParamEnhancerTest.php, line 26
Namespace
Drupal\Tests\jsonapi\Unit\RoutingView source
class JsonApiParamEnhancerTest extends UnitTestCase {
/**
* @covers ::applies
*/
public function testApplies() {
list($filter_normalizer, $sort_normalizer, $page_normalizer) = $this
->getMockNormalizers();
$object = new JsonApiParamEnhancer($filter_normalizer, $sort_normalizer, $page_normalizer);
$this
->assertTrue($object
->applies(new Route('/jsonapi/foo/bar', [
RouteObjectInterface::CONTROLLER_NAME => Routes::FRONT_CONTROLLER,
Routes::JSON_API_ROUTE_FLAG_KEY => TRUE,
Routes::RESOURCE_TYPE_KEY => 'foo--bar',
])));
$this
->assertFalse($object
->applies(new Route('/llama/foo/bar', [
RouteObjectInterface::CONTROLLER_NAME => 'failing',
])));
}
/**
* @covers ::enhance
*/
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']));
}
/**
* @covers ::enhance
*/
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']));
}
/**
* Builds mock normalizers.
*/
public function getMockNormalizers() {
$filter_normalizer = $this
->prophesize(DenormalizerInterface::class);
$filter_normalizer
->denormalize(Argument::any(), Filter::class, Argument::any(), Argument::any())
->willReturn($this
->prophesize(Filter::class)
->reveal());
$sort_normalizer = $this
->prophesize(DenormalizerInterface::class);
$sort_normalizer
->denormalize(Argument::any(), Sort::class, Argument::any(), Argument::any())
->willReturn($this
->prophesize(Sort::class)
->reveal());
$page_normalizer = $this
->prophesize(DenormalizerInterface::class);
$page_normalizer
->denormalize(Argument::any(), OffsetPage::class)
->willReturn($this
->prophesize(OffsetPage::class)
->reveal());
return [
$filter_normalizer
->reveal(),
$sort_normalizer
->reveal(),
$page_normalizer
->reveal(),
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JsonApiParamEnhancerTest:: |
public | function | Builds mock normalizers. | |
JsonApiParamEnhancerTest:: |
public | function | @covers ::applies | |
JsonApiParamEnhancerTest:: |
public | function | @covers ::enhance | |
JsonApiParamEnhancerTest:: |
public | function | @covers ::enhance | |
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 |