Skip to content

Commit 0c53bbf

Browse files
Merge pull request #8999 from magento-gl/spartans_pr_12062024
Spartans pr 12062024
2 parents 35b1b1d + faa90bb commit 0c53bbf

File tree

16 files changed

+365
-64
lines changed

16 files changed

+365
-64
lines changed

app/code/Magento/Catalog/Controller/Product/Compare/Index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77
namespace Magento\Catalog\Controller\Product\Compare;
88

9-
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
109
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
1111
use Magento\Framework\Data\Form\FormKey\Validator;
1212
use Magento\Framework\View\Result\PageFactory;
1313

@@ -81,6 +81,8 @@ public function execute()
8181
$this->_catalogSession->setBeforeCompareUrl(
8282
$this->urlDecoder->decode($beforeUrl)
8383
);
84+
} else {
85+
$this->_catalogSession->unsBeforeCompareUrl();
8486
}
8587
return $this->resultPageFactory->create();
8688
}

app/code/Magento/Catalog/CustomerData/CompareProducts.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\App\Config\ScopeConfigInterface;
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\UrlInterface;
1213
use Magento\Store\Model\StoreManagerInterface;
1314

1415
/**
@@ -43,25 +44,33 @@ class CompareProducts implements SectionSourceInterface
4344
*/
4445
private $storeManager;
4546

47+
/**
48+
* @var UrlInterface
49+
*/
50+
private $urlBuilder;
51+
4652
/**
4753
* @param \Magento\Catalog\Helper\Product\Compare $helper
4854
* @param \Magento\Catalog\Model\Product\Url $productUrl
4955
* @param \Magento\Catalog\Helper\Output $outputHelper
5056
* @param ScopeConfigInterface|null $scopeConfig
5157
* @param StoreManagerInterface|null $storeManager
58+
* @param UrlInterface|null $urlBuilder
5259
*/
5360
public function __construct(
5461
\Magento\Catalog\Helper\Product\Compare $helper,
5562
\Magento\Catalog\Model\Product\Url $productUrl,
5663
\Magento\Catalog\Helper\Output $outputHelper,
5764
?ScopeConfigInterface $scopeConfig = null,
58-
?StoreManagerInterface $storeManager = null
65+
?StoreManagerInterface $storeManager = null,
66+
?UrlInterface $urlBuilder = null
5967
) {
6068
$this->helper = $helper;
6169
$this->productUrl = $productUrl;
6270
$this->outputHelper = $outputHelper;
6371
$this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
6472
$this->storeManager = $storeManager ?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
73+
$this->urlBuilder = $urlBuilder ?? ObjectManager::getInstance()->get(UrlInterface::class);
6574
}
6675

6776
/**
@@ -73,7 +82,7 @@ public function getSectionData()
7382
return [
7483
'count' => $count,
7584
'countCaption' => $count == 1 ? __('1 item') : __('%1 items', $count),
76-
'listUrl' => $this->helper->getListUrl(),
85+
'listUrl' => $this->urlBuilder->getUrl('catalog/product_compare/index'),
7786
'items' => $count ? $this->getItems() : [],
7887
'websiteId' => $this->storeManager->getWebsite()->getId()
7988
];

app/code/Magento/Catalog/Test/Unit/CustomerData/CompareProductsTest.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
use Magento\Catalog\Model\ResourceModel\Product\Compare\Item\Collection;
1818
use Magento\Framework\App\Config\ScopeConfigInterface;
1919
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
20+
use Magento\Framework\UrlInterface;
21+
use Magento\Store\Model\StoreManagerInterface;
2022
use Magento\Store\Model\Website;
2123
use PHPUnit\Framework\MockObject\MockObject;
2224
use PHPUnit\Framework\TestCase;
23-
use Magento\Store\Model\StoreManagerInterface;
2425

26+
/**
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
28+
*/
2529
class CompareProductsTest extends TestCase
2630
{
2731
/**
@@ -64,6 +68,11 @@ class CompareProductsTest extends TestCase
6468
*/
6569
private $websiteMock;
6670

71+
/**
72+
* @var UrlInterface|MockObject
73+
*/
74+
private $urlBuilder;
75+
6776
/**
6877
* @var array
6978
*/
@@ -88,6 +97,9 @@ protected function setUp(): void
8897
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
8998
->disableOriginalConstructor()
9099
->getMockForAbstractClass();
100+
$this->urlBuilder = $this->getMockBuilder(UrlInterface::class)
101+
->disableOriginalConstructor()
102+
->getMock();
91103

92104
$this->storeManagerMock = $this->getMockBuilder(
93105
StoreManagerInterface::class
@@ -97,7 +109,7 @@ protected function setUp(): void
97109
$this->websiteMock = $this->getMockBuilder(
98110
Website::class
99111
)->onlyMethods(
100-
['getId',]
112+
['getId']
101113
)->disableOriginalConstructor()
102114
->getMock();
103115

@@ -110,8 +122,8 @@ protected function setUp(): void
110122
'productUrl' => $this->productUrlMock,
111123
'outputHelper' => $this->outputHelperMock,
112124
'scopeConfig' => $this->scopeConfigMock,
113-
'storeManager' => $this->storeManagerMock
114-
125+
'storeManager' => $this->storeManagerMock,
126+
'urlBuilder' => $this->urlBuilder
115127
]
116128
);
117129
}
@@ -219,9 +231,10 @@ public function testGetSectionData()
219231
->method('getItemCollection')
220232
->willReturn($itemCollectionMock);
221233

