Skip to content

Commit

Permalink
Resolves issue where store with code of 'default' fails to correctly …
Browse files Browse the repository at this point in the history
…load associated config valueues when not configured as default store.
  • Loading branch information
David Alger committed Jun 24, 2015
1 parent cfa26be commit 54ec80a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 52 deletions.
2 changes: 0 additions & 2 deletions app/code/Magento/Store/Model/Config/Reader/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
99 changes: 49 additions & 50 deletions app/code/Magento/Store/Test/Unit/Model/Config/Reader/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -151,9 +150,9 @@ public function testRead($storeCode, $storeMethod)
public function readDataProvider()
{
return [
['default', 'getDefaultStoreView'],
[null, 'getStore'],
['code', '']
['code', ''],
[ScopeConfigInterface::SCOPE_TYPE_DEFAULT, ''],
];
}
}

0 comments on commit 54ec80a

Please sign in to comment.