Skip to content

Commit bc45381

Browse files
committed
MAGETWO-54458: Scope selector on product page does not display all related websites for restricted user
- Merge commit
2 parents dde7f62 + b3892d2 commit bc45381

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

app/code/Magento/Backend/Block/Store/Switcher.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
/**
1010
* Store switcher block
11-
*
12-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1311
*/
1412
class Switcher extends \Magento\Backend\Block\Template
1513
{
@@ -152,11 +150,7 @@ public function getWebsites()
152150
{
153151
$websites = $this->_storeManager->getWebsites();
154152
if ($websiteIds = $this->getWebsiteIds()) {
155-
foreach (array_keys($websites) as $websiteId) {
156-
if (!in_array($websiteId, $websiteIds)) {
157-
unset($websites[$websiteId]);
158-
}
159-
}
153+
$websites = array_intersect_key($websites, array_flip($websiteIds));
160154
}
161155
return $websites;
162156
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Test\Unit\Block\Store;
8+
9+
class SwitcherTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @var \Magento\Backend\Block\Store\Switcher
13+
*/
14+
private $switcherBlock;
15+
16+
private $storeManagerMock;
17+
18+
protected function setUp()
19+
{
20+
$this->storeManagerMock = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class);
21+
$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
22+
$context = $objectHelper->getObject(
23+
\Magento\Backend\Block\Template\Context::class,
24+
[
25+
'storeManager' => $this->storeManagerMock,
26+
]
27+
);
28+
29+
$this->switcherBlock = $objectHelper->getObject(
30+
\Magento\Backend\Block\Store\Switcher::class,
31+
['context' => $context]
32+
);
33+
}
34+
35+
public function testGetWebsites()
36+
{
37+
$websiteMock = $this->getMock(\Magento\Store\Model\Website::class, [], [], '', false);
38+
$websites = [0 => $websiteMock, 1 => $websiteMock];
39+
$this->storeManagerMock->expects($this->once())->method('getWebsites')->will($this->returnValue($websites));
40+
$this->assertEquals($websites, $this->switcherBlock->getWebsites());
41+
}
42+
43+
public function testGetWebsitesIfSetWebsiteIds()
44+
{
45+
$websiteMock = $this->getMock(\Magento\Store\Model\Website::class, [], [], '', false);
46+
$websites = [0 => $websiteMock, 1 => $websiteMock];
47+
$this->storeManagerMock->expects($this->once())->method('getWebsites')->will($this->returnValue($websites));
48+
49+
$this->switcherBlock->setWebsiteIds([1]);
50+
$expected = [1 => $websiteMock];
51+
$this->assertEquals($expected, $this->switcherBlock->getWebsites());
52+
}
53+
}

0 commit comments

Comments
 (0)