Skip to content

Commit

Permalink
Test coverage for read only fields
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 committed Jun 26, 2018
1 parent ab3f767 commit af78c2f
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions app/code/Magento/Config/Test/Unit/Model/ConfigTest.php
Expand Up @@ -60,6 +60,11 @@ class ConfigTest extends \PHPUnit\Framework\TestCase
*/
protected $_configStructure;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $_settingsChecker;

protected function setUp()
{
$this->_eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
Expand All @@ -79,7 +84,7 @@ protected function setUp()

$this->_transFactoryMock = $this->createPartialMock(
\Magento\Framework\DB\TransactionFactory::class,
['create']
['create', 'addObject']
);
$this->_appConfigMock = $this->createMock(\Magento\Framework\App\Config\ReinitableConfigInterface::class);
$this->_configLoaderMock = $this->createPartialMock(
Expand All @@ -90,14 +95,18 @@ protected function setUp()

$this->_storeManager = $this->getMockForAbstractClass(\Magento\Store\Model\StoreManagerInterface::class);

$this->_settingsChecker = $this
->createMock(\Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker::class);

$this->_model = new \Magento\Config\Model\Config(
$this->_appConfigMock,
$this->_eventManagerMock,
$this->_configStructure,
$this->_transFactoryMock,
$this->_configLoaderMock,
$this->_dataFactoryMock,
$this->_storeManager
$this->_storeManager,
$this->_settingsChecker
);
}

Expand Down Expand Up @@ -149,6 +158,49 @@ public function testSaveToCheckAdminSystemConfigChangedSectionEvent()
$this->_model->save();
}

public function testDoNotSaveReadOnlyFields()
{
$transactionMock = $this->createMock(\Magento\Framework\DB\Transaction::class);
$this->_transFactoryMock->expects($this->any())->method('create')->will($this->returnValue($transactionMock));

$this->_settingsChecker->expects($this->any())->method('isReadOnly')->will($this->returnValue(true));
$this->_configLoaderMock->expects($this->any())->method('getConfigByPath')->will($this->returnValue([]));

$this->_model->setGroups(['1' => ['fields' => ['key' => ['data']]]]);
$this->_model->setSection('section');

$group = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Group::class);
$group->method('getPath')->willReturn('section/1');

$field = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Field::class);
$field->method('getGroupPath')->willReturn('section/1');
$field->method('getId')->willReturn('key');

$this->_configStructure->expects($this->at(0))
->method('getElement')
->with('section/1')
->will($this->returnValue($group));
$this->_configStructure->expects($this->at(1))
->method('getElement')
->with('section/1')
->will($this->returnValue($group));
$this->_configStructure->expects($this->at(2))
->method('getElement')
->with('section/1/key')
->will($this->returnValue($field));

$backendModel = $this->createPartialMock(
\Magento\Framework\App\Config\Value::class,
['addData']
);
$this->_dataFactoryMock->expects($this->any())->method('create')->will($this->returnValue($backendModel));

$this->_transFactoryMock->expects($this->never())->method('addObject');
$backendModel->expects($this->never())->method('addData');

$this->_model->save();
}

public function testSaveToCheckScopeDataSet()
{
$transactionMock = $this->createMock(\Magento\Framework\DB\Transaction::class);
Expand Down

0 comments on commit af78c2f

Please sign in to comment.