222-
$this->helperMock->expects($this->once())
223-
->method('getListUrl')
234+
$this->urlBuilder->expects($this->once())
235+
->method('getUrl')
224236
->willReturn('http://list.url');
237+
225238
$this->storeManagerMock->expects($this->any())->method('getWebsite')->willReturn($this->websiteMock);
226239
$this->websiteMock->expects($this->any())->method('getId')->willReturn(1);
227240
$this->assertEquals(
@@ -269,8 +282,8 @@ public function testGetSectionDataNoItems()
269282
$this->helperMock->expects($this->never())
270283
->method('getItemCollection');
271284

272-
$this->helperMock->expects($this->once())
273-
->method('getListUrl')
285+
$this->urlBuilder->expects($this->once())
286+
->method('getUrl')
274287
->willReturn('http://list.url');
275288

276289
$this->storeManagerMock->expects($this->any())->method('getWebsite')->willReturn($this->websiteMock);
@@ -314,8 +327,8 @@ public function testGetSectionDataSingleItem()
314327
->method('getItemCollection')
315328
->willReturn($itemCollectionMock);
316329

317-
$this->helperMock->expects($this->once())
318-
->method('getListUrl')
330+
$this->urlBuilder->expects($this->once())
331+
->method('getUrl')
319332
->willReturn('http://list.url');
320333

321334
$this->assertEquals(

app/code/Magento/Developer/Console/Command/DiInfoCommand.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99
use Magento\Developer\Model\Di\Information;
1010
use Symfony\Component\Console\Command\Command;
1111
use Symfony\Component\Console\Exception\InvalidArgumentException;
12+
use Symfony\Component\Console\Helper\Table;
13+
use Symfony\Component\Console\Input\InputArgument;
1214
use Symfony\Component\Console\Input\InputInterface;
1315
use Symfony\Component\Console\Output\OutputInterface;
14-
use Symfony\Component\Console\Input\InputArgument;
15-
use Symfony\Component\Console\Helper\Table;
1616

1717
class DiInfoCommand extends Command
1818
{
1919
/**
2020
* Command name
2121
*/
22-
const COMMAND_NAME = 'dev:di:info';
22+
public const COMMAND_NAME = 'dev:di:info';
2323

2424
/**
2525
* input name
2626
*/
27-
const CLASS_NAME = 'class';
27+
public const CLASS_NAME = 'class';
2828

2929
/**
3030
* @var Information
@@ -42,7 +42,8 @@ public function __construct(
4242
}
4343

4444
/**
45-
* {@inheritdoc}
45+
* Initialization of the command
46+
*
4647
* @throws InvalidArgumentException
4748
*/
4849
protected function configure()
@@ -93,7 +94,7 @@ private function printConstructorArguments($className, $output)
9394
$paramsTableArray[] = $parameterRow;
9495
}
9596
$paramsTable->setRows($paramsTableArray);
96-
$output->writeln($paramsTable->render());
97+
$paramsTable->render();
9798
}
9899

99100
/**
@@ -142,12 +143,14 @@ private function printPlugins($className, $output, $label)
142143
->setHeaders(['Plugin', 'Method', 'Type'])
143144
->setRows($parameters);
144145

145-
$output->writeln($table->render());
146+
$table->render();
146147
}
147148

148149
/**
149-
* {@inheritdoc}
150-
* @throws \InvalidArgumentException
150+
* Displays dependency injection configuration information for a class.
151+
*
152+
* @param InputInterface $input
153+
* @param OutputInterface $output
151154
*/
152155
protected function execute(InputInterface $input, OutputInterface $output)
153156
{

app/code/Magento/PageCache/Model/App/Request/Http/IdentifierForSave.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ class IdentifierForSave implements IdentifierInterface
2121
* @param Http $request
2222
* @param Context $context
2323
* @param Json $serializer
24+
* @param IdentifierStoreReader $identifierStoreReader
2425
*/
2526
public function __construct(
26-
private Http $request,
27-
private Context $context,
28-
private Json $serializer
27+
private Http $request,
28+
private Context $context,
29+
private Json $serializer,
30+
private IdentifierStoreReader $identifierStoreReader,
2931
) {
3032
}
3133

@@ -42,6 +44,8 @@ public function getValue()
4244
$this->context->getVaryString()
4345
];
4446

47+
$data = $this->identifierStoreReader->getPageTagsWithStoreCacheTags($data);
48+
4549
return sha1($this->serializer->serialize($data));
4650
}
4751
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageCache\Model\App\Request\Http;
9+
10+
use Magento\Store\Model\StoreManager;
11+
12+
class IdentifierStoreReader
13+
{
14+
/**
15+
* @var \Magento\Framework\View\DesignExceptions
16+
*/
17+
private $designExceptions;
18+
19+
/**
20+
* @var \Magento\Framework\App\RequestInterface
21+
*/
22+
private $request;
23+
24+
/**
25+
* @var \Magento\PageCache\Model\Config
26+
*/
27+
private $config;
28+
29+
/**
30+
* @param \Magento\Framework\View\DesignExceptions $designExceptions
31+
* @param \Magento\Framework\App\RequestInterface $request
32+
* @param \Magento\PageCache\Model\Config $config
33+
*/
34+
public function __construct(
35+
\Magento\Framework\View\DesignExceptions $designExceptions,
36+
\Magento\Framework\App\RequestInterface $request,
37+
\Magento\PageCache\Model\Config $config
38+
) {
39+
$this->designExceptions = $designExceptions;
40+
$this->request = $request;
41+
$this->config = $config;
42+
}
43+
44+
/**
45+
* Adds a theme key to identifier for a built-in cache if user-agent theme rule is actual
46+
*
47+
* @param array $data
48+
* @return array|null
49+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
50+
*/
51+
public function getPageTagsWithStoreCacheTags(array $data): ?array
52+
{
53+
if ($this->config->getType() === \Magento\PageCache\Model\Config::BUILT_IN && $this->config->isEnabled()) {
54+
$ruleDesignException = $this->designExceptions->getThemeByRequest($this->request);
55+
if ($ruleDesignException !== false) {
56+
$data['DESIGN'] = $ruleDesignException;
57+
}
58+
59+
if ($runType = $this->request->getServerValue(StoreManager::PARAM_RUN_TYPE)) {
60+
$data[StoreManager::PARAM_RUN_TYPE] = $runType;
61+
}
62+
63+
if ($runCode = $this->request->getServerValue(StoreManager::PARAM_RUN_CODE)) {
64+
$data[StoreManager::PARAM_RUN_CODE] = $runCode;
65+
}
66+
}
67+
68+
return $data;
69+
}
70+
}

