Skip to content

Commit d33814d

Browse files
committed
Merge remote-tracking branch 'origin/MC-33205' into 2.4-develop-pr32
2 parents 8647888 + 69a6b05 commit d33814d

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

app/code/Magento/Catalog/Helper/Output.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\Escaper;
1616
use Magento\Framework\Exception\LocalizedException;
1717
use Magento\Framework\Filter\Template;
18+
use Magento\Framework\Phrase;
1819
use function is_object;
1920
use function method_exists;
2021
use function preg_match;
@@ -157,7 +158,7 @@ public function process($method, $result, $params)
157158
* Prepare product attribute html output
158159
*
159160
* @param ModelProduct $product
160-
* @param string $attributeHtml
161+
* @param string|Phrase $attributeHtml
161162
* @param string $attributeName
162163
* @return string
163164
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
@@ -235,14 +236,14 @@ public function categoryAttribute($category, $attributeHtml, $attributeName)
235236
/**
236237
* Check if string has directives
237238
*
238-
* @param string $attributeHtml
239+
* @param string|Phrase $attributeHtml
239240
* @return bool
240241
*/
241242
public function isDirectivesExists(string $attributeHtml): bool
242243
{
243244
$matches = false;
244245
foreach ($this->directivePatterns as $pattern) {
245-
if (preg_match($pattern, $attributeHtml)) {
246+
if (preg_match($pattern, (string)$attributeHtml)) {
246247
$matches = true;
247248
break;
248249
}

dev/tests/integration/testsuite/Magento/Catalog/Helper/OutputTest.php

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@
55
*/
66
namespace Magento\Catalog\Helper;
77

8-
class OutputTest extends \PHPUnit\Framework\TestCase
8+
use Magento\Catalog\Model\Category;
9+
use Magento\Catalog\Model\Product;
10+
use Magento\Framework\Phrase;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use PHPUnit\Framework\TestCase;
13+
14+
class OutputTest extends TestCase
915
{
1016
/**
11-
* @var \Magento\Catalog\Helper\Output
17+
* @var Output
1218
*/
1319
protected $_helper;
1420

1521
protected function setUp()
1622
{
17-
$this->_helper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
18-
\Magento\Catalog\Helper\Output::class
23+
$this->_helper = Bootstrap::getObjectManager()->get(
24+
Output::class
1925
);
2026
}
2127

@@ -50,7 +56,7 @@ public function testProductAttribute()
5056
{
5157
$this->_testAttribute(
5258
'productAttribute',
53-
\Magento\Catalog\Model\Product::ENTITY,
59+
Product::ENTITY,
5460
"&lt;p&gt;line1&lt;/p&gt;<br />\nline2"
5561
);
5662
}
@@ -59,41 +65,50 @@ public function testCategoryAttribute()
5965
{
6066
$this->_testAttribute(
6167
'categoryAttribute',
62-
\Magento\Catalog\Model\Category::ENTITY,
68+
Category::ENTITY,
6369
"&lt;p&gt;line1&lt;/p&gt;\nline2"
6470
);
6571
}
6672

6773
/**
74+
* Tests if string has directives.
75+
*
6876
* @dataProvider isDirectiveDataProvider
77+
* @param string|Phrase $html
78+
* @param bool $expectedResult
6979
*/
70-
public function testIsDirective($html, $expectedResult)
80+
public function testIsDirectivesExists($html, bool $expectedResult): void
7181
{
7282
$this->assertEquals($expectedResult, $this->_helper->isDirectivesExists($html));
7383
}
7484

75-
public function isDirectiveDataProvider()
85+
/**
86+
* Data provider for testIsDirectivesExists()
87+
*
88+
* @return array
89+
*/
90+
public function isDirectiveDataProvider(): array
7691
{
7792
return [
78-
['{{', false],
79-
['Test string', false],
80-
['{store url="customer/account/login"}', false],
81-
['{{store url="customer/account/login"}}', true],
93+
'attribute_html_without_directive' => ['Test string', false],
94+
'attribute_html_with_incorrect_directive' => ['{store url="customer/account/login"}', false],
95+
'attribute_html_with_correct_directive' => ['{{store url="customer/account/login"}}', true],
96+
'attribute_html_with_object_type' => [__('{{store url="%1"}}', 'customer/account/login'), true],
8297
];
8398
}
8499

85100
/**
86101
* Helper method for testProcess()
87102
*
88-
* @param \Magento\Catalog\Helper\Output $helper
103+
* @param Output $helper
89104
* @param string $string
90105
* @param mixed $params
91106
* @return string
92107
* @see testProcess()
93108
*
94109
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
95110
*/
96-
public function sampleProcessor(\Magento\Catalog\Helper\Output $helper, $string, $params)
111+
public function sampleProcessor(Output $helper, $string, $params)
97112
{
98113
return __CLASS__ . $string;
99114
}
@@ -109,7 +124,7 @@ public function sampleProcessor(\Magento\Catalog\Helper\Output $helper, $string,
109124
protected function _testAttribute($method, $entityCode, $expectedResult)
110125
{
111126
$attributeName = 'description';
112-
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
127+
$attribute = Bootstrap::getObjectManager()->get(
113128
\Magento\Eav\Model\Config::class
114129
)->getAttribute(
115130
$entityCode,

0 commit comments

Comments
 (0)