Skip to content

Commit cd42c9d

Browse files
committed
MC-38074: Report - Products in Carts not following user roles scope
1 parent 8090eb0 commit cd42c9d

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

app/code/Magento/Reports/Block/Adminhtml/Grid/Shopcart.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Shopcart extends \Magento\Backend\Block\Widget\Grid\Extended
2828

2929
/**
3030
* StoreIds setter
31+
*
3132
* @codeCoverageIgnore
3233
*
3334
* @param array $storeIds
@@ -46,6 +47,10 @@ public function setStoreIds($storeIds)
4647
*/
4748
public function getCurrentCurrencyCode()
4849
{
50+
if (empty($this->_storeIds)) {
51+
$this->setStoreIds(array_keys($this->_storeManager->getStores()));
52+
}
53+
4954
if ($this->_currentCurrencyCode === null) {
5055
reset($this->_storeIds);
5156
$this->_currentCurrencyCode = count(
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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\Reports\Test\Unit\Block\Adminhtml\Grid;
9+
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
11+
use Magento\Reports\Block\Adminhtml\Grid\Shopcart;
12+
use Magento\Store\Api\Data\StoreInterface;
13+
use Magento\Store\Model\StoreManagerInterface;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Test for class \Magento\Reports\Block\Adminhtml\Grid\Shopcart.
19+
*/
20+
class ShopcartTest extends TestCase
21+
{
22+
/**
23+
* @var Shopcart|MockObject
24+
*/
25+
private $model;
26+
27+
/**
28+
* @var StoreManagerInterface|MockObject
29+
*/
30+
private $storeManagerMock;
31+
32+
protected function setUp(): void
33+
{
34+
$objectManager = new ObjectManager($this);
35+
36+
$this->storeManagerMock = $this->getMockForAbstractClass(
37+
StoreManagerInterface::class,
38+
[],
39+
'',
40+
true,
41+
true,
42+
true,
43+
['getStore']
44+
);
45+
46+
$this->model = $objectManager->getObject(
47+
Shopcart::class,
48+
['_storeManager' => $this->storeManagerMock]
49+
);
50+
}
51+
52+
/**
53+
* @param $storeIds
54+
*
55+
* @dataProvider getCurrentCurrencyCodeDataProvider
56+
*/
57+
public function testGetCurrentCurrencyCode($storeIds)
58+
{
59+
$storeMock = $this->getMockForAbstractClass(
60+
StoreInterface::class,
61+
[],
62+
'',
63+
true,
64+
true,
65+
true,
66+
['getBaseCurrencyCode']
67+
);
68+
69+
$this->model->setStoreIds($storeIds);
70+
71+
if ($storeIds) {
72+
$expectedCurrencyCode = 'EUR';
73+
$this->storeManagerMock->expects($this->once())
74+
->method('getStore')
75+
->with($storeIds[0])
76+
->willReturn($storeMock);
77+
$storeMock->expects($this->once())
78+
->method('getBaseCurrencyCode')
79+
->willReturn($expectedCurrencyCode);
80+
} else {
81+
$expectedCurrencyCode = 'USD';
82+
$this->storeManagerMock->expects($this->once())
83+
->method('getStore')
84+
->with(1)
85+
->willReturn($storeMock);
86+
$this->storeManagerMock->expects($this->once())
87+
->method('getStores')
88+
->willReturn([1 => $storeMock]);
89+
$storeMock->expects($this->once())
90+
->method('getBaseCurrencyCode')
91+
->willReturn($expectedCurrencyCode);
92+
}
93+
94+
$currencyCode = $this->model->getCurrentCurrencyCode();
95+
$this->assertEquals($expectedCurrencyCode, $currencyCode);
96+
}
97+
98+
/**
99+
* DataProvider for testGetCurrentCurrencyCode.
100+
*
101+
* @return array
102+
*/
103+
public function getCurrentCurrencyCodeDataProvider()
104+
{
105+
return [
106+
[[]],
107+
[[2]],
108+
];
109+
}
110+
}

0 commit comments

Comments
 (0)