Skip to content

Commit 36968e0

Browse files
authored
Merge pull request #8147 from magento-cia/cia-2.4.7-beta1-develop-bugfixes-02132023
Cia 2.4.7 beta1 develop bugfixes 02132023
2 parents 1f72a51 + 0cbe4f6 commit 36968e0

File tree

6 files changed

+196
-12
lines changed

6 files changed

+196
-12
lines changed

app/code/Magento/Catalog/Test/Unit/Pricing/Render/FinalPriceBoxTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
use Magento\Catalog\Pricing\Render\FinalPriceBox;
1616
use Magento\Framework\App\Cache\StateInterface;
1717
use Magento\Framework\App\Config\ScopeConfigInterface;
18+
use Magento\Framework\App\DeploymentConfig;
1819
use Magento\Framework\App\State;
20+
use Magento\Framework\Config\ConfigOptionsListConstants;
1921
use Magento\Framework\Event\Test\Unit\ManagerStub;
22+
use Magento\Framework\ObjectManagerInterface;
2023
use Magento\Framework\Pricing\Amount\AmountInterface;
2124
use Magento\Framework\Pricing\Price\PriceInterface;
2225
use Magento\Framework\Pricing\PriceInfoInterface;
@@ -96,11 +99,27 @@ class FinalPriceBoxTest extends TestCase
9699
*/
97100
private $minimalPriceCalculator;
98101

