Skip to content

Commit c506e59

Browse files
committed
Merge remote-tracking branch 'origin/MC-37348' into 2.4-develop-pr109
2 parents 070be8a + 594295d commit c506e59

File tree

3 files changed

+120
-5
lines changed

3 files changed

+120
-5
lines changed

app/code/Magento/PageBuilder/view/frontend/page_layout/product-full-width.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<block class="Magento\Framework\View\Element\Template" name="product.attributes.wrapper" template="Magento_PageBuilder::catalog/product/view/section_wrapper.phtml">
3838
<arguments>
3939
<argument name="title" translate="true" xsi:type="string">More Information</argument>
40+
<argument name="section_id" xsi:type="string">additional</argument>
4041
</arguments>
4142
<!-- Create a new instance of attributes which excludes Page Builder attributes -->
4243
<block class="Magento\PageBuilder\Block\Catalog\Block\Product\View\Attributes" name="product.attributes.exclude.pagebuilder" as="additional" template="Magento_Catalog::product/view/attributes.phtml">
@@ -48,6 +49,7 @@
4849
<block class="Magento\Framework\View\Element\Template" name="product.reviews.wrapper" after="product.attributes.wrapper" template="Magento_PageBuilder::catalog/product/view/section_wrapper.phtml">
4950
<arguments>
5051
<argument name="title" translate="true" xsi:type="string">Reviews</argument>
52+
<argument name="section_id" xsi:type="string">reviews</argument>
5153
</arguments>
5254
<block class="Magento\Review\Block\Product\View\ListView" name="product.info.product_additional_data.wrapper" template="Magento_Review::product/view/list.phtml" ifconfig="catalog/review/active">
5355
<arguments>

app/code/Magento/PageBuilder/view/frontend/templates/catalog/product/view/section_wrapper.phtml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@
77
/**
88
* Wrapper for product sections to include title
99
*
10-
* @var \Magento\Framework\View\Element\Template $block
10+
* @var Template $block
11+
* @var Escaper $escaper
1112
*/
13+
14+
use Magento\Framework\Escaper;
15+
use Magento\Framework\View\Element\Template;
16+
1217
$childHtml = $block->getChildHtml();
18+
$sectionId = $block->getSectionId();
19+
$sectionIdAttribute = $sectionId ? ' id="' . $escaper->escapeHtmlAttr($sectionId) . '"' : '';
1320
?>
14-
<?php if (trim($childHtml) !== "") : ?>
15-
<div class="product-full-width-section">
16-
<h2 class="product-section-title"><?= $block->escapeHtml($block->getTitle()); ?></h2>
21+
<?php if (trim($childHtml) !== ""): ?>
22+
<div class="product-full-width-section"<?= /* @noEscape */ $sectionIdAttribute ?>>
23+
<h2 class="product-section-title"><?= $escaper->escapeHtml($block->getTitle()); ?></h2>
1724
<?= $block->getChildHtml(); ?>
1825
</div>
19-
<?php endif; ?>
26+
<?php endif; ?>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageBuilder\Block\Catalog\Product;
9+
10+
use Magento\Framework\View\LayoutInterface;
11+
use Magento\Review\Block\Product\Review;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\Framework\View\Element\Template;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* PageBuilder Product view integration tests.
18+
*
19+
* @magentoAppArea frontend
20+
*/
21+
class ViewTest extends TestCase
22+
{
23+
/**
24+
* @var string
25+
*/
26+
private $wrapperTemplatePath = 'Magento_PageBuilder::catalog/product/view/%s';
27+
28+
/**
29+
* @var LayoutInterface
30+
*/
31+
private $layout;
32+
33+
/**
34+
* @inheritDoc
35+
*/
36+
protected function setUp(): void
37+
{
38+
$this->layout = Bootstrap::getObjectManager()->get(LayoutInterface::class);
39+
}
40+
41+
/**
42+
* Check that Section Wrapper page contains section ID if it was provided.
43+
*
44+
* @param string $sectionId
45+
* @return void
46+
* @dataProvider sectionWrapperDataProvider
47+
*/
48+
public function testSectionWrapperWithProvidedSectionId(string $sectionId): void
49+
{
50+
$wrapperBlock = $this->prepareSectionWrapperBlock();
51+
$wrapperBlock->setSectionId($sectionId);
52+
53+
$this->assertStringContainsString(sprintf('id="%s"', $sectionId), $wrapperBlock->toHtml());
54+
}
55+
56+
/**
57+
* Check that Section Wrapper page does NOT contain section ID if it was NOT provided.
58+
*
59+
* @param string $sectionId
60+
* @return void
61+
* @dataProvider sectionWrapperDataProvider
62+
*/
63+
public function testSectionWrapperWithoutSectionId(string $sectionId): void
64+
{
65+
$wrapperBlock = $this->prepareSectionWrapperBlock();
66+
67+
$this->assertStringNotContainsString(sprintf('id="%s"', $sectionId), $wrapperBlock->toHtml());
68+
}
69+
70+
/**
71+
* DataProvider for testSectionWrapper().
72+
*
73+
* @return array
74+
*/
75+
public function sectionWrapperDataProvider(): array
76+
{
77+
return [
78+
['description'],
79+
['additional'],
80+
['reviews'],
81+
];
82+
}
83+
84+
/**
85+
* Create and retrieve Section Wrapper block instance.
86+
*
87+
* @return Template
88+
*/
89+
private function prepareSectionWrapperBlock(): Template
90+
{
91+
/** @var Template $wrapperBlock */
92+
$wrapperBlock = $this->layout->createBlock(Template::class);
93+
$wrapperBlock->setTemplate(
94+
sprintf(
95+
$this->wrapperTemplatePath,
96+
'section_wrapper.phtml'
97+
)
98+
);
99+
/** @var Review $childReviewBlock */
100+
$childReviewBlock = $this->layout->createBlock(Review::class);
101+
$childReviewBlock->setTemplate('Magento_Review::review.phtml');
102+
$wrapperBlock->setChild('child.review', $childReviewBlock);
103+
104+
return $wrapperBlock;
105+
}
106+
}

0 commit comments

Comments
 (0)