class FieldNormalizerValueTest in JSON:API 8
@coversDefaultClass \Drupal\jsonapi\Normalizer\Value\FieldNormalizerValue @group jsonapi
@internal
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\jsonapi\Unit\Normalizer\Value\FieldNormalizerValueTest
Expanded class hierarchy of FieldNormalizerValueTest
File
- tests/
src/ Unit/ Normalizer/ Value/ FieldNormalizerValueTest.php, line 18
Namespace
Drupal\Tests\jsonapi\Unit\Normalizer\ValueView source
class FieldNormalizerValueTest extends UnitTestCase {
/**
* The cache contexts manager.
*
* @var \Drupal\Core\Cache\Context\CacheContextsManager|\PHPUnit_Framework_MockObject_MockObject
*/
protected $cacheContextsManager;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->cacheContextsManager = $this
->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')
->disableOriginalConstructor()
->getMock();
$this->cacheContextsManager
->method('assertValidTokens')
->willReturn(TRUE);
$container = new ContainerBuilder();
$container
->set('cache_contexts_manager', $this->cacheContextsManager);
\Drupal::setContainer($container);
}
/**
* @covers ::rasterizeValue
* @covers ::__construct
* @dataProvider rasterizeValueProvider
*/
public function testRasterizeValue($values, $cardinality, $expected) {
$object = new FieldNormalizerValue(AccessResult::allowed()
->cachePerUser()
->addCacheTags([
'field:foo',
]), $values, $cardinality, 'attributes');
$this
->assertEquals($expected, $object
->rasterizeValue());
$this
->assertSame([
'ccfoo',
'user',
], $object
->getCacheContexts());
$this
->assertSame([
'ctfoo',
'field:foo',
], $object
->getCacheTags());
$this
->assertSame(15, $object
->getCacheMaxAge());
}
/**
* Data provider for testRasterizeValue.
*/
public function rasterizeValueProvider() {
$uuid_raw = '4ae99eec-8b0e-41f7-9400-fbd65c174902';
$uuid_value = $this
->prophesize(FieldItemNormalizerValue::class);
$uuid_value
->rasterizeValue()
->willReturn('4ae99eec-8b0e-41f7-9400-fbd65c174902');
$uuid_value
->getCacheContexts()
->willReturn([
'ccfoo',
]);
$uuid_value
->getCacheTags()
->willReturn([
'ctfoo',
]);
$uuid_value
->getCacheMaxAge()
->willReturn(15);
return [
[
[
$uuid_value
->reveal(),
],
1,
$uuid_raw,
],
[
[
$uuid_value
->reveal(),
$uuid_value
->reveal(),
],
-1,
[
$uuid_raw,
$uuid_raw,
],
],
];
}
/**
* @covers ::rasterizeIncludes
*/
public function testRasterizeIncludes() {
$value = $this
->prophesize(RelationshipItemNormalizerValue::class);
$include = $this
->prophesize('\\Drupal\\jsonapi\\Normalizer\\Value\\EntityNormalizerValue');
$include
->rasterizeValue()
->willReturn('Lorem');
$value
->getCacheContexts()
->willReturn([
'ccfoo',
]);
$value
->getCacheTags()
->willReturn([
'ctfoo',
]);
$value
->getCacheMaxAge()
->willReturn(15);
$value
->getInclude()
->willReturn($include
->reveal());
$object = new FieldNormalizerValue(AccessResult::allowed(), [
$value
->reveal(),
], 1, 'attributes');
$this
->assertEquals([
'Lorem',
], $object
->rasterizeIncludes());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FieldNormalizerValueTest:: |
protected | property | The cache contexts manager. | |
FieldNormalizerValueTest:: |
public | function | Data provider for testRasterizeValue. | |
FieldNormalizerValueTest:: |
protected | function |
Overrides UnitTestCase:: |
|
FieldNormalizerValueTest:: |
public | function | @covers ::rasterizeIncludes | |
FieldNormalizerValueTest:: |
public | function | @covers ::rasterizeValue @covers ::__construct @dataProvider rasterizeValueProvider | |
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. |