app/code/Magento/PageCache/Test/Unit/Model/App/Request/Http/IdentifierForSaveTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\App\Request\Http as HttpRequest;
1212
use Magento\Framework\Serialize\Serializer\Json;
1313
use Magento\PageCache\Model\App\Request\Http\IdentifierForSave;
14+
use Magento\PageCache\Model\App\Request\Http\IdentifierStoreReader;
1415
use PHPUnit\Framework\MockObject\MockObject;
1516
use PHPUnit\Framework\TestCase;
1617

@@ -40,6 +41,10 @@ class IdentifierForSaveTest extends TestCase
4041
* @var Json|MockObject
4142
*/
4243
private mixed $serializerMock;
44+
/**
45+
* @var IdentifierStoreReader|MockObject
46+
*/
47+
private $identifierStoreReader;
4348

4449
/**
4550
* @inheritdoc
@@ -64,10 +69,16 @@ function ($value) {
6469
}
6570
);
6671

72+
$this->identifierStoreReader = $this->getMockBuilder(IdentifierStoreReader::class)
73+
->onlyMethods(['getPageTagsWithStoreCacheTags'])
74+
->disableOriginalConstructor()
75+
->getMock();
76+
6777
$this->model = new IdentifierForSave(
6878
$this->requestMock,
6979
$this->contextMock,
70-
$this->serializerMock
80+
$this->serializerMock,
81+
$this->identifierStoreReader
7182
);
7283
parent::setUp();
7384
}
@@ -91,6 +102,12 @@ public function testGetValue(): void
91102
->method('getVaryString')
92103
->willReturn(self::VARY);
93104

105+
$this->identifierStoreReader->method('getPageTagsWithStoreCacheTags')->willReturnCallback(
106+
function ($value) {
107+
return $value;
108+
}
109+
);
110+
94111
$this->assertEquals(
95112
sha1(
96113
json_encode(

0 commit comments

Comments
 (0)