Skip to content

Commit 1a17be2

Browse files
committed
Merge remote-tracking branch 'engcom/2.4-develop' into module-login-as-customer
2 parents 785e842 + 1173ac5 commit 1a17be2

File tree

5 files changed

+51
-8
lines changed

5 files changed

+51
-8
lines changed

app/code/Magento/Customer/Block/Address/Renderer/DefaultRenderer.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Customer\Model\Address\AddressModelInterface;
99
use Magento\Customer\Model\Address\Mapper;
1010
use Magento\Customer\Model\Metadata\ElementFactory;
11+
use Magento\Directory\Model\Country\Format;
1112
use Magento\Framework\View\Element\AbstractBlock;
1213

1314
/**
@@ -91,6 +92,8 @@ public function setType(\Magento\Framework\DataObject $type)
9192
}
9293

9394
/**
95+
* Get the format of the address
96+
*
9497
* @param AddressModelInterface|null $address
9598
* @return string
9699
* All new code should use renderArray based on Metadata service
@@ -106,8 +109,11 @@ public function getFormat(AddressModelInterface $address = null)
106109
}
107110

108111
/**
109-
* {@inheritdoc}
112+
* Render address
110113
*
114+
* @param AddressModelInterface $address
115+
* @param string|null $format
116+
* @return mixed
111117
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
112118
* @SuppressWarnings(PHPMD.NPathComplexity)
113119
*/
@@ -118,7 +124,7 @@ public function render(AddressModelInterface $address, $format = null)
118124
}
119125

120126
/**
121-
* {@inheritdoc}
127+
* @inheritdoc
122128
*/
123129
public function getFormatArray($addressAttributes = null)
124130
{
@@ -133,8 +139,11 @@ public function getFormatArray($addressAttributes = null)
133139
}
134140

135141
/**
136-
* {@inheritdoc}
142+
* Render address by attribute array
137143
*
144+
* @param array $addressAttributes
145+
* @param Format|null $format
146+
* @return string
138147
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
139148
* @SuppressWarnings(PHPMD.NPathComplexity)
140149
*/
@@ -167,7 +176,7 @@ public function renderArray($addressAttributes, $format = null)
167176
$addressAttributes['country_id']
168177
)->getName();
169178
} elseif ($attributeCode == 'region' && isset($addressAttributes['region'])) {
170-
$data['region'] = __($addressAttributes['region']);
179+
$data['region'] = (string)__($addressAttributes['region']);
171180
} elseif (isset($addressAttributes[$attributeCode])) {
172181
$value = $addressAttributes[$attributeCode];
173182
$dataModel = $this->_elementFactory->create($attributeMetadata, $value, 'customer_address');

dev/tests/integration/testsuite/Magento/Framework/Filter/DirectiveProcessor/SimpleDirectiveTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public function testDefaultFiltersAreUsed()
7474
public function testParametersAreParsed()
7575
{
7676
$filter = $this->objectManager->create(Template::class);
77+
$filter->setStrictMode(false);
7778

7879
$processor = $this->createWithProcessorsAndFilters(
7980
['mydir' => $this->objectManager->create(MyDirProcessor::class)],

dev/tests/integration/testsuite/Magento/Framework/Filter/TemplateTest.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public function testIfDirective()
155155

156156
public function testNonDataObjectVariableParsing()
157157
{
158+
$previous = $this->templateFilter->setStrictMode(false);
158159
$this->templateFilter->setVariables(
159160
[
160161
'address' => new class {
@@ -168,11 +169,33 @@ public function format($type)
168169

169170
$template = '{{var address.format(\'html\')}}';
170171
$expected = '<foo>html</foo>';
171-
self::assertEquals($expected, $this->templateFilter->filter($template));
172+
try {
173+
self::assertEquals($expected, $this->templateFilter->filter($template));
174+
} finally {
175+
$this->templateFilter->setStrictMode($previous);
176+
}
177+
}
178+
179+
public function testStrictModeByDefault()
180+
{
181+
$this->templateFilter->setVariables(
182+
[
183+
'address' => new class {
184+
public function format()
185+
{
186+
throw new \Exception('Should not run');
187+
}
188+
}
189+
]
190+
);
191+
192+
$template = '{{var address.format(\'html\')}}';
193+
self::assertEquals('', $this->templateFilter->filter($template));
172194
}
173195

174196
public function testComplexVariableArguments()
175197
{
198+
$previous = $this->templateFilter->setStrictMode(false);
176199
$this->templateFilter->setVariables(
177200
[
178201
'address' => new class {
@@ -187,11 +210,16 @@ public function format($a, $b, $c)
187210

188211
$template = '{{var address.format($arg1,\'bar\',[param1:baz])}}';
189212
$expected = 'foo bar baz';
190-
self::assertEquals($expected, $this->templateFilter->filter($template));
213+
try {
214+
self::assertEquals($expected, $this->templateFilter->filter($template));
215+
} finally {
216+
$this->templateFilter->setStrictMode($previous);
217+
}
191218
}
192219

193220
public function testComplexVariableGetterArguments()
194221
{
222+
$previous = $this->templateFilter->setStrictMode(false);
195223
$this->templateFilter->setVariables(
196224
[
197225
'address' => new class extends DataObject {
@@ -206,7 +234,11 @@ public function getFoo($a, $b, $c)
206234

207235
$template = '{{var address.getFoo($arg1,\'bar\',[param1:baz])}}';
208236
$expected = 'foo bar baz';
209-
self::assertEquals($expected, $this->templateFilter->filter($template));
237+
try {
238+
self::assertEquals($expected, $this->templateFilter->filter($template));
239+
} finally {
240+
$this->templateFilter->setStrictMode($previous);
241+
}
210242
}
211243

212244
public function testNonDataObjectRendersBlankInStrictMode()

dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/blacklist/common.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ lib/internal/Magento/Framework/Interception/Test/Unit/Config/ConfigTest.php
77
lib/internal/Magento/Framework/Cache/Backend/Eaccelerator.php
88
lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php
99
dev/tests/integration/framework/deployTestModules.php
10+
dev/tests/integration/testsuite/Magento/Framework/Filter/DirectiveProcessor/SimpleDirectiveTest.php
1011
dev/tests/integration/testsuite/Magento/Framework/Session/ConfigTest.php
1112
dev/tests/integration/testsuite/Magento/Framework/Session/SessionManagerTest.php
1213
dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/AbstractFiltersTest.php

lib/internal/Magento/Framework/Filter/Template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Template implements \Zend_Filter_Interface
9191
/**
9292
* @var bool
9393
*/
94-
private $strictMode = false;
94+
private $strictMode = true;
9595

9696
/**
9797
* @var VariableResolverInterface|null

0 commit comments

Comments
 (0)