You are here

public function RelationshipNormalizerValueTest::testRasterizeValue in JSON:API 8

@covers ::rasterizeValue @dataProvider rasterizeValueProvider

File

tests/src/Unit/Normalizer/Value/RelationshipNormalizerValueTest.php, line 51

Class

RelationshipNormalizerValueTest
@coversDefaultClass \Drupal\jsonapi\Normalizer\Value\RelationshipNormalizerValue @group jsonapi

Namespace

Drupal\Tests\jsonapi\Unit\Normalizer\Value

Code

public function testRasterizeValue($values, $cardinality, $expected, CacheableMetadata $expected_cacheability) {
  $link_manager = $this
    ->prophesize(LinkManager::class);
  $link_manager
    ->getEntityLink(Argument::any(), Argument::any(), Argument::type('array'), Argument::type('string'))
    ->willReturn('dummy_entity_link');
  $resource_type = new ResourceType($this
    ->randomMachineName(), $this
    ->randomMachineName(), NULL);
  $resource_type
    ->setRelatableResourceTypes([
    'ipsum' => [
      $resource_type,
    ],
  ]);
  $object = new RelationshipNormalizerValue(AccessResult::allowed()
    ->cachePerUser()
    ->addCacheTags([
    'relationship:foo',
  ]), $values, $cardinality, [
    'link_manager' => $link_manager
      ->reveal(),
    'host_entity_id' => 'lorem',
    'resource_type' => $resource_type,
    'field_name' => 'ipsum',
  ]);
  $this
    ->assertEquals($expected, $object
    ->rasterizeValue());
  $this
    ->assertSame($expected_cacheability
    ->getCacheContexts(), $object
    ->getCacheContexts());
  $this
    ->assertSame($expected_cacheability
    ->getCacheTags(), $object
    ->getCacheTags());
  $this
    ->assertSame($expected_cacheability
    ->getCacheMaxAge(), $object
    ->getCacheMaxAge());
}