Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StoresConfigTest.php
Go to the documentation of this file.
1 <?php
10 
11 class StoresConfigTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $_model;
17 
21  protected $_storeManager;
22 
26  protected $_storeOne;
27 
31  protected $_storeTwo;
32 
36  protected $_config;
37 
38  protected function setUp()
39  {
40  $this->_storeOne = $this->createMock(\Magento\Store\Model\Store::class);
41  $this->_storeTwo = $this->createMock(\Magento\Store\Model\Store::class);
42  $this->_storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
43  $this->_config = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
44 
45  $this->_model = new \Magento\Store\Model\StoresConfig(
46  $this->_storeManager,
47  $this->_config
48  );
49  }
50 
51  public function testGetStoresConfigByPath()
52  {
53  $path = 'config/path';
54 
55  $this->_storeOne
56  ->expects($this->at(0))
57  ->method('getCode')
58  ->will($this->returnValue('code_0'));
59 
60  $this->_storeOne
61  ->expects($this->at(1))
62  ->method('getId')
63  ->will($this->returnValue(0));
64 
65  $this->_storeTwo
66  ->expects($this->at(0))
67  ->method('getCode')
68  ->will($this->returnValue('code_1'));
69 
70  $this->_storeTwo
71  ->expects($this->at(1))
72  ->method('getId')
73  ->will($this->returnValue(1));
74 
75  $this->_storeManager
76  ->expects($this->once())
77  ->method('getStores')
78  ->with(true)
79  ->will($this->returnValue([0 => $this->_storeOne, 1 => $this->_storeTwo]));
80 
81  $this->_config
82  ->expects($this->at(0))
83  ->method('getValue')
84  ->with($path, 'store', 'code_0')
85  ->will($this->returnValue(0));
86 
87  $this->_config
88  ->expects($this->at(1))
89  ->method('getValue')
90  ->with($path, 'store', 'code_1')
91  ->will($this->returnValue(1));
92 
93  $this->assertEquals([0 => 0, 1 => 1], $this->_model->getStoresConfigByPath($path));
94  }
95 }