Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StoreConfigurationProviderTest.php
Go to the documentation of this file.
1 <?php
8 
14 
15 class StoreConfigurationProviderTest extends \PHPUnit\Framework\TestCase
16 {
20  private $scopeConfigMock;
21 
25  private $configPaths;
26 
30  private $storeManagerMock;
31 
35  private $websiteMock;
36 
40  private $storeMock;
41 
45  private $storeConfigurationProvider;
46 
50  protected function setUp()
51  {
52  $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55 
56  $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
57  ->disableOriginalConstructor()
58  ->getMock();
59 
60  $this->websiteMock = $this->getMockBuilder(WebsiteInterface::class)
61  ->disableOriginalConstructor()
62  ->getMock();
63 
64  $this->storeMock = $this->getMockBuilder(StoreInterface::class)
65  ->disableOriginalConstructor()
66  ->getMock();
67 
68  $this->configPaths = [
69  'web/unsecure/base_url',
70  'currency/options/base',
71  'general/locale/timezone'
72  ];
73 
74  $this->storeConfigurationProvider = new StoreConfigurationProvider(
75  $this->scopeConfigMock,
76  $this->storeManagerMock,
77  $this->configPaths
78  );
79  }
80 
81  public function testGetReport()
82  {
83  $map = [
84  ['web/unsecure/base_url', 'default', 0, '127.0.0.1'],
85  ['currency/options/base', 'default', 0, 'USD'],
86  ['general/locale/timezone', 'default', 0, 'America/Dawson'],
87  ['web/unsecure/base_url', 'websites', 1, '127.0.0.2'],
88  ['currency/options/base', 'websites', 1, 'USD'],
89  ['general/locale/timezone', 'websites', 1, 'America/Belem'],
90  ['web/unsecure/base_url', 'stores', 2, '127.0.0.3'],
91  ['currency/options/base', 'stores', 2, 'USD'],
92  ['general/locale/timezone', 'stores', 2, 'America/Phoenix'],
93  ];
94 
95  $this->scopeConfigMock
96  ->method('getValue')
97  ->will($this->returnValueMap($map));
98 
99  $this->storeManagerMock->expects($this->once())
100  ->method('getWebsites')
101  ->willReturn([$this->websiteMock]);
102 
103  $this->storeManagerMock->expects($this->once())
104  ->method('getStores')
105  ->willReturn([$this->storeMock]);
106 
107  $this->websiteMock->expects($this->once())
108  ->method('getId')
109  ->willReturn(1);
110 
111  $this->storeMock->expects($this->once())
112  ->method('getId')
113  ->willReturn(2);
114  $result = iterator_to_array($this->storeConfigurationProvider->getReport());
115  $resultValues = [];
116  foreach ($result as $item) {
117  $resultValues[] = array_values($item);
118  }
119  array_multisort($resultValues);
120  array_multisort($map);
121  $this->assertEquals($resultValues, $map);
122  }
123 }