102+
/**
103+
* @var DeploymentConfig|MockObject
104+
*/
105+
private $deploymentConfig;
106+
107+
/**
108+
* @var ObjectManagerInterface|MockObject
109+
*/
110+
private $objectManagerMock;
111+
99112
/**
100113
* @inheritDoc
114+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
101115
*/
102116
protected function setUp(): void
103117
{
118+
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
119+
->disableOriginalConstructor()
120+
->onlyMethods(['get'])
121+
->getMockForAbstractClass();
122+
\Magento\Framework\App\ObjectManager::setInstance($this->objectManagerMock);
104123
$this->product = $this->getMockBuilder(Product::class)
105124
->addMethods(['getCanShowPrice'])
106125
->onlyMethods(['getPriceInfo', 'isSalable', 'getId'])
@@ -183,6 +202,11 @@ protected function setUp(): void
183202
->disableOriginalConstructor()
184203
->getMockForAbstractClass();
185204

205+
$this->deploymentConfig = $this->createPartialMock(
206+
DeploymentConfig::class,
207+
['get']
208+
);
209+
186210
$this->minimalPriceCalculator = $this->getMockForAbstractClass(MinimalPriceCalculatorInterface::class);
187211
$this->object = $objectManager->getObject(
188212
FinalPriceBox::class,
@@ -455,6 +479,15 @@ public function testHidePrice(): void
455479
*/
456480
public function testGetCacheKey(): void
457481
{
482+
$this->objectManagerMock->expects($this->any())
483+
->method('get')
484+
->with(DeploymentConfig::class)
485+
->willReturn($this->deploymentConfig);
486+
487+
$this->deploymentConfig->expects($this->any())
488+
->method('get')
489+
->with(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY)
490+
->willReturn('448198e08af35844a42d3c93c1ef4e03');
458491
$result = $this->object->getCacheKey();
459492
$this->assertStringEndsWith('list-category-page', $result);
460493
}

app/code/Magento/Email/Model/Template/Filter.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,22 @@ class Filter extends Template
6969
/**
7070
* @var bool
7171
* @deprecated SID is not being used as query parameter anymore.
72+
* @see Session ID's in URL
7273
*/
7374
protected $_useSessionInUrl = false;
7475

7576
/**
7677
* @var array
7778
* @deprecated 101.0.4 Use the new Directive Processor interfaces
79+
* @see Directive Processor interfaces
7880
*/
7981
protected $_modifiers = ['nl2br' => ''];
8082

83+
/**
84+
* @var string
85+
*/
86+
private const CACHE_KEY_PREFIX = "EMAIL_FILTER_";
87+
8188
/**
8289
* @var bool
8390
*/
@@ -281,6 +288,7 @@ public function setUseAbsoluteLinks($flag)
281288
* @return $this
282289
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
283290
* @deprecated SID query parameter is not used in URLs anymore.
291+
* @see SessionId's in URL
284292
*/
285293
public function setUseSessionInUrl($flag)
286294
{
@@ -404,6 +412,11 @@ public function blockDirective($construction)
404412
{
405413
$skipParams = ['class', 'id', 'output'];
406414
$blockParameters = $this->getParameters($construction[2]);
415+
416+
if (isset($blockParameters['cache_key'])) {
417+
$blockParameters['cache_key'] = self::CACHE_KEY_PREFIX . $blockParameters['cache_key'];
418+
}
419+
407420
$block = null;
408421

409422
if (isset($blockParameters['class'])) {
@@ -688,6 +701,7 @@ public function varDirective($construction)
688701
* @param string $default assumed modifier if none present
689702
* @return array
690703
* @deprecated 101.0.4 Use the new FilterApplier or Directive Processor interfaces
704+
* @see Directive Processor Interfaces
691705
*/
692706
protected function explodeModifiers($value, $default = null)
693707
{
@@ -707,6 +721,7 @@ protected function explodeModifiers($value, $default = null)
707721
* @param string $modifiers
708722
* @return string
709723
* @deprecated 101.0.4 Use the new FilterApplier or Directive Processor interfaces
724+
* @see Directive Processor Interfaces
710725
*/
711726
protected function applyModifiers($value, $modifiers)
712727
{
@@ -736,6 +751,7 @@ protected function applyModifiers($value, $modifiers)
736751
* @param string $type
737752
* @return string
738753
* @deprecated 101.0.4 Use the new FilterApplier or Directive Processor interfaces
754+
* @see Directive Processor Interfacees
739755
*/
740756
public function modifierEscape($value, $type = 'html')
741757
{

app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/Listing/ConfigurableTest.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
use Magento\Framework\App\Config\ScopeConfigInterface;
2424
use Magento\Framework\App\Request\Http;
2525
use Magento\Framework\App\RequestInterface;
26+
use Magento\Framework\App\DeploymentConfig;
27+
use Magento\Framework\Config\ConfigOptionsListConstants;
2628
use Magento\Framework\Json\EncoderInterface;
2729
use Magento\Framework\Model\AbstractModel;
30+
use Magento\Framework\ObjectManagerInterface;
2831
use Magento\Framework\Pricing\PriceCurrencyInterface;
2932
use Magento\Framework\Pricing\PriceInfo\Base;
3033
use Magento\Framework\Stdlib\ArrayUtils;
@@ -95,8 +98,23 @@ class ConfigurableTest extends TestCase
9598
*/
9699
private $request;
97100

101+
/**
102+
* @var ObjectManagerInterface|MockObject
103+
*/
104+
private $objectManagerMock;
105+
106+
/**
107+
* @var DeploymentConfig|MockObject
108+
*/
109+
private $deploymentConfig;
110+
98111
protected function setUp(): void
99112
{
113+
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
114+
->disableOriginalConstructor()
115+
->onlyMethods(['get'])
116+
->getMockForAbstractClass();
117+
\Magento\Framework\App\ObjectManager::setInstance($this->objectManagerMock);
100118
$this->arrayUtils = $this->createMock(ArrayUtils::class);
101119
$this->jsonEncoder = $this->getMockForAbstractClass(EncoderInterface::class);
102120
$this->helper = $this->createMock(Data::class);
@@ -127,6 +145,16 @@ protected function setUp(): void
127145
$context = $this->getContextMock();
128146
$context->method('getRequest')->willReturn($this->request);
129147

148+
$this->deploymentConfig = $this->createPartialMock(
149+
DeploymentConfig::class,
150+
['get']
151+
);
152+
153+
$this->deploymentConfig->expects($this->any())
154+
->method('get')
155+
->with(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY)
156+
->willReturn('448198e08af35844a42d3c93c1ef4e03');
157+
130158
$objectManagerHelper = new ObjectManager($this);
131159
$this->configurable = $objectManagerHelper->getObject(
132160
ConfigurableRenderer::class,
@@ -146,7 +174,7 @@ protected function setUp(): void
146174
'configurableAttributeData' => $this->configurableAttributeData,
147175
'data' => [],
148176
'variationPrices' => $this->variationPricesMock,
149-
'customerSession' => $customerSession,
177+
'customerSession' => $customerSession
150178
]
151179
);
152180
}
@@ -308,6 +336,10 @@ public function testGetCacheKey()
308336
->willReturn($configurableAttributes);
309337

310338
$this->request->method('toArray')->willReturn($requestParams);
339+
$this->objectManagerMock->expects($this->any())
340+
->method('get')
341+
->with(DeploymentConfig::class)
342+
->willReturn($this->deploymentConfig);
311343
$this->assertStringContainsString(
312344
sha1(json_encode(['color' => 59, 'size' => 1])),
313345
$this->configurable->getCacheKey()

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

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public function getTemplateProcessor()
189189
*
190190
* @param string $value
191191
* @return string
192+
*
192193
* @throws \Exception
193194
*/
194195
public function filter($value)
@@ -203,19 +204,21 @@ public function filter($value)
203204
$this->filteringDepthMeter->descend();
204205

205206
// Processing of template directives.
206-
$templateDirectivesResults = $this->processDirectives($value);
207+
$templateDirectivesResults = array_unique(
208+
$this->processDirectives($value),
209+
SORT_REGULAR
210+
);
207211

208-
foreach ($templateDirectivesResults as $result) {
209-
$value = str_replace($result['directive'], $result['output'], $value);
210-
}
212+
$value = $this->applyDirectivesResults($value, $templateDirectivesResults);
211213

212214
// Processing of deferred directives received from child templates
213215
// or nested directives.
214-
$deferredDirectivesResults = $this->processDirectives($value, true);
216+
$deferredDirectivesResults = array_unique(
217+
$this->processDirectives($value, true),
218+
SORT_REGULAR
219+
);
215220

216-
foreach ($deferredDirectivesResults as $result) {
217-
$value = str_replace($result['directive'], $result['output'], $value);
218-
}
221+
$value = $this->applyDirectivesResults($value, $deferredDirectivesResults);
219222

220223
if ($this->filteringDepthMeter->showMark() > 1) {
221224
// Signing own deferred directives (if any).
@@ -282,6 +285,35 @@ private function processDirectives($value, $isSigned = false): array
282285
return $results;
283286
}
284287

288+
/**
289+
* Applies results produced by directives.
290+
*
291+
* @param string $value
292+
* @param array $results
293+
*
294+
* @return string
295+
*/
296+
private function applyDirectivesResults(string $value, array $results): string
297+
{
298+
$processedResults = [];
299+
300+
foreach ($results as $result) {
301+
foreach ($processedResults as $processedResult) {
302+
$result['directive'] = str_replace(
303+
$processedResult['directive'],
304+
$processedResult['output'],
305+
$result['directive']
306+
);
307+
}
308+
309+
$value = str_replace($result['directive'], $result['output'], $value);
310+
311+
$processedResults[] = $result;
312+
}
313+
314+
return $value;
315+
}
316+
285317
/**
286318
* Modifies given regular expression pattern to be able to recognize signed directives.
287319
*

0 commit comments

Comments
 (0)