diff --git a/app/code/Magento/Store/Model/Config/Reader/Store.php b/app/code/Magento/Store/Model/Config/Reader/Store.php index 151c3625f2b1d..787b6d6dbfb94 100644 --- a/app/code/Magento/Store/Model/Config/Reader/Store.php +++ b/app/code/Magento/Store/Model/Config/Reader/Store.php @@ -75,8 +75,6 @@ public function read($code = null) { if (empty($code)) { $store = $this->_storeManager->getStore(); - } elseif (($code == ScopeConfigInterface::SCOPE_TYPE_DEFAULT)) { - $store = $this->_storeManager->getDefaultStoreView(); } else { $store = $this->_storeFactory->create(); $store->load($code); diff --git a/app/code/Magento/Store/Test/Unit/Model/Config/Reader/StoreTest.php b/app/code/Magento/Store/Test/Unit/Model/Config/Reader/StoreTest.php index bb1fb3e025a03..5efea71aeb2c6 100644 --- a/app/code/Magento/Store/Test/Unit/Model/Config/Reader/StoreTest.php +++ b/app/code/Magento/Store/Test/Unit/Model/Config/Reader/StoreTest.php @@ -5,6 +5,9 @@ */ namespace Magento\Store\Test\Unit\Model\Config\Reader; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Object; + class StoreTest extends \PHPUnit_Framework_TestCase { /** @@ -44,9 +47,14 @@ protected function setUp() '', false ); + $storeFactoryMock = $this->getMock('Magento\Store\Model\StoreFactory', ['create'], [], '', false); $this->_storeMock = $this->getMock('Magento\Store\Model\Store', [], [], '', false); - $storeFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->_storeMock)); + $this->_defaultStoreMock = $this->getMock('Magento\Store\Model\Store', [], [], '', false); + + $storeFactoryMock->expects($this->any()) + ->method('create') + ->will($this->returnValue($this->_storeMock)); $placeholderProcessor = $this->getMock( 'Magento\Store\Model\Config\Processor\Placeholder', @@ -75,68 +83,59 @@ public function testRead($storeCode, $storeMethod) { $websiteCode = 'default'; $storeId = 1; + $defaultStoreCode = 'foostore'; + $defaultStoreId = 2; + $websiteMock = $this->getMock('Magento\Store\Model\Website', [], [], '', false); $websiteMock->expects($this->any())->method('getCode')->will($this->returnValue($websiteCode)); + $this->_storeMock->expects($this->any())->method('getWebsite')->will($this->returnValue($websiteMock)); $this->_storeMock->expects($this->any())->method('load')->with($storeCode); $this->_storeMock->expects($this->any())->method('getId')->will($this->returnValue($storeId)); $this->_storeMock->expects($this->any())->method('getCode')->will($this->returnValue($websiteCode)); + $this->_defaultStoreMock->expects($this->any())->method('getWebsite')->will($this->returnValue($websiteMock)); + $this->_defaultStoreMock->expects($this->any())->method('load')->with($defaultStoreCode); + $this->_defaultStoreMock->expects($this->any())->method('getId')->will($this->returnValue($defaultStoreId)); + $this->_defaultStoreMock->expects($this->any())->method('getCode')->will($this->returnValue($defaultStoreCode)); + $dataMock = $this->getMock('Magento\Framework\App\Config\Data', [], [], '', false); - $dataMock->expects( - $this->any() - )->method( - 'getValue' - )->will( - $this->returnValue(['config' => ['key0' => 'website_value0', 'key1' => 'website_value1']]) - ); + $dataMock->expects($this->any()) + ->method('getValue') + ->will($this->returnValue(['config' => ['key0' => 'website_value0', 'key1' => 'website_value1']])); - $dataMock->expects( - $this->once() - )->method( - 'getSource' - )->will( - $this->returnValue(['config' => ['key0' => 'website_value0', 'key1' => 'website_value1']]) - ); - $this->_scopePullMock->expects( - $this->once() - )->method( - 'getScope' - )->with( - 'website', - $websiteCode - )->will( - $this->returnValue($dataMock) - ); + $dataMock->expects($this->once()) + ->method('getSource') + ->will($this->returnValue(['config' => ['key0' => 'website_value0', 'key1' => 'website_value1']])); - $this->_initialConfigMock->expects( - $this->once() - )->method( - 'getData' - )->with( - "stores|{$storeCode}" - )->will( - $this->returnValue(['config' => ['key1' => 'store_value1', 'key2' => 'store_value2']]) - ); - $this->_collectionFactory->expects( - $this->once() - )->method( - 'create' - )->with( - ['scope' => 'stores', 'scopeId' => $storeId] - )->will( - $this->returnValue( + $this->_scopePullMock->expects($this->once()) + ->method('getScope') + ->with('website', $websiteCode) + ->will($this->returnValue($dataMock)); + + $this->_initialConfigMock->expects($this->once()) + ->method('getData') + ->with("stores|{$storeCode}") + ->will($this->returnValue(['config' => ['key1' => 'store_value1', 'key2' => 'store_value2']])); + + $this->_collectionFactory->expects($this->once()) + ->method('create') + ->with(['scope' => 'stores', 'scopeId' => $storeId]) + ->will($this->returnValue( [ - new \Magento\Framework\Object(['path' => 'config/key1', 'value' => 'store_db_value1']), - new \Magento\Framework\Object(['path' => 'config/key3', 'value' => 'store_db_value3']), + new Object(['path' => 'config/key1', 'value' => 'store_db_value1']), + new Object(['path' => 'config/key3', 'value' => 'store_db_value3']), ] - ) - ); + )); - $this->_storeManagerMock - ->expects($this->any()) + $this->_storeManagerMock->expects($this->any()) + ->method('getDefaultStoreView') + ->will($this->returnValue($this->_defaultStoreMock)); + + $this->_storeManagerMock->expects($this->any()) ->method($storeMethod) ->will($this->returnValue($this->_storeMock)); + $expectedData = [ 'config' => [ 'key0' => 'website_value0', @@ -151,9 +150,9 @@ public function testRead($storeCode, $storeMethod) public function readDataProvider() { return [ - ['default', 'getDefaultStoreView'], [null, 'getStore'], - ['code', ''] + ['code', ''], + [ScopeConfigInterface::SCOPE_TYPE_DEFAULT, ''], ]; } }