Skip to content

Commit 7751230

Browse files
authored
Merge branch 'develop' into fix-child-content-finding
2 parents 5bf6a55 + ae2cdeb commit 7751230

File tree

11 files changed

+216
-16
lines changed

11 files changed

+216
-16
lines changed

app/code/Magento/PageBuilder/Model/Stage/HtmlFilter.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,43 @@ public function filterHtml(string $content): string
7878
);
7979
foreach ($htmlContentTypes as $htmlContentType) {
8080
/* @var \DOMElement $htmlContentType */
81-
$innerHTML = '';
82-
$children = $htmlContentType->childNodes;
83-
foreach ($children as $child) {
84-
$innerHTML .= $child->ownerDocument->saveXML($child);
85-
}
8681
$htmlContentType->setAttribute(
8782
"class",
8883
$htmlContentType->getAttribute("class") . " placeholder-html-code"
8984
);
85+
86+
$innerHTML = $this->getChildrenInnerHtml($htmlContentType);
87+
9088
$htmlContentType->nodeValue = htmlentities($innerHTML);
9189
}
9290
return substr(trim($dom->saveHTML()), 5, -6);
9391
}
92+
93+
/**
94+
* Get inner HTML of element's children
95+
*
96+
* @param \DOMElement $element
97+
* @return string
98+
*/
99+
private function getChildrenInnerHtml(\DOMElement $element): string
100+
{
101+
$innerHTML = '';
102+
$childrenIterator = $element->childNodes->getIterator();
103+
while ($childrenIterator->valid()) {
104+
$child = $childrenIterator->current();
105+
try {
106+
$ownerDocument = $child->ownerDocument;
107+
} catch (\Error $error) {
108+
$ownerDocument = null;
109+
$this->loggerInterface->critical($error->getMessage());
110+
}
111+
if ($ownerDocument === null) {
112+
$childrenIterator->next();
113+
continue;
114+
}
115+
$innerHTML .= $ownerDocument->saveXML($child);
116+
$childrenIterator->next();
117+
}
118+
return $innerHTML;
119+
}
94120
}

