protected function setUp() { $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->scopeConfigMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $this->scopeConfigMock->expects($this->any())->method('getValue')->willReturn(['test' => 1]); $this->structureMock = $this->getMock('Magento\\Config\\Model\\Config\\Structure', [], [], '', false); $this->structureMock->expects($this->any())->method('getFieldPathsByAttribute')->willReturn(['path' => 'test']); $this->resourceModelMock = $this->getMock('Magento\\Email\\Model\\Resource\\Template', [], [], '', false); $this->resourceModelMock->expects($this->any())->method('getSystemConfigByPathsAndTemplateId')->willReturn(['test_config' => 2015]); $objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface'); $objectManagerMock->expects($this->any())->method('get')->with('Magento\\Email\\Model\\Resource\\Template')->will($this->returnValue($this->resourceModelMock)); \Magento\Framework\App\ObjectManager::setInstance($objectManagerMock); $this->model = $helper->getObject('Magento\\Email\\Model\\BackendTemplate', ['scopeConfig' => $this->scopeConfigMock, 'structure' => $this->structureMock]); }
private function setUpChangeEncryptionKey() { $paths = ['path1', 'path2']; $table = ['item1', 'item2']; $values = ['key1' => 'value1', 'key2' => 'value2']; $this->writerMock->expects($this->once())->method('checkIfWritable')->willReturn(true); $this->resourceMock->expects($this->atLeastOnce())->method('getConnection')->willReturn($this->adapterMock); $this->adapterMock->expects($this->once())->method('beginTransaction'); $this->structureMock->expects($this->once())->method('getFieldPathsByAttribute')->willReturn($paths); $this->resourceMock->expects($this->atLeastOnce())->method('getTableName')->willReturn($table); $this->adapterMock->expects($this->any())->method('select')->willReturn($this->selectMock); $this->adapterMock->expects($this->any())->method('fetchPairs')->willReturn($values); $this->selectMock->expects($this->any())->method('from')->willReturnSelf(); $this->selectMock->expects($this->atLeastOnce())->method('where')->willReturnSelf(); $this->selectMock->expects($this->any())->method('update')->willReturnSelf(); $this->writerMock->expects($this->once())->method('saveConfig'); $this->adapterMock->expects($this->once())->method('getTransactionLevel')->willReturn(1); }
public function testSaveToCheckScopeDataSet() { $transactionMock = $this->getMock('Magento\\Framework\\DB\\Transaction', [], [], '', false); $this->_transFactoryMock->expects($this->any())->method('create')->will($this->returnValue($transactionMock)); $this->_configLoaderMock->expects($this->any())->method('getConfigByPath')->will($this->returnValue([])); $this->_eventManagerMock->expects($this->at(0))->method('dispatch')->with($this->equalTo('admin_system_config_changed_section_'), $this->arrayHasKey('website')); $this->_eventManagerMock->expects($this->at(0))->method('dispatch')->with($this->equalTo('admin_system_config_changed_section_'), $this->arrayHasKey('store')); $group = $this->getMock('Magento\\Config\\Model\\Config\\Structure\\Element\\Group', [], [], '', false); $field = $this->getMock('Magento\\Config\\Model\\Config\\Structure\\Element\\Field', [], [], '', false); $this->_configStructure->expects($this->at(0))->method('getElement')->with('/1')->will($this->returnValue($group)); $this->_configStructure->expects($this->at(1))->method('getElement')->with('/1/key')->will($this->returnValue($field)); $website = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false); $website->expects($this->any())->method('getCode')->will($this->returnValue('website_code')); $this->_storeManager->expects($this->any())->method('getWebsite')->will($this->returnValue($website)); $this->_storeManager->expects($this->any())->method('getWebsites')->will($this->returnValue([$website])); $this->_storeManager->expects($this->any())->method('isSingleStoreMode')->will($this->returnValue(true)); $this->_model->setWebsite('website'); $this->_model->setGroups(['1' => ['fields' => ['key' => ['data']]]]); $backendModel = $this->getMock('Magento\\Framework\\App\\Config\\Value', ['setPath', 'addData', '__sleep', '__wakeup'], [], '', false); $backendModel->expects($this->once())->method('addData')->with(['field' => 'key', 'groups' => [1 => ['fields' => ['key' => ['data']]]], 'group_id' => null, 'scope' => 'websites', 'scope_id' => 0, 'scope_code' => 'website_code', 'field_config' => null, 'fieldset_data' => ['key' => null]]); $backendModel->expects($this->once())->method('setPath')->with('/key')->will($this->returnValue($backendModel)); $this->_dataFactoryMock->expects($this->any())->method('create')->will($this->returnValue($backendModel)); $this->_model->save(); }