Skip to content

Commit 435b165

Browse files
author
gwharton
committed
[2.3-develop] [ForwardPort] Port of #12285 The option <var name="allowfullscreen">false</var> for mobile device don't work in product view page gallery
Change the type of config variables of values "true" and "false" to type boolean, instead of string.
1 parent 4f9b705 commit 435b165

File tree

2 files changed

+95
-1
lines changed

2 files changed

+95
-1
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Config;
8+
9+
use Magento\Framework\ObjectManagerInterface;
10+
11+
/**
12+
* Tests Magento\Framework\Config\Convert
13+
*/
14+
class ConverterTest extends \PHPUnit\Framework\TestCase
15+
{
16+
/**
17+
* @var ObjectManagerInterface
18+
*/
19+
private $objectManager;
20+
21+
/**
22+
* @var Converter
23+
*/
24+
private $converter;
25+
26+
/**
27+
* Tests config value "false" is not interpreted as true.
28+
*
29+
* @param string $sourceString
30+
* @param array $expected
31+
* @dataProvider parseVarElementDataProvider
32+
*/
33+
public function testParseVarElement($sourceString, $expected)
34+
{
35+
$document = new \DOMDocument();
36+
$document->loadXML($sourceString);
37+
$actual = $this->converter->convert($document);
38+
39+
self::assertEquals(
40+
$expected,
41+
$actual
42+
);
43+
}
44+
45+
/**
46+
* Data provider for testParseVarElement.
47+
*
48+
* @return array
49+
*/
50+
public function parseVarElementDataProvider()
51+
{
52+
$sourceString = <<<'XML'
53+
<?xml version="1.0"?>
54+
<view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/view.xsd">
55+
<vars module="Magento_Test">
56+
<var name="str">some string</var>
57+
<var name="int-1">1</var>
58+
<var name="int-0">0</var>
59+
<var name="bool-true">true</var>
60+
<var name="bool-false">false</var>
61+
</vars>
62+
</view>
63+
XML;
64+
$expectedResult = [
65+
'vars' => [
66+
'Magento_Test' => [
67+
'str' => 'some string',
68+
'int-1' => '1',
69+
'int-0' => '0',
70+
'bool-true' => true,
71+
'bool-false' => false
72+
]
73+
]
74+
];
75+
76+
return [
77+
[
78+
$sourceString,
79+
$expectedResult
80+
],
81+
];
82+
}
83+
84+
/**
85+
* @inheritdoc
86+
*/
87+
protected function setUp()
88+
{
89+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
90+
$this->converter = $this->objectManager->get(Converter::class);
91+
}
92+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ protected function parseVarElement(\DOMElement $node)
103103
}
104104
}
105105
if (!count($result)) {
106-
$result = $node->nodeValue;
106+
$result = (strtolower($node->nodeValue) !== 'true' && strtolower($node->nodeValue) !== 'false')
107+
? $node->nodeValue
108+
: filter_var($node->nodeValue, FILTER_VALIDATE_BOOLEAN);
107109
}
108110
return $result;
109111
}

0 commit comments

Comments
 (0)