Skip to content

Commit 8f427bc

Browse files
committed
Merge remote-tracking branch 'local/ACP2E-2392' into PR_L3_March_24
2 parents 0c59b60 + 83643e2 commit 8f427bc

File tree

4 files changed

+99
-3
lines changed

4 files changed

+99
-3
lines changed

app/code/Magento/Catalog/Block/Widget/RecentlyViewed.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
*/
1414
class RecentlyViewed extends Wrapper implements \Magento\Widget\Block\BlockInterface
1515
{
16+
protected const RENDER_TYPE = 'html';
1617
}

app/code/Magento/Ui/Block/Wrapper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*/
1515
class Wrapper extends \Magento\Framework\View\Element\Template
1616
{
17+
protected const RENDER_TYPE = '';
18+
1719
/**
1820
* @var UiComponentGenerator
1921
*/
@@ -91,6 +93,6 @@ public function renderApp($data = [])
9193
->generateUiComponent($this->getData('uiComponent'), $this->getLayout());
9294
$this->injectDataInDataSource($uiComponent, $this->getData());
9395
$this->addDataToChildComponents($uiComponent, $data);
94-
return (string) $uiComponent->render();
96+
return (string) $uiComponent->render(static::RENDER_TYPE);
9597
}
9698
}

app/code/Magento/Ui/Component/Listing.php

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Ui\Component;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\View\Element\UiComponent\ContentType\ContentTypeFactory;
10+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
811
use Magento\Ui\Component\Listing\Columns;
912

1013
/**
@@ -13,13 +16,34 @@
1316
*/
1417
class Listing extends AbstractComponent
1518
{
16-
const NAME = 'listing';
19+
public const NAME = 'listing';
1720

1821
/**
1922
* @var array
2023
*/
2124
protected $columns = [];
2225

26+
/**
27+
* @var ContentTypeFactory
28+
*/
29+
private ContentTypeFactory $contentTypeFactory;
30+
31+
/**
32+
* @param ContextInterface $context
33+
* @param array $components
34+
* @param array $data
35+
* @param ContentTypeFactory|null $contentTypeFactory
36+
*/
37+
public function __construct(
38+
ContextInterface $context,
39+
array $components = [],
40+
array $data = [],
41+
?ContentTypeFactory $contentTypeFactory = null
42+
) {
43+
$this->contentTypeFactory = $contentTypeFactory ?: ObjectManager::getInstance()->get(ContentTypeFactory::class);
44+
parent::__construct($context, $components, $data);
45+
}
46+
2347
/**
2448
* Get component name
2549
*
@@ -31,10 +55,25 @@ public function getComponentName()
3155
}
3256

3357
/**
34-
* {@inheritdoc}
58+
* @inheritdoc
3559
*/
3660
public function getDataSourceData()
3761
{
3862
return ['data' => $this->getContext()->getDataProvider()->getData()];
3963
}
64+
65+
/**
66+
* Render content depending on specified type
67+
*
68+
* @param string $contentType
69+
* @return string
70+
*/
71+
public function render(string $contentType = '')
72+
{
73+
if ($contentType) {
74+
return $this->contentTypeFactory->get($contentType)->render($this, $this->getTemplate());
75+
}
76+
77+
return parent::render();
78+
}
4079
}

app/code/Magento/Ui/Test/Unit/Component/ListingTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
namespace Magento\Ui\Test\Unit\Component;
99

1010
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
11+
use Magento\Framework\View\Element\UiComponent\ContentType\AbstractContentType;
12+
use Magento\Framework\View\Element\UiComponent\ContentType\ContentTypeFactory;
13+
use Magento\Framework\View\Element\UiComponent\ContentType\Html;
1114
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1215
use Magento\Framework\View\Element\UiComponent\Processor;
1316
use Magento\Ui\Component\Listing;
@@ -26,6 +29,11 @@ class ListingTest extends TestCase
2629
*/
2730
protected $objectManager;
2831

32+
/**
33+
* @var ContentTypeFactory|MockObject
34+
*/
35+
private ContentTypeFactory $contentTypeFactory;
36+
2937
/**
3038
* @inheritdoc
3139
*/
@@ -39,6 +47,8 @@ protected function setUp(): void
3947
'',
4048
false
4149
);
50+
51+
$this->contentTypeFactory = $this->createMock(ContentTypeFactory::class);
4252
}
4353

4454
/**
@@ -103,4 +113,48 @@ public function testPrepare(): void
103113

104114
$listing->prepare();
105115
}
116+
117+
/**
118+
* @return void
119+
*/
120+
public function testRenderSpecificContentType(): void
121+
{
122+
$html = 'html output';
123+
$renderer = $this->createMock(Html::class);
124+
$renderer->expects($this->once())->method('render')->willReturn($html);
125+
$this->contentTypeFactory->expects($this->once())
126+
->method('get')
127+
->with('html')
128+
->willReturn($renderer);
129+
130+
/** @var Listing $listing */
131+
$listing = $this->objectManager->getObject(
132+
Listing::class,
133+
[
134+
'context' => $this->contextMock,
135+
'contentTypeFactory' => $this->contentTypeFactory
136+
]
137+
);
138+
$this->assertSame($html, $listing->render('html'));
139+
}
140+
141+
/**
142+
* @return void
143+
*/
144+
public function testRenderParent()
145+
{
146+
$html = 'html output';
147+
$renderer = $this->createMock(AbstractContentType::class);
148+
$renderer->expects($this->once())->method('render')->willReturn($html);
149+
$this->contextMock->expects($this->once())->method('getRenderEngine')->willReturn($renderer);
150+
151+
/** @var Listing $listing */
152+
$listing = $this->objectManager->getObject(
153+
Listing::class,
154+
[
155+
'context' => $this->contextMock
156+
]
157+
);
158+
$this->assertSame($html, $listing->render());
159+
}
106160
}

0 commit comments

Comments
 (0)