app/code/Magento/PageBuilder/Test/Unit/Model/Filter/TemplateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testFilter(string $input, string $output): void
6161
/**
6262
* @return array
6363
*/
64-
public function filterProvider(): array
64+
public static function filterProvider(): array
6565
{
6666
return [
6767
[

app/code/Magento/PageBuilder/Test/Unit/Model/Session/RandomKeyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function ($length) {
8484
/**
8585
* @return array[]
8686
*/
87-
public function getValueDataProvider(): array
87+
public static function getValueDataProvider(): array
8888
{
8989
return [
9090
[
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageBuilder\Test\Unit\Model\Stage;
9+
10+
use Magento\PageBuilder\Model\Stage\HtmlFilter;
11+
use PHPUnit\Framework\MockObject\MockObject;
12+
use PHPUnit\Framework\TestCase;
13+
use Psr\Log\LoggerInterface;
14+
15+
class HtmlFilterTest extends TestCase
16+
{
17+
/**
18+
* @var LoggerInterface|MockObject
19+
*/
20+
private $loggerMock;
21+
22+
/**
23+
* @var HtmlFilter
24+
*/
25+
private $htmlFilter;
26+
27+
protected function setUp(): void
28+
{
29+
$this->loggerMock = $this->createMock(LoggerInterface::class);
30+
$this->htmlFilter = new HtmlFilter($this->loggerMock);
31+
}
32+
33+
public function testFilterHtml()
34+
{
35+
//test for script tag
36+
$inputHtml = '<div><script type="text/x-magento-init">alert("test")</script><p>Content</p></div>';
37+
$expectedOutput = '<div><p>Content</p></div>';
38+
39+
$result = $this->htmlFilter->filterHtml($inputHtml);
40+
$this->assertEquals($expectedOutput, $result);
41+
42+
//test for PB placeholder
43+
$inputHtml = '
44+
<div data-content-type="html" data-appearance="default" data-element="main" class="test">
45+
<div class="block-123">Test</div>
46+
</div>';
47+
$expectedOutput = '
48+
<div data-content-type="html" data-appearance="default" data-element="main" class="test placeholder-html-code">
49+
&lt;div class="block-123"&gt;Test&lt;/div&gt;
50+
</div>';
51+
52+
$result = $this->htmlFilter->filterHtml($inputHtml);
53+
$this->assertEquals($expectedOutput, $result);
54+
}
55+
}

app/code/Magento/PageBuilder/Test/Unit/Model/WidgetInitializerConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testGetConfig(array $config, array $expectedConfig): void
3535
/**
3636
* @return array
3737
*/
38-
public function configProvider(): array
38+
public static function configProvider(): array
3939
{
4040
return [
4141
[

app/code/Magento/PageBuilder/Test/Unit/Plugin/ClearEditorConfigCacheTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testAfterLogin(bool $isUseSecretKey): void
7373
/**
7474
* @return array
7575
*/
76-
public function afterLoginDataProvider(): array
76+
public static function afterLoginDataProvider(): array
7777
{
7878
return [
7979
[false],

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/provider.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
define([
77
'Magento_Ui/js/form/provider',
8-
'Magento_PageBuilder/js/events'
9-
], function (Provider, events) {
8+
'Magento_PageBuilder/js/events',
9+
'jquery'
10+
], function (Provider, events, $) {
1011
'use strict';
1112

1213
return Provider.extend({
@@ -18,8 +19,42 @@ define([
1819
/** @inheritdoc **/
1920
save: function () {
2021
events.trigger('form:' + this.id + ':saveAfter', this.get('data'));
22+
this._refreshSlickOnSave();
2123

2224
return this;
25+
},
26+
27+
/**
28+
* Refresh slick slide of parent window
29+
*
30+
* @private
31+
*/
32+
_refreshSlickOnSave: function () {
33+
let slickObj = $('.slick-list.draggable'),
34+
parentSlick,
35+
currentSettings;
36+
37+
if (slickObj.length === 0) {
38+
return;
39+
}
40+
41+
parentSlick = slickObj.parent();
42+
43+
if (typeof parentSlick.slick !== 'function') {
44+
return;
45+
}
46+
47+
currentSettings = parentSlick.slick('getSlick').options;
48+
49+
if (!currentSettings.infinite) {
50+
return;
51+
}
52+
53+
if (currentSettings.rows > 0) {
54+
parentSlick.slick('slickSetOption', 'rows', 0);
55+
}
56+
57+
parentSlick.slick('refresh');
2358
}
2459
});
2560
});

dev/tests/integration/testsuite/Magento/CmsPageBuilderAnalytics/Model/ContentTypeUsageReportProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testGetReport($expectedReportData, $ignoredContentTypes)
6666
/**
6767
* @return array
6868
*/
69-
public function reportDataProvider(): array
69+
public static function reportDataProvider(): array
7070
{
7171
return [
7272
[

dev/tests/integration/testsuite/Magento/PageBuilder/Block/Catalog/Product/ViewTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function testSectionWrapperWithoutSectionId(string $sectionId): void
7272
*
7373
* @return array
7474
*/
75-
public function sectionWrapperDataProvider(): array
75+
public static function sectionWrapperDataProvider(): array
7676
{
7777
return [
7878
['description'],

dev/tests/integration/testsuite/Magento/PageBuilder/CatalogWidget/Block/Product/ProductListTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function testCategoryFilterAndSort(array $categories, int $categoryId, st
153153
/**
154154
* @return array
155155
*/
156-
public function priceFilterDataProvider(): array
156+
public static function priceFilterDataProvider(): array
157157
{
158158
return [
159159
[
@@ -189,7 +189,7 @@ public function priceFilterDataProvider(): array
189189
/**
190190
* @return array
191191
*/
192-
public function priceSortDataProvider(): array
192+
public static function priceSortDataProvider(): array
193193
{
194194
return [
195195
[
@@ -212,7 +212,7 @@ public function priceSortDataProvider(): array
212212
/**
213213
* @return array
214214
*/
215-
public function categoryFilterAndSortDataProvider(): array
215+
public static function categoryFilterAndSortDataProvider(): array
216216
{
217217
$categories = [
218218
//Category 1

0 commit comments

Comments
 (0)