コード例 #1
0
 /**
  * @dataProvider isPaymentEnabledDataProvider
  */
 public function testIsPaymentEnabled($groupConfig, $expected)
 {
     $this->_element->setGroup($groupConfig);
     $this->_backendConfig->expects($this->any())->method('getConfigDataValue')->will($this->returnValueMap([[self::CONFIG_PATH_ACTIVE, null, null, '1'], [self::CONFIG_PATH_NOT_ACTIVE, null, null, '0']]));
     $html = $this->_model->render($this->_element);
     $this->assertContains($expected, $html);
 }
コード例 #2
0
ファイル: Backend.php プロジェクト: aiesh/magento2
 /**
  * Get selected merchant country code in system configuration
  *
  * @return string
  */
 public function getConfigurationCountryCode()
 {
     $countryCode = $this->_request->getParam(\Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY);
     if (is_null($countryCode) || preg_match('/^[a-zA-Z]{2}$/', $countryCode) == 0) {
         $countryCode = $this->_backendConfig->getConfigDataValue(\Magento\Paypal\Block\Adminhtml\System\Config\Field\Country::FIELD_CONFIG_PATH);
     }
     if (empty($countryCode)) {
         $countryCode = $this->_coreHelper->getDefaultCountry();
     }
     return $countryCode;
 }
コード例 #3
0
 /**
  * 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);
 }
コード例 #4
0
ファイル: Payment.php プロジェクト: aiesh/magento2
 /**
  * Check whether current payment method is enabled
  *
  * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  * @return bool
  */
 protected function _isPaymentEnabled($element)
 {
     $groupConfig = $element->getGroup();
     $activityPaths = isset($groupConfig['activity_path']) ? $groupConfig['activity_path'] : [];
     if (!is_array($activityPaths)) {
         $activityPaths = [$activityPaths];
     }
     $isPaymentEnabled = false;
     foreach ($activityPaths as $activityPath) {
         $isPaymentEnabled = $isPaymentEnabled || (bool) (string) $this->_backendConfig->getConfigDataValue($activityPath);
     }
     return $isPaymentEnabled;
 }
コード例 #5
0
 /**
  * Initialize config group fields
  *
  * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset
  * @param \Magento\Backend\Model\Config\Structure\Element\Group $group
  * @param \Magento\Backend\Model\Config\Structure\Element\Section $section
  * @param string $fieldPrefix
  * @param string $labelPrefix
  * @return $this
  */
 public function initFields(\Magento\Framework\Data\Form\Element\Fieldset $fieldset, \Magento\Backend\Model\Config\Structure\Element\Group $group, \Magento\Backend\Model\Config\Structure\Element\Section $section, $fieldPrefix = '', $labelPrefix = '')
 {
     if (!$this->_configDataObject) {
         $this->_initObjects();
     }
     // Extends for config data
     $extraConfigGroups = [];
     /** @var $element \Magento\Backend\Model\Config\Structure\Element\Field */
     foreach ($group->getChildren() as $element) {
         if ($element instanceof \Magento\Backend\Model\Config\Structure\Element\Group) {
             $this->_initGroup($element, $section, $fieldset);
         } else {
             $path = $element->getConfigPath() ?: $element->getPath($fieldPrefix);
             if ($element->getSectionId() != $section->getId()) {
                 $groupPath = $element->getGroupPath();
                 if (!isset($extraConfigGroups[$groupPath])) {
                     $this->_configData = $this->_configDataObject->extendConfig($groupPath, false, $this->_configData);
                     $extraConfigGroups[$groupPath] = true;
                 }
             }
             $this->_initElement($element, $fieldset, $path, $fieldPrefix, $labelPrefix);
         }
     }
     return $this;
 }
コード例 #6
0
 /**
  * @param string $path
  * @param string $expectedException
  *
  * @dataProvider setDataByPathWrongDepthDataProvider
  */
 public function testSetDataByPathWrongDepth($path, $expectedException)
 {
     $expectedException = 'Allowed depth of configuration is 3 (<section>/<group>/<field>). ' . $expectedException;
     $this->setExpectedException('\\UnexpectedValueException', $expectedException);
     $value = 'value';
     $this->_model->setDataByPath($path, $value);
 }
コード例 #7
0
ファイル: ConfigTest.php プロジェクト: Atlis/docker-magento2
 public function testSaveToCheckScopeDataSet()
 {
     $transactionMock = $this->getMock('Magento\\Framework\\DB\\Transaction', array(), array(), '', false);
     $this->_transFactoryMock->expects($this->any())->method('create')->will($this->returnValue($transactionMock));
     $this->_configLoaderMock->expects($this->any())->method('getConfigByPath')->will($this->returnValue(array()));
     $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\\Backend\\Model\\Config\\Structure\\Element\\Group', array(), array(), '', false);
     $field = $this->getMock('Magento\\Backend\\Model\\Config\\Structure\\Element\\Field', array(), array(), '', 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', array(), array(), '', false);
     $this->_storeManager->expects($this->any())->method('getWebsite')->will($this->returnValue($website));
     $this->_storeManager->expects($this->any())->method('getWebsites')->will($this->returnValue(array($website)));
     $this->_storeManager->expects($this->any())->method('isSingleStoreMode')->will($this->returnValue(true));
     $this->_model->setWebsite('website');
     $this->_model->setGroups(array('1' => array('fields' => array('key' => array('data')))));
     $backendModel = $this->getMock('Magento\\Framework\\App\\Config\\Value', array('setPath', 'addData', '__sleep', '__wakeup'), array(), '', false);
     $backendModel->expects($this->once())->method('addData')->with(array('field' => 'key', 'groups' => array(1 => array('fields' => array('key' => array('data')))), 'group_id' => null, 'scope' => 'websites', 'scope_id' => 0, 'scope_code' => 'website', 'field_config' => null, 'fieldset_data' => array('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();
 }
コード例 #8
0
 /**
  * Prepare backend config for test
  *
  * @param string|null|false $config
  */
 private function _configurationCountryCodePrepareConfig($config)
 {
     $this->_backendConfig->expects($this->once())->method('getConfigDataValue')->with(\Magento\Paypal\Block\Adminhtml\System\Config\Field\Country::FIELD_CONFIG_PATH)->will($this->returnValue($config));
 }