Skip to content

Commit e391757

Browse files
authored
Merge pull request #4241 from magento-plankton/MC-16880-1
2 parents 9ec0aec + d8f9d70 commit e391757

File tree

7 files changed

+101
-66
lines changed

7 files changed

+101
-66
lines changed

dev/tests/integration/testsuite/Magento/Framework/Search/_files/search_request_merged.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
'match_query' => [
3636
'value' => '$match_term_override$',
3737
'name' => 'match_query',
38-
'boost' => '1',
3938
'match' => [
4039
0 => [
4140
'field' => 'match_field',
@@ -51,7 +50,6 @@
5150
],
5251
'must_query' => [
5352
'name' => 'must_query',
54-
'boost' => '1',
5553
'filterReference' => [
5654
0 => [
5755
'clause' => 'must',
@@ -62,7 +60,6 @@
6260
],
6361
'should_query' => [
6462
'name' => 'should_query',
65-
'boost' => '1',
6663
'filterReference' => [
6764
0 => [
6865
'clause' => 'should',
@@ -73,7 +70,6 @@
7370
],
7471
'not_query' => [
7572
'name' => 'not_query',
76-
'boost' => '1',
7773
'filterReference' => [
7874
0 => [
7975
'clause' => 'not',
@@ -84,7 +80,6 @@
8480
],
8581
'match_query_2' => [
8682
'value' => '$match_term_override$',
87-
'boost' => '1',
8883
'name' => 'match_query_2',
8984
'match' => [
9085
0 => [
@@ -168,7 +163,6 @@
168163
'queries' => [
169164
'filter_query' => [
170165
'name' => 'filter_query',
171-
'boost' => '1',
172166
'filterReference' => [
173167
0 =>
174168
[
@@ -236,7 +230,6 @@
236230
'new_match_query' => [
237231
'value' => '$match_term$',
238232
'name' => 'new_match_query',
239-
'boost' => '1',
240233
'match' => [
241234
0 =>
242235
[

dev/tests/integration/testsuite/Magento/Framework/View/Layout/MergeTest.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ class MergeTest extends \PHPUnit\Framework\TestCase
4141
*/
4242
protected $_cache;
4343

44+
/**
45+
* @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
protected $_serializer;
48+
4449
/**
4550
* @var \PHPUnit_Framework_MockObject_MockObject
4651
*/
@@ -74,7 +79,8 @@ class MergeTest extends \PHPUnit\Framework\TestCase
7479
protected function setUp()
7580
{
7681
$files = [];
77-
foreach (glob(__DIR__ . '/_mergeFiles/layout/*.xml') as $filename) {
82+
$fileDriver = new \Magento\Framework\Filesystem\Driver\File();
83+
foreach ($fileDriver->readDirectory(__DIR__ . '/_mergeFiles/layout/') as $filename) {
7884
$files[] = new \Magento\Framework\View\File($filename, 'Magento_Widget');
7985
}
8086
$fileSource = $this->getMockForAbstractClass(\Magento\Framework\View\File\CollectorInterface::class);
@@ -100,6 +106,8 @@ protected function setUp()
100106

101107
$this->_cache = $this->getMockForAbstractClass(\Magento\Framework\Cache\FrontendInterface::class);
102108

109+
$this->_serializer = $this->getMockForAbstractClass(\Magento\Framework\Serialize\SerializerInterface::class);
110+
103111
$this->_theme = $this->createMock(\Magento\Theme\Model\Theme::class);
104112
$this->_theme->expects($this->any())->method('isPhysical')->will($this->returnValue(true));
105113
$this->_theme->expects($this->any())->method('getArea')->will($this->returnValue('area'));
@@ -140,6 +148,7 @@ function ($filename) use ($fileDriver) {
140148
'resource' => $this->_resource,
141149
'appState' => $this->_appState,
142150
'cache' => $this->_cache,
151+
'serializer' => $this->_serializer,
143152
'theme' => $this->_theme,
144153
'validator' => $this->_layoutValidator,
145154
'logger' => $this->_logger,
@@ -276,9 +285,16 @@ public function testLoadFileSystemWithPageLayout()
276285

277286
public function testLoadCache()
278287
{
288+
$cacheValue = [
289+
"pageLayout" => "1column",
290+
"layout" => self::FIXTURE_LAYOUT_XML
291+
];
292+
279293
$this->_cache->expects($this->at(0))->method('load')
280-
->with('LAYOUT_area_STORE20_100c6a4ccd050e33acef0553f24ef399961')
281-
->will($this->returnValue(self::FIXTURE_LAYOUT_XML));
294+
->with('LAYOUT_area_STORE20_100c6a4ccd050e33acef0553f24ef399961_page_layout_merged')
295+
->will($this->returnValue(json_encode($cacheValue)));
296+
297+
$this->_serializer->expects($this->once())->method('unserialize')->willReturn($cacheValue);
282298

283299
$this->assertEmpty($this->_model->getHandles());
284300
$this->assertEmpty($this->_model->asString());
@@ -424,8 +440,10 @@ public function testLoadWithInvalidLayout()
424440
->method('isValid')
425441
->willThrowException(new \Exception('Layout is invalid.'));
426442

443+
// phpcs:ignore Magento2.Security.InsecureFunction
427444
$suffix = md5(implode('|', $this->_model->getHandles()));
428-
$cacheId = "LAYOUT_{$this->_theme->getArea()}_STORE{$this->scope->getId()}_{$this->_theme->getId()}{$suffix}";
445+
$cacheId = "LAYOUT_{$this->_theme->getArea()}_STORE{$this->scope->getId()}"
446+
. "_{$this->_theme->getId()}{$suffix}_page_layout_merged";
429447
$messages = $this->_layoutValidator->getMessages();
430448

431449
// Testing error message is logged with logger

lib/internal/Magento/Framework/Config/Dom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public static function validateDomDocument(
379379
libxml_set_external_entity_loader([self::$urnResolver, 'registerEntityLoader']);
380380
$errors = [];
381381
try {
382-
$result = $dom->schemaValidate($schema, LIBXML_SCHEMA_CREATE);
382+
$result = $dom->schemaValidate($schema);
383383
if (!$result) {
384384
$errors = self::getXmlErrors($errorFormat);
385385
}

lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -169,48 +169,6 @@ public function validateDataProvider()
169169
];
170170
}
171171

172-
/**
173-
* @param string $xml
174-
* @param string $expectedValue
175-
* @dataProvider validateWithDefaultValueDataProvider
176-
*/
177-
public function testValidateWithDefaultValue($xml, $expectedValue)
178-
{
179-
if (!function_exists('libxml_set_external_entity_loader')) {
180-
$this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
181-
}
182-
183-
$actualErrors = [];
184-
185-
$dom = new \Magento\Framework\Config\Dom($xml, $this->validationStateMock);
186-
$dom->validate(__DIR__ . '/_files/sample.xsd', $actualErrors);
187-
188-
$actualValue = $dom->getDom()
189-
->getElementsByTagName('root')->item(0)
190-
->getElementsByTagName('node')->item(0)
191-
->getAttribute('attribute_with_default_value');
192-
193-
$this->assertEmpty($actualErrors);
194-
$this->assertEquals($expectedValue, $actualValue);
195-
}
196-
197-
/**
198-
* @return array
199-
*/
200-
public function validateWithDefaultValueDataProvider()
201-
{
202-
return [
203-
'default_value' => [
204-
'<root><node id="id1"/></root>',
205-
'default_value'
206-
],
207-
'custom_value' => [
208-
'<root><node id="id1" attribute_with_default_value="non_default_value"/></root>',
209-
'non_default_value'
210-
],
211-
];
212-
}
213-
214172
public function testValidateCustomErrorFormat()
215173
{
216174
$xml = '<root><unknown_node/></root>';

lib/internal/Magento/Framework/Config/Test/Unit/_files/sample.xsd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
<xs:simpleContent>
2222
<xs:extension base="xs:string">
2323
<xs:attribute name="id" type="xs:string" use="required"/>
24-
<xs:attribute name="attribute_with_default_value" type="xs:string" default="default_value"/>
2524
</xs:extension>
2625
</xs:simpleContent>
2726
</xs:complexType>

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

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
*/
66
namespace Magento\Framework\View\Model\Layout;
77

8+
use Magento\Framework\App\ObjectManager;
89
use Magento\Framework\App\State;
910
use Magento\Framework\Config\Dom\ValidationException;
1011
use Magento\Framework\Filesystem\DriverPool;
1112
use Magento\Framework\Filesystem\File\ReadFactory;
13+
use Magento\Framework\Serialize\SerializerInterface;
1214
use Magento\Framework\View\Layout\LayoutCacheKeyInterface;
1315
use Magento\Framework\View\Model\Layout\Update\Validator;
1416

@@ -42,7 +44,7 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface
4244
/**
4345
* Cache id suffix for page layout
4446
*/
45-
const PAGE_LAYOUT_CACHE_SUFFIX = 'page_layout';
47+
const PAGE_LAYOUT_CACHE_SUFFIX = 'page_layout_merged';
4648

4749
/**
4850
* @var \Magento\Framework\View\Design\ThemeInterface
@@ -54,6 +56,11 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface
5456
*/
5557
private $scope;
5658

59+
/**
60+
* @var SerializerInterface
61+
*/
62+
private $serializer;
63+
5764
/**
5865
* In-memory cache for loaded layout updates
5966
*
@@ -173,10 +180,11 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface
173180
* @param \Magento\Framework\Cache\FrontendInterface $cache
174181
* @param \Magento\Framework\View\Model\Layout\Update\Validator $validator
175182
* @param \Psr\Log\LoggerInterface $logger
176-
* @param ReadFactory $readFactory ,
183+
* @param ReadFactory $readFactory
177184
* @param \Magento\Framework\View\Design\ThemeInterface $theme Non-injectable theme instance
178185
* @param string $cacheSuffix
179186
* @param LayoutCacheKeyInterface $layoutCacheKey
187+
* @param SerializerInterface|null $serializer
180188
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
181189
*/
182190
public function __construct(
@@ -191,7 +199,8 @@ public function __construct(
191199
ReadFactory $readFactory,
192200
\Magento\Framework\View\Design\ThemeInterface $theme = null,
193201
$cacheSuffix = '',
194-
LayoutCacheKeyInterface $layoutCacheKey = null
202+
LayoutCacheKeyInterface $layoutCacheKey = null,
203+
SerializerInterface $serializer = null
195204
) {
196205
$this->theme = $theme ?: $design->getDesignTheme();
197206
$this->scope = $scopeResolver->getScope();
@@ -205,6 +214,7 @@ public function __construct(
205214
$this->cacheSuffix = $cacheSuffix;
206215
$this->layoutCacheKey = $layoutCacheKey
207216
?: \Magento\Framework\App\ObjectManager::getInstance()->get(LayoutCacheKeyInterface::class);
217+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
208218
}
209219

210220
/**
@@ -283,6 +293,7 @@ public function getHandles()
283293

284294
/**
285295
* Add the first existing (declared in layout updates) page handle along with all parents to the update.
296+
*
286297
* Return whether any page handles have been added or not.
287298
*
288299
* @param string[] $handlesToTry
@@ -315,6 +326,8 @@ public function pageHandleExists($handleName)
315326
}
316327

317328
/**
329+
* Page layout type
330+
*
318331
* @return string|null
319332
*/
320333
public function getPageLayout()
@@ -437,12 +450,12 @@ public function load($handles = [])
437450

438451
$this->addHandle($handles);
439452

440-
$cacheId = $this->getCacheId();
441-
$cacheIdPageLayout = $cacheId . '_' . self::PAGE_LAYOUT_CACHE_SUFFIX;
453+
$cacheId = $this->getCacheId() . '_' . self::PAGE_LAYOUT_CACHE_SUFFIX;
442454
$result = $this->_loadCache($cacheId);
443-
if ($result) {
444-
$this->addUpdate($result);
445-
$this->pageLayout = $this->_loadCache($cacheIdPageLayout);
455+
if ($result !== false && $result !== null) {
456+
$data = $this->serializer->unserialize($result);
457+
$this->pageLayout = $data["pageLayout"];
458+
$this->addUpdate($data["layout"]);
446459
foreach ($this->getHandles() as $handle) {
447460
$this->allHandles[$handle] = $this->handleProcessed;
448461
}
@@ -455,8 +468,13 @@ public function load($handles = [])
455468

456469
$layout = $this->asString();
457470
$this->_validateMergedLayout($cacheId, $layout);
458-
$this->_saveCache($layout, $cacheId, $this->getHandles());
459-
$this->_saveCache((string)$this->pageLayout, $cacheIdPageLayout, $this->getHandles());
471+
472+
$data = [
473+
"pageLayout" => (string)$this->pageLayout,
474+
"layout" => $layout
475+
];
476+
$this->_saveCache($this->serializer->serialize($data), $cacheId, $this->getHandles());
477+
460478
return $this;
461479
}
462480

@@ -602,7 +620,7 @@ protected function _fetchDbLayoutUpdates($handle)
602620
*/
603621
public function validateUpdate($handle, $updateXml)
604622
{
605-
return;
623+
return null;
606624
}
607625

608626
/**
@@ -930,6 +948,7 @@ public function getScope()
930948
public function getCacheId()
931949
{
932950
$layoutCacheKeys = $this->layoutCacheKey->getCacheKeys();
951+
// phpcs:ignore Magento2.Security.InsecureFunction
933952
return $this->generateCacheId(md5(implode('|', array_merge($this->getHandles(), $layoutCacheKeys))));
934953
}
935954
}

0 commit comments

Comments
 (0)