/**
  * Sets scope for backend config
  *
  * @param string $sectionId
  * @return bool
  */
 protected function isSectionAllowed($sectionId)
 {
     $website = $this->getRequest()->getParam('website');
     $store = $this->getRequest()->getParam('store');
     if ($store) {
         $this->_backendConfig->setStore($store);
     } elseif ($website) {
         $this->_backendConfig->setWebsite($website);
     }
     return parent::isSectionAllowed($sectionId);
 }
 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();
 }