Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue with reading store config for store with code of 'default' #1406

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, ''],
];
}
}