Skip to content

Commit 205ee0f

Browse files
committed
MC-31499: [2.4] Re: Magento 2.3.4 | serious issues with local storage if custom sections.xml invalidations are active
1 parent 293cd41 commit 205ee0f

File tree

7 files changed

+175
-14
lines changed

7 files changed

+175
-14
lines changed

app/code/Magento/Customer/CustomerData/SectionConfigConverter.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Customer\CustomerData;
77

8+
/**
9+
* Class that receives xml merged source and process it.
10+
*/
811
class SectionConfigConverter implements \Magento\Framework\Config\ConverterInterface
912
{
1013
/**
@@ -13,18 +16,26 @@ class SectionConfigConverter implements \Magento\Framework\Config\ConverterInter
1316
const INVALIDATE_ALL_SECTIONS_MARKER = '*';
1417

1518
/**
16-
* {@inheritdoc}
19+
* @inheritdoc
1720
*/
1821
public function convert($source)
1922
{
2023
$sections = [];
2124
foreach ($source->getElementsByTagName('action') as $action) {
2225
$actionName = strtolower($action->getAttribute('name'));
2326
foreach ($action->getElementsByTagName('section') as $section) {
24-
$sections[$actionName][] = strtolower($section->getAttribute('name'));
27+
$sectionName = strtolower($section->getAttribute('name'));
28+
29+
if ($sectionName === self::INVALIDATE_ALL_SECTIONS_MARKER) {
30+
$sections[$actionName] = [];
31+
$sections[$actionName][] = self::INVALIDATE_ALL_SECTIONS_MARKER;
32+
break;
33+
} else {
34+
$sections[$actionName][] = $sectionName;
35+
}
2536
}
2637
if (!isset($sections[$actionName])) {
27-
$sections[$actionName] = self::INVALIDATE_ALL_SECTIONS_MARKER;
38+
$sections[$actionName][] = self::INVALIDATE_ALL_SECTIONS_MARKER;
2839
}
2940
}
3041
return [

app/code/Magento/Customer/Test/Unit/CustomerData/SectionConfigConverterTest.php

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Customer\Test\Unit\CustomerData;
88

9+
use Magento\Framework\App\Arguments\ValidationState;
910
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1011

1112
class SectionConfigConverterTest extends \PHPUnit\Framework\TestCase
@@ -19,27 +20,74 @@ class SectionConfigConverterTest extends \PHPUnit\Framework\TestCase
1920
/** @var \DOMDocument */
2021
protected $source;
2122

23+
/** @var \Magento\Framework\Config\Dom config merger */
24+
private $configMergerClass;
25+
26+
/** @var ValidationState */
27+
private $validationStateMock;
28+
2229
protected function setUp()
2330
{
2431
$this->source = new \DOMDocument();
2532
$this->objectManagerHelper = new ObjectManagerHelper($this);
2633
$this->converter = $this->objectManagerHelper->getObject(
2734
\Magento\Customer\CustomerData\SectionConfigConverter::class
2835
);
36+
$this->validationStateMock = $this->createMock(ValidationState::class);
37+
}
38+
39+
/**
40+
* Return newly created instance of a config merger
41+
*
42+
* @param string $mergerClass
43+
* @param string $initialContents
44+
* @return \Magento\Framework\Config\Dom
45+
* @throws \UnexpectedValueException
46+
*/
47+
private function createConfig($mergerClass, $initialContents)
48+
{
49+
$this->validationStateMock->method('isValidationRequired')->willReturn(\false);
50+
return new $mergerClass(
51+
$initialContents,
52+
$this->validationStateMock,
53+
[
54+
'/config/action' => 'name',
55+
'/config/action/section' => 'name',
56+
],
57+
null,
58+
null
59+
);
2960
}
3061

3162
public function testConvert()
3263
{
3364
$this->source->loadXML(file_get_contents(__DIR__ . '/_files/sections.xml'));
3465

66+
$this->configMergerClass = $this->createConfig(
67+
'Magento\Framework\Config\Dom',
68+
file_get_contents(__DIR__ . '/_files/sections.xml')
69+
);
70+
71+
$this->configMergerClass->merge(file_get_contents(__DIR__ . '/_files/sections2.xml'));
72+
3573
$this->assertEquals(
3674
[
3775
'sections' => [
38-
'customer/account/logout' => '*',
39-
'customer/account/editpost' => ['account'],
76+
'sales/guest/reorder' => ['account'],
77+
'sales/order/reorder' => ['account', 'cart'],
78+
'stores/store/switch' => ['*'],
79+
'directory/currency/switch' => ['*'],
80+
'customer/account/logout' => ['account', 'cart'],
81+
'customer/account/editpost' => ['account', 'acc', 'cart'],
82+
'checkout/cart/delete' => ['*'],
83+
'customer/account/createpost' => ['*'],
84+
'catalog/product_compare/add' => ['*'],
85+
'catalog/product_compare/remove' => ['account', 'acc'],
86+
'catalog/product_compare/clear' => ['*'],
87+
'checkout/cart/add' => ['*'],
4088
],
4189
],
42-
$this->converter->convert($this->source)
90+
$this->converter->convert($this->configMergerClass->getDom())
4391
);
4492
}
4593
}

app/code/Magento/Customer/Test/Unit/CustomerData/_files/sections.xml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,56 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
10-
<action name="customer/account/logout"/>
10+
<!-- Actions 1-4 are specified in sections.xml file only -->
11+
<!-- 1 - Action has one Section -->
12+
<action name="sales/guest/reorder">
13+
<section name="account"/>
14+
</action>
15+
<!-- 2 - Action has two Sections -->
16+
<action name="sales/order/reorder">
17+
<section name="account"/>
18+
<section name="cart"/>
19+
</action>
20+
<!-- 3 - Action has two Sections and "*" -->
21+
<action name="stores/store/switch">
22+
<section name="account"/>
23+
<section name="*"/>
24+
<section name="cart"/>
25+
</action>
26+
<!-- 4 - Action has "empty_section" -->
27+
<action name="directory/currency/switch"/>
28+
<!-- Actions 5-12 are specified in files sections.xml and sections2.xml for merging -->
29+
<!-- 5 - Action in both files has unique Section -->
30+
<action name="customer/account/logout">
31+
<section name="account"/>
32+
</action>
33+
<!-- 6 - Action in both files has at least one identical Section -->
1134
<action name="customer/account/editPost">
1235
<section name="account"/>
36+
<section name="acc"/>
37+
</action>
38+
<!-- 7 - Action in both files has at least one identical Section and "*" -->
39+
<action name="checkout/cart/delete">
40+
<section name="account"/>
41+
<section name="acc"/>
42+
</action>
43+
<!-- 8 - Action in both files has Section and "*" -->
44+
<action name="customer/account/createPost">
45+
<section name="account"/>
46+
</action>
47+
<!-- 9 - Action in both files has "*" and "*" -->
48+
<action name="catalog/product_compare/add">
49+
<section name="*"/>
50+
</action>
51+
<!-- 10 - Action in both files has Section and "empty_section" -->
52+
<action name="catalog/product_compare/remove">
53+
<section name="account"/>
54+
<section name="acc"/>
55+
</action>
56+
<!-- 11 - Action in both files has "empty_section" and "empty_section" -->
57+
<action name="catalog/product_compare/clear"/>
58+
<!-- 12 - Action in both files has "*" and "empty_section" -->
59+
<action name="checkout/cart/add">
60+
<section name="*"/>
1361
</action>
1462
</config>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
10+
<!-- Actions 5-12 are specified in files sections.xml and sections2.xml for merging -->
11+
<!-- 5 - Action in both files has unique Section -->
12+
<action name="customer/account/logout">
13+
<section name="cart"/>
14+
</action>
15+
<!-- 6 - Action in both files has at least one identical Section -->
16+
<action name="customer/account/editPost">
17+
<section name="cart"/>
18+
<section name="account"/>
19+
</action>
20+
<!-- 7 - Action in both files has at least one identical Section and "*" -->
21+
<action name="checkout/cart/delete">
22+
<section name="cart"/>
23+
<section name="*"/>
24+
<section name="account"/>
25+
</action>
26+
<!-- 8 - Action in both files has Section and "*" -->
27+
<action name="customer/account/createPost">
28+
<section name="*"/>
29+
</action>
30+
<!-- 9 - Action in both files has "*" and "*" -->
31+
<action name="catalog/product_compare/add">
32+
<section name="*"/>
33+
</action>
34+
<!-- 10 - Action in both files has Section and "empty_section" -->
35+
<action name="catalog/product_compare/remove"/>
36+
<!-- 11 - Action in both files has "empty_section" and "empty_section" -->
37+
<action name="catalog/product_compare/clear"/>
38+
<!-- 12 - Action in both files has "*" and "empty_section" -->
39+
<action name="checkout/cart/add"/>
40+
</config>

app/code/Magento/Customer/etc/frontend/sections.xml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
10-
<action name="customer/account/logout"/>
11-
<action name="customer/account/loginPost"/>
12-
<action name="customer/account/createPost"/>
13-
<action name="customer/account/editPost"/>
10+
<action name="customer/account/logout">
11+
<section name="*"/>
12+
</action>
13+
<action name="customer/account/loginPost">
14+
<section name="*"/>
15+
</action>
16+
<action name="customer/account/createPost">
17+
<section name="*"/>
18+
</action>
19+
<action name="customer/account/editPost">
20+
<section name="*"/>
21+
</action>
1422
<action name="customer/ajax/login">
1523
<section name="checkout-data"/>
1624
<section name="cart"/>

app/code/Magento/Directory/etc/frontend/sections.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
10-
<action name="directory/currency/switch"/>
10+
<action name="directory/currency/switch">
11+
<section name="*"/>
12+
</action>
1113
</config>

app/code/Magento/Store/etc/frontend/sections.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
10-
<action name="stores/store/switch"/>
11-
<action name="stores/store/switchrequest"/>
10+
<action name="stores/store/switch">
11+
<section name="*"/>
12+
</action>
13+
<action name="stores/store/switchrequest">
14+
<section name="*"/>
15+
</action>
1216
</config>

0 commit comments

Comments
 (0)