Skip to content

Commit af78c2f

Browse files
committed
Test coverage for read only fields
1 parent ab3f767 commit af78c2f

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

app/code/Magento/Config/Test/Unit/Model/ConfigTest.php

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ class ConfigTest extends \PHPUnit\Framework\TestCase
6060
*/
6161
protected $_configStructure;
6262

63+
/**
64+
* @var \PHPUnit_Framework_MockObject_MockObject
65+
*/
66+
private $_settingsChecker;
67+
6368
protected function setUp()
6469
{
6570
$this->_eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
@@ -79,7 +84,7 @@ protected function setUp()
7984

8085
$this->_transFactoryMock = $this->createPartialMock(
8186
\Magento\Framework\DB\TransactionFactory::class,
82-
['create']
87+
['create', 'addObject']
8388
);
8489
$this->_appConfigMock = $this->createMock(\Magento\Framework\App\Config\ReinitableConfigInterface::class);
8590
$this->_configLoaderMock = $this->createPartialMock(
@@ -90,14 +95,18 @@ protected function setUp()
9095

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

98+
$this->_settingsChecker = $this
99+
->createMock(\Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker::class);
100+
93101
$this->_model = new \Magento\Config\Model\Config(
94102
$this->_appConfigMock,
95103
$this->_eventManagerMock,
96104
$this->_configStructure,
97105
$this->_transFactoryMock,
98106
$this->_configLoaderMock,
99107
$this->_dataFactoryMock,
100-
$this->_storeManager
108+
$this->_storeManager,
109+
$this->_settingsChecker
101110
);
102111
}
103112

@@ -149,6 +158,49 @@ public function testSaveToCheckAdminSystemConfigChangedSectionEvent()
149158
$this->_model->save();
150159
}
151160

161+
public function testDoNotSaveReadOnlyFields()
162+
{
163+
$transactionMock = $this->createMock(\Magento\Framework\DB\Transaction::class);
164+
$this->_transFactoryMock->expects($this->any())->method('create')->will($this->returnValue($transactionMock));
165+
166+
$this->_settingsChecker->expects($this->any())->method('isReadOnly')->will($this->returnValue(true));
167+
$this->_configLoaderMock->expects($this->any())->method('getConfigByPath')->will($this->returnValue([]));
168+
169+
$this->_model->setGroups(['1' => ['fields' => ['key' => ['data']]]]);
170+
$this->_model->setSection('section');
171+
172+
$group = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Group::class);
173+
$group->method('getPath')->willReturn('section/1');
174+
175+
$field = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Field::class);
176+
$field->method('getGroupPath')->willReturn('section/1');
177+
$field->method('getId')->willReturn('key');
178+
179+
$this->_configStructure->expects($this->at(0))
180+
->method('getElement')
181+
->with('section/1')
182+
->will($this->returnValue($group));
183+
$this->_configStructure->expects($this->at(1))
184+
->method('getElement')
185+
->with('section/1')
186+
->will($this->returnValue($group));
187+
$this->_configStructure->expects($this->at(2))
188+
->method('getElement')
189+
->with('section/1/key')
190+
->will($this->returnValue($field));
191+
192+
$backendModel = $this->createPartialMock(
193+
\Magento\Framework\App\Config\Value::class,
194+
['addData']
195+
);
196+
$this->_dataFactoryMock->expects($this->any())->method('create')->will($this->returnValue($backendModel));
197+
198+
$this->_transFactoryMock->expects($this->never())->method('addObject');
199+
$backendModel->expects($this->never())->method('addData');
200+
201+
$this->_model->save();
202+
}
203+
152204
public function testSaveToCheckScopeDataSet()
153205
{
154206
$transactionMock = $this->createMock(\Magento\Framework\DB\Transaction::class);

0 commit comments

Comments
 (0)