Skip to content

Commit 8ffe003

Browse files
committed
test: relationship with meta in the resource identifier object
1 parent f4c4294 commit 8ffe003

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/Parsers/ItemParserTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,25 @@ public function itParsesMeta()
645645
static::assertEquals(new Meta(['foo' => 'bar']), $item->getMeta());
646646
}
647647

648+
/**
649+
* @test
650+
*/
651+
public function itParsesMetaInData()
652+
{
653+
$typeMapper = new TypeMapper();
654+
$typeMapper->setMapping('child', ChildItem::class);
655+
$typeMapper->setMapping('master', MasterItem::class);
656+
$parser = $this->getItemParser($typeMapper);
657+
658+
$item = $parser->parse($this->getJsonApiItemMock('master', '1'));
659+
660+
$dataMeta = $item->getRelation('childwithdatameta')->getIncluded()->getDataMeta();
661+
static::assertInstanceOf(Meta::class, $dataMeta);
662+
663+
$image = $dataMeta->imageDerivatives->links->header->href;
664+
$this->assertEquals('https://example.com/image/header/about-us.jpeg', $image);
665+
}
666+
648667
/**
649668
* @param \Swis\JsonApi\Client\Interfaces\TypeMapperInterface|null $typeMapper
650669
*
@@ -766,6 +785,30 @@ private function getJsonApiItemMock($type, $id)
766785
'foo' => 'bar',
767786
],
768787
],
788+
'childwithdatameta' => [
789+
'data' => [
790+
'type' => 'child',
791+
'id' => '9',
792+
'meta' => [
793+
'alt' => '',
794+
'width' => 1920,
795+
'height' => 1280,
796+
'imageDerivatives' => [
797+
'links' => [
798+
'header' => [
799+
'href' => 'https://example.com/image/header/about-us.jpeg',
800+
'meta' => [
801+
'rel' => 'drupal://jsonapi/extensions/consumer_image_styles/links/relation-types/#derivative',
802+
],
803+
],
804+
],
805+
],
806+
],
807+
],
808+
'links' => [
809+
'self' => 'http://example.com/'.$type.'/'.$id.'/relationships/childwithdatameta',
810+
],
811+
],
769812
'empty' => [
770813
'data' => null,
771814
],

0 commit comments

Comments
 (0)