1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Backend\Test\Unit\Block\Store;
class SwitcherTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Backend\Block\Store\Switcher
*/
private $switcherBlock;
private $storeManagerMock;
protected function setUp()
{
$this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$context = $objectHelper->getObject(
\Magento\Backend\Block\Template\Context::class,
[
'storeManager' => $this->storeManagerMock,
]
);
$this->switcherBlock = $objectHelper->getObject(
\Magento\Backend\Block\Store\Switcher::class,
['context' => $context]
);
}
public function testGetWebsites()
{
$websiteMock = $this->createMock(\Magento\Store\Model\Website::class);
$websites = [0 => $websiteMock, 1 => $websiteMock];
$this->storeManagerMock->expects($this->once())->method('getWebsites')->will($this->returnValue($websites));
$this->assertEquals($websites, $this->switcherBlock->getWebsites());
}
public function testGetWebsitesIfSetWebsiteIds()
{
$websiteMock = $this->createMock(\Magento\Store\Model\Website::class);
$websites = [0 => $websiteMock, 1 => $websiteMock];
$this->storeManagerMock->expects($this->once())->method('getWebsites')->will($this->returnValue($websites));
$this->switcherBlock->setWebsiteIds([1]);
$expected = [1 => $websiteMock];
$this->assertEquals($expected, $this->switcherBlock->getWebsites());
}
}