Skip to content

Commit ef6d047

Browse files
committed
Merge remote-tracking branch 'origin/AC-10660' into spartans_pr_06062024
2 parents beaba8b + 2c345bf commit ef6d047

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
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(

0 commit comments

Comments
 (0)