/** * Initialize properties of object required for test. * * @return \Magento\Backend\Block\System\Config\Form */ protected function _initObjects() { parent::_initObjects(); $this->_configData = $this->_configDataStub; if ($this->_configRootStub) { $this->_configRoot = $this->_configRootStub; } $this->_fieldRenderer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Backend\\Block\\System\\Config\\Form\\Field'); }
/** * @dataProvider initFieldsDataProvider * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testInitFields($backendConfigValue, $configValue, $configPath, $inherit, $expectedValue) { // Parameters initialization $fieldsetMock = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false, false); $groupMock = $this->getMock('Magento\\Backend\\Model\\Config\\Structure\\Element\\Group', [], [], '', false, false); $sectionMock = $this->getMock('Magento\\Backend\\Model\\Config\\Structure\\Element\\Section', [], [], '', false, false); $fieldPrefix = 'fieldPrefix'; $labelPrefix = 'labelPrefix'; // Field Renderer Mock configuration $fieldRendererMock = $this->getMock('Magento\\Backend\\Block\\System\\Config\\Form\\Field', [], [], '', false, false); $this->_fieldFactoryMock->expects($this->once())->method('create')->will($this->returnValue($fieldRendererMock)); $this->_backendConfigMock->expects($this->once())->method('extendConfig')->with('some/config/path', false, ['section1/group1/field1' => 'some_value'])->will($this->returnValue($backendConfigValue)); $this->_coreConfigMock->expects($this->any())->method('getValue')->with($configPath)->will($this->returnValue($configValue)); // Field mock configuration $fieldMock = $this->getMock('Magento\\Backend\\Model\\Config\\Structure\\Element\\Field', [], [], '', false, false); $fieldMock->expects($this->any())->method('getPath')->will($this->returnValue('section1/group1/field1')); $fieldMock->expects($this->any())->method('getConfigPath')->will($this->returnValue($configPath)); $fieldMock->expects($this->any())->method('getGroupPath')->will($this->returnValue('some/config/path')); $fieldMock->expects($this->once())->method('getSectionId')->will($this->returnValue('some_section')); $fieldMock->expects($this->once())->method('hasBackendModel')->will($this->returnValue(false)); $fieldMock->expects($this->once())->method('getDependencies')->with($fieldPrefix)->will($this->returnValue([])); $fieldMock->expects($this->any())->method('getType')->will($this->returnValue('field')); $fieldMock->expects($this->once())->method('getLabel')->will($this->returnValue('label')); $fieldMock->expects($this->once())->method('getComment')->will($this->returnValue('comment')); $fieldMock->expects($this->once())->method('getTooltip')->will($this->returnValue('tooltip')); $fieldMock->expects($this->once())->method('getHint')->will($this->returnValue('hint')); $fieldMock->expects($this->once())->method('getFrontendClass')->will($this->returnValue('frontClass')); $fieldMock->expects($this->once())->method('showInDefault')->will($this->returnValue(false)); $fieldMock->expects($this->any())->method('showInWebsite')->will($this->returnValue(false)); $fieldMock->expects($this->once())->method('getData')->will($this->returnValue('fieldData')); $fieldMock->expects($this->any())->method('getRequiredFields')->will($this->returnValue([])); $fieldMock->expects($this->any())->method('getRequiredGroups')->will($this->returnValue([])); $fields = [$fieldMock]; $groupMock->expects($this->once())->method('getChildren')->will($this->returnValue($fields)); $sectionMock->expects($this->once())->method('getId')->will($this->returnValue('section1')); $formFieldMock = $this->getMockForAbstractClass('Magento\\Framework\\Data\\Form\\Element\\AbstractElement', [], '', false, false, true, ['setRenderer']); $params = ['name' => 'groups[group1][fields][fieldPrefixfield1][value]', 'label' => 'label', 'comment' => 'comment', 'tooltip' => 'tooltip', 'hint' => 'hint', 'value' => $expectedValue, 'inherit' => $inherit, 'class' => 'frontClass', 'field_config' => 'fieldData', 'scope' => 'stores', 'scope_id' => 1, 'scope_label' => '[GLOBAL]', 'can_use_default_value' => false, 'can_use_website_value' => false]; $formFieldMock->expects($this->once())->method('setRenderer')->with($fieldRendererMock); $fieldsetMock->expects($this->once())->method('addField')->with('section1_group1_field1', 'field', $params)->will($this->returnValue($formFieldMock)); $fieldMock->expects($this->once())->method('populateInput'); $this->_object->initFields($fieldsetMock, $groupMock, $sectionMock, $fieldPrefix, $labelPrefix); }