Skip to content

Commit 9218190

Browse files
committed
Merge remote-tracking branch 'adobe-commerce-tier-4/ACP2E-3044' into Tier4-Kings-PR-06-12-2024
2 parents 7240fc6 + 3d77487 commit 9218190

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

lib/internal/Magento/Framework/View/Layout.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra
3333
/**
3434
* Empty layout xml
3535
*/
36-
const LAYOUT_NODE = '<layout/>';
36+
public const LAYOUT_NODE = '<layout/>';
3737

3838
/**
3939
* Default cache life time
@@ -604,6 +604,9 @@ protected function _renderContainer($name, $useCache = true)
604604
$children = $this->getChildNames($name);
605605
foreach ($children as $child) {
606606
$html .= $this->renderElement($child, $useCache);
607+
if (ctype_space($html)) {
608+
$html = trim($html);
609+
}
607610
}
608611
if ($html == '' || !$this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG)) {
609612
return $html;

lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,45 @@ public function testRenderElementDoNotDisplay($displayValue): void
11491149
$this->assertEquals($blockHtml, $this->model->renderElement($name, false));
11501150
}
11511151

1152+
/**
1153+
* @param string $expectedResult
1154+
* @param string $blockHtml
1155+
*
1156+
* @return void
1157+
* @dataProvider trimWhitespaceContainingBlockHtmlDataProvider
1158+
*/
1159+
public function testTrimWhitespaceContainingBlockHtml($expectedResult, $blockHtml): void
1160+
{
1161+
$name = 'test_container';
1162+
$child = 'child_block';
1163+
$children = [$child => true];
1164+
$displayValue = true;
1165+
1166+
$this->structureMock->expects($this->atLeastOnce())
1167+
->method('getAttribute')
1168+
->willReturnMap(
1169+
[
1170+
[$name, 'display', $displayValue],
1171+
[$child, 'display', $displayValue],
1172+
[$child, 'type', Element::TYPE_BLOCK]
1173+
]
1174+
);
1175+
1176+
$this->structureMock->expects($this->atLeastOnce())->method('hasElement')
1177+
->willReturnMap([[$child, true]]);
1178+
1179+
$this->structureMock->expects($this->once())
1180+
->method('getChildren')
1181+
->with($name)
1182+
->willReturn($children);
1183+
1184+
$block = $this->createMock(AbstractBlock::class);
1185+
$block->expects($this->once())->method('toHtml')->willReturn($blockHtml);
1186+
1187+
$this->model->setBlock($child, $block);
1188+
$this->assertEquals($expectedResult, $this->model->renderElement($name, false));
1189+
}
1190+
11521191
/**
11531192
* @return array
11541193
*/
@@ -1161,6 +1200,17 @@ public static function renderElementDoNotDisplayDataProvider(): array
11611200
];
11621201
}
11631202

1203+
/**
1204+
* @return array
1205+
*/
1206+
public static function trimWhitespaceContainingBlockHtmlDataProvider(): array
1207+
{
1208+
return [
1209+
['', ' '],
1210+
[' <html/>', ' <html/>']
1211+
];
1212+
}
1213+
11641214
/**
11651215
* @return array
11661216
*/

0 commit comments

Comments
 (0)