Skip to content

Commit f34018a

Browse files
authored
Merge pull request #352 from magento-obsessive-owls/PB-317
[Owls] PB-317: Saving PageBuilder Content w/ Background Images on Edge Will Results in No Images on Storefront
2 parents dfd18e7 + 87503aa commit f34018a

File tree

2 files changed

+113
-1
lines changed

2 files changed

+113
-1
lines changed

app/code/Magento/PageBuilder/Plugin/Filter/TemplatePlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
class TemplatePlugin
1414
{
15-
const BACKGROUND_IMAGE_PATTERN = '/data-background-images=\"{[^"]+}\"/si';
15+
const BACKGROUND_IMAGE_PATTERN = '/data-background-images=(?:\'|"){.+}(?:\'|")/si';
1616

1717
const HTML_CONTENT_TYPE_PATTERN = '/data-content-type="html"/si';
1818

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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\Model\Filter;
9+
10+
use Magento\TestFramework\ObjectManager;
11+
12+
class TemplateTest extends \PHPUnit\Framework\TestCase
13+
{
14+
/**
15+
* @var Template
16+
*/
17+
private $templateFilter;
18+
19+
protected function setUp()
20+
{
21+
$this->templateFilter = ObjectManager::getInstance()->create(Template::class);
22+
}
23+
24+
/**
25+
* @param string $results
26+
* @param bool $contains
27+
* @param string $value
28+
* @dataProvider getFilterForDataProvider
29+
*/
30+
public function testFilterFor(string $results, bool $contains, string $value)
31+
{
32+
$contains ?
33+
self::assertContains($results, $this->templateFilter->filter($value)) :
34+
self::assertNotContains($results, $this->templateFilter->filter($value));
35+
}
36+
37+
/**
38+
* @return array
39+
*/
40+
public function getFilterForDataProvider() : array
41+
{
42+
$template = <<<TEMPLATE
43+
<div data-content-type="row" data-appearance="contained" data-element="main">
44+
<div data-enable-parallax="0" data-parallax-speed="0.5"
45+
data-background-images="{\&quot;desktop_image\&quot;:\&quot;{{media url=jb-decorating.jpg}}\&quot;}"
46+
data-element="inner" style="justify-content: flex-start; display: flex; flex-direction: column;
47+
background-position: center center; background-size: cover; background-repeat: repeat;
48+
background-attachment: scroll; border-style: none; border-width: 1px; border-radius: 0px; min-height: 350px;
49+
margin: 0px 0px 10px; padding: 10px;"></div>
50+
</div>
51+
TEMPLATE;
52+
53+
$template2 = <<<TEMPLATE
54+
<div data-content-type="row" data-element="main" data-appearance="contained">
55+
<div style="background-position: center; border-width: 1px; border-style: none; margin: 0px 0px 10px;
56+
padding: 10px; border-radius: 0px; background-repeat: repeat; background-attachment: scroll; display: flex;
57+
min-height: 350px; background-size: cover; flex-direction: column; justify-content: flex-start;"
58+
data-element="inner" data-background-images='{\"desktop_image\":\"{{media url=jb-decorating.jpg}}\"}'
59+
data-parallax-speed="0.5" data-enable-parallax="0"></div>
60+
</div>
61+
TEMPLATE;
62+
63+
$template3 = <<<TEMPLATE
64+
<div data-content-type="row" data-element="main" data-appearance="contained">
65+
<div style="background-position: center; border-width: 1px; border-style: none; margin: 0px 0px 10px;
66+
padding: 10px; border-radius: 0px; background-repeat: repeat; background-attachment: scroll; display: flex;
67+
min-height: 350px; background-size: cover; flex-direction: column; justify-content: flex-start;"
68+
data-element="inner" data-background-images='{}' data-parallax-speed="0.5" data-enable-parallax="0"></div>
69+
</div>
70+
TEMPLATE;
71+
72+
$expectedResult = <<<EXPECTED_RESULT
73+
<style type="text/css">.background-image-
74+
EXPECTED_RESULT;
75+
76+
$expectedResult2 = <<<EXPECTED_RESULT
77+
class="background-image-
78+
EXPECTED_RESULT;
79+
return [
80+
[
81+
$expectedResult,
82+
true,
83+
$template
84+
],
85+
[
86+
$expectedResult2,
87+
true,
88+
$template
89+
],
90+
[
91+
$expectedResult,
92+
true,
93+
$template2
94+
],
95+
[
96+
$expectedResult2,
97+
true,
98+
$template2
99+
],
100+
[
101+
$expectedResult,
102+
false,
103+
$template3
104+
],
105+
[
106+
$expectedResult2,
107+
false,
108+
$template3
109+
],
110+
];
111+
}
112+
}

0 commit comments

Comments
 (0)