From 24389993278cb05d5ec299bc0609cebfce14e065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Chrastina?= Date: Fri, 29 Oct 2021 19:33:05 +0200 Subject: [PATCH] extend resolution --- src/Kentico/Kontent/Delivery/DefaultMapper.php | 3 ++- .../Kontent/Delivery/InlineLinkedItemsResolverInterface.php | 3 ++- src/Kentico/Kontent/Delivery/ModelBinder.php | 2 +- tests/Unit/DefaultMapperTest.php | 4 ++-- tests/Unit/ModelBinderTest.php | 6 ++++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Kentico/Kontent/Delivery/DefaultMapper.php b/src/Kentico/Kontent/Delivery/DefaultMapper.php index c14b491..a51cbc8 100644 --- a/src/Kentico/Kontent/Delivery/DefaultMapper.php +++ b/src/Kentico/Kontent/Delivery/DefaultMapper.php @@ -176,10 +176,11 @@ public function resolveBrokenLinkUrl() * * @param string $input input html of inline linked items. * @param mixed $item data for inline linked items. + * @param mixed|null $linkedItems JSON response containing nested linked items * * @return string */ - public function resolveInlineLinkedItems($input, $item) + public function resolveInlineLinkedItems($input, $item, $linkedItems) { if(isset($item) && strpos($input, $item->system->codename) !== false){ return $input; diff --git a/src/Kentico/Kontent/Delivery/InlineLinkedItemsResolverInterface.php b/src/Kentico/Kontent/Delivery/InlineLinkedItemsResolverInterface.php index 8e7f57c..6e35765 100644 --- a/src/Kentico/Kontent/Delivery/InlineLinkedItemsResolverInterface.php +++ b/src/Kentico/Kontent/Delivery/InlineLinkedItemsResolverInterface.php @@ -15,8 +15,9 @@ interface InlineLinkedItemsResolverInterface * * @param string $input input html of inline linked items. * @param mixed $item data for inline linked items. + * @param mixed|null $linkedItems JSON response containing nested linked items * * @return string */ - public function resolveInlineLinkedItems($input, $item); + public function resolveInlineLinkedItems($input, $item, $linkedItems); } diff --git a/src/Kentico/Kontent/Delivery/ModelBinder.php b/src/Kentico/Kontent/Delivery/ModelBinder.php index 6808ded..cf81dbc 100644 --- a/src/Kentico/Kontent/Delivery/ModelBinder.php +++ b/src/Kentico/Kontent/Delivery/ModelBinder.php @@ -295,7 +295,7 @@ private function resolveLinkedItem($linkedItem, $linkedItems, $processedItems) $linkedItemsArray = get_object_vars($linkedItems); $linkedItemData = array_merge($linkedItemsArray, $processedItems); if (isset($linkedItemData[$itemCodeName])) { - $linkedItem->outertext = $this->inlineLinkedItemsResolver->resolveInlineLinkedItems($linkedItem->outertext, $linkedItemData[$itemCodeName]); + $linkedItem->outertext = $this->inlineLinkedItemsResolver->resolveInlineLinkedItems($linkedItem->outertext, $linkedItemData[$itemCodeName], $linkedItems); } } return $linkedItem->outertext; diff --git a/tests/Unit/DefaultMapperTest.php b/tests/Unit/DefaultMapperTest.php index f075b92..3bd0d06 100644 --- a/tests/Unit/DefaultMapperTest.php +++ b/tests/Unit/DefaultMapperTest.php @@ -62,7 +62,7 @@ public function test_ResolveInlineLinkedItems_ItemNull_returnEmptyString() { $mapper = new DefaultMapper(); $input = ''; - $result = $mapper->resolveInlineLinkedItems($input, null); + $result = $mapper->resolveInlineLinkedItems($input, null, null); $this->assertTrue(is_string($result)); $this->assertEmpty($result); @@ -74,7 +74,7 @@ public function test_ResolveInlineLinkedItems_ItemValid_returnInput() $input = ''; $itemJson = file_get_contents('./tests/Unit/Data/SimpleItem.json'); $item = json_decode($itemJson); - $result = $mapper->resolveInlineLinkedItems($input, $item); + $result = $mapper->resolveInlineLinkedItems($input, $item, null); $this->assertTrue(is_string($result)); $this->assertEquals($input, $result); diff --git a/tests/Unit/ModelBinderTest.php b/tests/Unit/ModelBinderTest.php index 9678125..710e4ca 100644 --- a/tests/Unit/ModelBinderTest.php +++ b/tests/Unit/ModelBinderTest.php @@ -81,7 +81,8 @@ public function test_BindModel_MockImplementation_InlineLinkedItemsResolved() $inlineLinkedItemsResolver ->expects($this->exactly(3)) ->method('resolveInlineLinkedItems') - ->will($this->returnCallback(function ($input, $item) { + ->will($this->returnCallback(function ($input, $item, $linkedItems) { + $this->assertCount(2, get_object_vars($linkedItems)); return '
' . $item->system->name . '
'; })); @@ -120,7 +121,8 @@ public function test_BindModel_MockImplementation_WorkflowStepNotSetForComponent $inlineLinkedItemsResolver ->expects($this->exactly(2)) ->method('resolveInlineLinkedItems') - ->will($this->returnCallback(function ($input, $item) { + ->will($this->returnCallback(function ($input, $item, $linkedItems) { + $this->assertCount(2, get_object_vars($linkedItems)); if($item->system->codename == 'n8bf1055d_7b61_0180_e1c6_3a09d88f0396') { $this->assertFalse(isset($item->system->workflow_step)); } else {