class ConfigEntityNormalizerTest in JSON:API 8
@coversDefaultClass \Drupal\jsonapi\Normalizer\ConfigEntityNormalizer @group jsonapi
@internal
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\jsonapi\Unit\Normalizer\ConfigEntityNormalizerTest
Expanded class hierarchy of ConfigEntityNormalizerTest
File
- tests/
src/ Unit/ Normalizer/ ConfigEntityNormalizerTest.php, line 20
Namespace
Drupal\Tests\jsonapi\Unit\NormalizerView source
class ConfigEntityNormalizerTest extends UnitTestCase {
/**
* The normalizer under test.
*
* @var \Drupal\jsonapi\Normalizer\ConfigEntityNormalizer
*/
protected $normalizer;
/**
* {@inheritdoc}
*/
public function setUp() {
$link_manager = $this
->prophesize(LinkManager::class);
$resource_type = new ResourceType('dolor', 'sid', NULL);
$resource_type
->setRelatableResourceTypes([]);
$resource_type_repository = $this
->prophesize(ResourceTypeRepository::class);
$resource_type_repository
->get(Argument::type('string'), Argument::type('string'))
->willReturn($resource_type);
$this->normalizer = new ConfigEntityNormalizer($link_manager
->reveal(), $resource_type_repository
->reveal(), $this
->prophesize(EntityTypeManagerInterface::class)
->reveal());
}
/**
* @covers ::normalize
* @dataProvider normalizeProvider
*/
public function testNormalize($input, $expected) {
$entity = $this
->prophesize(ConfigEntityInterface::class);
$entity
->toArray()
->willReturn([
'amet' => $input,
]);
$entity
->getCacheContexts()
->willReturn([]);
$entity
->getCacheTags()
->willReturn([]);
$entity
->getCacheMaxAge()
->willReturn(-1);
$entity
->getEntityTypeId()
->willReturn('');
$entity
->bundle()
->willReturn('');
$normalized = $this->normalizer
->normalize($entity
->reveal(), 'api_json', []);
$first = $normalized
->getValues();
$first = reset($first);
$this
->assertSame($expected, $first
->rasterizeValue());
}
/**
* Data provider for the normalize test.
*
* @return array
* The data for the test method.
*/
public function normalizeProvider() {
return [
[
'lorem',
'lorem',
],
[
[
'ipsum' => 'dolor',
'ra' => 'foo',
],
[
'ipsum' => 'dolor',
'ra' => 'foo',
],
],
[
[
'ipsum' => 'dolor',
],
[
'ipsum' => 'dolor',
],
],
[
[
'lorem' => [
'ipsum' => [
'dolor' => 'sid',
'amet' => 'ra',
],
],
],
[
'lorem' => [
'ipsum' => [
'dolor' => 'sid',
'amet' => 'ra',
],
],
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigEntityNormalizerTest:: |
protected | property | The normalizer under test. | |
ConfigEntityNormalizerTest:: |
public | function | Data provider for the normalize test. | |
ConfigEntityNormalizerTest:: |
public | function |
Overrides UnitTestCase:: |
|
ConfigEntityNormalizerTest:: |
public | function | @covers ::normalize @dataProvider normalizeProvider | |
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. |