Пример #1
0
 /**
  * Check whether survey question can show
  *
  * @return bool
  */
 public function isDisplayed()
 {
     if ($this->_authSession->getHideSurveyQuestion() || false == $this->_authorization->isAllowed(null) || $this->_survey->isSurveyViewed() || false == $this->_survey->isSurveyUrlValid()) {
         return false;
     }
     return true;
 }
Пример #2
0
 /**
  * Handler for all SOAP operations.
  *
  * @param string $operation
  * @param array $arguments
  * @return \stdClass|null
  * @throws WebapiException
  * @throws \LogicException
  * @throws AuthorizationException
  */
 public function __call($operation, $arguments)
 {
     $requestedServices = $this->_request->getRequestedServices();
     $serviceMethodInfo = $this->_apiConfig->getServiceMethodInfo($operation, $requestedServices);
     $serviceClass = $serviceMethodInfo[SoapConfig::KEY_CLASS];
     $serviceMethod = $serviceMethodInfo[SoapConfig::KEY_METHOD];
     // check if the operation is a secure operation & whether the request was made in HTTPS
     if ($serviceMethodInfo[SoapConfig::KEY_IS_SECURE] && !$this->_request->isSecure()) {
         throw new WebapiException(__("Operation allowed only in HTTPS"));
     }
     $isAllowed = false;
     foreach ($serviceMethodInfo[SoapConfig::KEY_ACL_RESOURCES] as $resource) {
         if ($this->_authorization->isAllowed($resource)) {
             $isAllowed = true;
             break;
         }
     }
     if (!$isAllowed) {
         throw new AuthorizationException(__(AuthorizationException::NOT_AUTHORIZED, ['resources' => implode(', ', $serviceMethodInfo[SoapConfig::KEY_ACL_RESOURCES])]));
     }
     $service = $this->_objectManager->get($serviceClass);
     $inputData = $this->_prepareRequestData($serviceClass, $serviceMethod, $arguments);
     $outputData = call_user_func_array([$service, $serviceMethod], $inputData);
     return $this->_prepareResponseData($outputData, $serviceClass, $serviceMethod);
 }
 /**
  * Replace standard admin login form with HTTP Basic authentication
  *
  * @param AbstractAction $subject
  * @param callable $proceed
  * @param RequestInterface $request
  * @return ResponseInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function aroundDispatch(AbstractAction $subject, \Closure $proceed, RequestInterface $request)
 {
     $resource = isset($this->aclResources[$request->getControllerName()]) ? isset($this->aclResources[$request->getControllerName()][$request->getActionName()]) ? $this->aclResources[$request->getControllerName()][$request->getActionName()] : $this->aclResources[$request->getControllerName()] : null;
     $type = $request->getParam('type');
     $resourceType = isset($this->aclResources[$type]) ? $this->aclResources[$type] : null;
     if (!$resource || !$resourceType) {
         return parent::aroundDispatch($subject, $proceed, $request);
     }
     $session = $this->_auth->getAuthStorage();
     // Try to login using HTTP-authentication
     if (!$session->isLoggedIn()) {
         list($login, $password) = $this->httpAuthentication->getCredentials();
         try {
             $this->_auth->login($login, $password);
         } catch (AuthenticationException $e) {
             $this->logger->critical($e);
         }
     }
     // Verify if logged in and authorized
     if (!$session->isLoggedIn() || !$this->authorization->isAllowed($resource) || !$this->authorization->isAllowed($resourceType)) {
         $this->httpAuthentication->setAuthenticationFailed('RSS Feeds');
         return $this->_response;
     }
     return parent::aroundDispatch($subject, $proceed, $request);
 }
Пример #4
0
 /**
  * Generate row url
  * @param \Magento\Framework\DataObject $item
  * @return bool|string
  */
 public function getUrl($item)
 {
     if ($this->_authorization->isAllowed('Magento_Sales::actions_view')) {
         return parent::getUrl($item);
     }
     return false;
 }
Пример #5
0
 /**
  * Create url for passed item using passed url model
  * @param \Magento\Framework\Object $item
  * @return string
  */
 public function getUrl($item)
 {
     if ($this->_authorization->isAllowed('Magento_Customer::manage') && $item->getCustomerId()) {
         return parent::getUrl($item);
     }
     return false;
 }
Пример #6
0
 /**
  * Remove massaction items in case they disallowed for user
  * @param mixed $argument
  * @return mixed
  */
 public function update($argument)
 {
     if (false === $this->authorization->isAllowed('Magento_Indexer::changeMode')) {
         unset($argument['change_mode_onthefly']);
         unset($argument['change_mode_changelog']);
     }
     return $argument;
 }
 /**
  * Block admin ability to use customer billing agreements
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute($observer)
 {
     $event = $observer->getEvent();
     $methodInstance = $event->getMethodInstance();
     if ($methodInstance instanceof \Magento\Paypal\Model\Payment\Method\Billing\AbstractAgreement && false == $this->_authorization->isAllowed('Magento_Paypal::use')) {
         $event->getResult()->isAvailable = false;
     }
 }
 /**
  * @return boolean
  */
 protected function canAddAttributes()
 {
     $isWrapped = $this->registry->registry('use_wrapper');
     if (!isset($isWrapped)) {
         $isWrapped = true;
     }
     return $isWrapped && $this->authorization->isAllowed('Magento_Catalog::attributes_attributes');
 }
Пример #9
0
 /**
  * @return array
  */
 public function getButtonData()
 {
     $customerId = $this->getCustomerId();
     $data = [];
     if ($customerId && $this->authorization->isAllowed('Magento_Sales::create')) {
         $data = ['label' => __('Create Order'), 'on_click' => sprintf("location.href = '%s';", $this->getCreateOrderUrl()), 'class' => 'add', 'sort_order' => 40];
     }
     return $data;
 }
Пример #10
0
 /**
  * Check if all ACL resources are allowed to be accessed by current API user.
  *
  * @param string[] $aclResources
  * @return bool
  */
 public function isAllowed($aclResources)
 {
     foreach ($aclResources as $resource) {
         if (!$this->authorization->isAllowed($resource)) {
             return false;
         }
     }
     return true;
 }
 /**
  * Block admin ability to use customer billing agreements
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     $event = $observer->getEvent();
     $methodInstance = $event->getMethodInstance();
     if ($methodInstance instanceof \Magento\Paypal\Model\Payment\Method\Billing\AbstractAgreement && false == $this->_authorization->isAllowed('Magento_Paypal::use')) {
         /** @var \Magento\Framework\DataObject $result */
         $result = $observer->getEvent()->getResult();
         $result->setData('is_available', false);
     }
 }
Пример #12
0
 /**
  * @return array
  */
 public function getButtonData()
 {
     $customerId = $this->getCustomerId();
     $data = [];
     $canModify = $customerId && $this->_authorization->isAllowed('Magefan_LoginAsCustomer::login_button');
     if ($canModify) {
         $data = ['label' => __('Login As Customer'), 'class' => 'login login-button', 'on_click' => 'window.open( \'' . $this->getInvalidateTokenUrl() . '\')', 'sort_order' => 70];
     }
     return $data;
 }
 /**
  * @param object $methodInstance
  * @param bool $isAllowed
  * @param bool $isAvailable
  * @dataProvider restrictAdminBillingAgreementUsageDataProvider
  */
 public function testExecute($methodInstance, $isAllowed, $isAvailable)
 {
     $this->_event->setMethodInstance($methodInstance);
     $this->_authorization->expects($this->any())->method('isAllowed')->with('Magento_Paypal::use')->will($this->returnValue($isAllowed));
     $result = new \stdClass();
     $result->isAvailable = true;
     $this->_event->setResult($result);
     $this->_model->execute($this->_observer);
     $this->assertEquals($isAvailable, $result->isAvailable);
 }
Пример #14
0
 /**
  * Prepare Data Source
  *
  * @param array $dataSource
  * @return array
  */
 public function prepareDataSource(array $dataSource)
 {
     if (isset($dataSource['data']['items'])) {
         $hidden = !$this->_authorization->isAllowed('Magefan_LoginAsCustomer::login_button');
         foreach ($dataSource['data']['items'] as &$item) {
             $item[$this->getData('name')]['edit'] = ['href' => $this->urlBuilder->getUrl('loginascustomer/login/login', ['customer_id' => $item['entity_id']]), 'label' => __('Login As Customer'), 'hidden' => $hidden, 'target' => '_blank'];
         }
     }
     return $dataSource;
 }
Пример #15
0
 /**
  * Delete elements that have "acl" attribute but value is "not allowed"
  * In any case, the "acl" attribute will be unset
  *
  * @param ScheduledStructure $scheduledStructure
  * @param Structure $structure
  */
 public function filterAclElements(ScheduledStructure $scheduledStructure, Structure $structure)
 {
     foreach ($scheduledStructure->getElements() as $name => $data) {
         list(, $data) = $data;
         if (isset($data['attributes']['acl']) && $data['attributes']['acl']) {
             if (!$this->authorization->isAllowed($data['attributes']['acl'])) {
                 $this->removeElement($scheduledStructure, $structure, $name);
             }
         }
     }
 }
Пример #16
0
 /**
  * Delete nodes that have "acl" attribute but value is "not allowed"
  * In any case, the "acl" attribute will be unset
  *
  * @param \Magento\Framework\Simplexml\Element $xml
  * @return void
  */
 public function filterAclNodes(\Magento\Framework\Simplexml\Element $xml)
 {
     $limitations = $xml->xpath('//*[@acl]') ?: array();
     foreach ($limitations as $node) {
         if (!$this->_authorization->isAllowed($node['acl'])) {
             $node->unsetSelf();
         } else {
             unset($node['acl']);
         }
     }
 }
Пример #17
0
 public function testFilterAclElements()
 {
     $scheduledStructureMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\ScheduledStructure')->disableOriginalConstructor()->getMock();
     $structureMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Data\\Structure')->disableOriginalConstructor()->getMock();
     $elements = ['element_0' => [0 => '', 1 => ['attributes' => ['name' => 'element_0']]], 'element_1' => [0 => '', 1 => ['attributes' => ['name' => 'element_1', 'acl' => 'acl_authorised']]], 'element_2' => [0 => '', 1 => ['attributes' => ['name' => 'element_2', 'acl' => 'acl_non_authorised']]], 'element_3' => [0 => '', 1 => ['attributes' => ['name' => 'element_3', 'acl' => 'acl_non_authorised']]]];
     $scheduledStructureMock->expects($this->once())->method('getElements')->willReturn($elements);
     $this->authorizationMock->expects($this->exactly(3))->method('isAllowed')->willReturnMap([['acl_authorised', null, true], ['acl_non_authorised', null, false]]);
     $structureMock->expects($this->exactly(3))->method('getChildren')->willReturnMap([['element_2', ['element_2_child' => []]], ['element_2_child', []], ['element_3', []]]);
     $scheduledStructureMock->expects($this->exactly(3))->method('unsetElement')->willReturnMap([['element_2', null], ['element_2_child', null], ['element_3', null]]);
     $structureMock->expects($this->exactly(2))->method('unsetElement')->willReturnMap([['element_2', true, true], ['element_3', true, true]]);
     $this->model->filterAclElements($scheduledStructureMock, $structureMock);
 }
Пример #18
0
 /**
  * Remove massaction items in case they disallowed for user
  * @param mixed $argument
  * @return mixed
  */
 public function update($argument)
 {
     if (false === $this->_authorization->isAllowed('Magento_Sales::cancel')) {
         unset($argument['cancel_order']);
     }
     if (false === $this->_authorization->isAllowed('Magento_Sales::hold')) {
         unset($argument['hold_order']);
     }
     if (false === $this->_authorization->isAllowed('Magento_Sales::unhold')) {
         unset($argument['unhold_order']);
     }
     return $argument;
 }
 /**
  * Force admin to change password
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     if (!$this->observerConfig->isPasswordChangeForced()) {
         return;
     }
     if (!$this->authSession->isLoggedIn()) {
         return;
     }
     $actionList = ['adminhtml_system_account_index', 'adminhtml_system_account_save', 'adminhtml_auth_logout'];
     /** @var \Magento\Framework\App\Action\Action $controller */
     $controller = $observer->getEvent()->getControllerAction();
     /** @var \Magento\Framework\App\RequestInterface $request */
     $request = $observer->getEvent()->getRequest();
     if ($this->authSession->getPciAdminUserIsPasswordExpired()) {
         if (!in_array($request->getFullActionName(), $actionList)) {
             if ($this->authorization->isAllowed('Magento_Backend::myaccount')) {
                 $controller->getResponse()->setRedirect($this->url->getUrl('adminhtml/system_account/'));
                 $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
                 $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_POST_DISPATCH, true);
             } else {
                 /*
                  * if admin password is expired and access to 'My Account' page is denied
                  * than we need to do force logout with error message
                  */
                 $this->authSession->clearStorage();
                 $this->session->clearStorage();
                 $this->messageManager->addErrorMessage(__('Your password has expired; please contact your administrator.'));
                 $controller->getRequest()->setDispatched(false);
             }
         }
     }
 }
Пример #20
0
 /**
  * Check whether item is allowed to the user
  *
  * @return bool
  */
 public function isAllowed()
 {
     try {
         return $this->_acl->isAllowed((string) $this->_resource);
     } catch (\Exception $e) {
         return false;
     }
 }
Пример #21
0
 public function testGetMethodAllStoresInvalid()
 {
     $this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['1']));
     $this->_authorizationMock->expects($this->any())->method('isAllowed')->will($this->returnValue(true));
     $this->storeMock->expects($this->once())->method('getCode')->willReturn('admin');
     $this->_requestMock->expects($this->once())->method('getMethod')->willReturn('get');
     $this->_restController->dispatch($this->_requestMock);
     $this->assertTrue($this->_responseMock->isException());
     $this->assertSame("Cannot perform GET operation with store code 'all'", $this->_responseMock->getException()[0]->getMessage());
 }
 /**
  * @param string $dataObjectType
  * @param string $attributeCode
  * @return bool
  */
 private function isAttributePermissionValid($dataObjectType, $attributeCode)
 {
     $typeName = $this->getRegularTypeForExtensionAttributesType($dataObjectType);
     $permissions = $this->getPermissionsForTypeAndMethod($typeName, $attributeCode);
     foreach ($permissions as $permission) {
         if (!$this->authorization->isAllowed($permission)) {
             return false;
         }
     }
     return true;
 }
 /**
  * @param bool $isPermissionAllowed
  * @param array $expectedValue
  * @dataProvider buildOutputDataArrayWithPermissionProvider
  */
 public function testBuildOutputDataArrayWithPermission($isPermissionAllowed, $expectedValue)
 {
     $dataObject = new \Magento\Framework\Reflection\Test\Unit\ExtensionAttributesObject();
     $dataObjectType = 'Magento\\Framework\\Reflection\\Test\\Unit\\ExtensionAttributesObject';
     $methodName = 'getAttrName';
     $attributeName = 'attr_name';
     $attributeValue = 'attrName';
     $this->methodsMapProcessorMock->expects($this->once())->method('getMethodsMap')->with($dataObjectType)->will($this->returnValue([$methodName => []]));
     $this->methodsMapProcessorMock->expects($this->once())->method('isMethodValidForDataField')->with($dataObjectType, $methodName)->will($this->returnValue(true));
     $this->fieldNamerMock->expects($this->once())->method('getFieldNameForMethodName')->with($methodName)->will($this->returnValue($attributeName));
     $permissionName = 'Magento_Permission';
     $this->configReaderMock->expects($this->once())->method('read')->will($this->returnValue([$dataObjectType => [$attributeName => [Converter::RESOURCE_PERMISSIONS => [$permissionName]]]]));
     $this->authorizationMock->expects($this->once())->method('isAllowed')->with($permissionName)->will($this->returnValue($isPermissionAllowed));
     if ($isPermissionAllowed) {
         $this->methodsMapProcessorMock->expects($this->once())->method('getMethodReturnType')->with($dataObjectType, $methodName)->will($this->returnValue('string'));
         $this->typeCasterMock->expects($this->once())->method('castValueToType')->with($attributeValue, 'string')->will($this->returnValue($attributeValue));
     }
     $value = $this->model->buildOutputDataArray($dataObject, $dataObjectType);
     $this->assertEquals($value, $expectedValue);
 }
Пример #24
0
 /**
  * @param array $requestData Data from the request
  * @param array $parameters Data from config about which parameters to override
  * @param array $expectedOverriddenParams Result of overriding $requestData when applying rules from $parameters
  * @param int $userId The id of the user invoking the request
  * @param int $userType The type of user invoking the request
  *
  * @dataProvider overrideParmasDataProvider
  */
 public function testOverrideParams($requestData, $parameters, $expectedOverriddenParams, $userId, $userType)
 {
     $this->_routeMock->expects($this->once())->method('getParameters')->will($this->returnValue($parameters));
     $this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['1']));
     $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
     $this->_requestMock->expects($this->any())->method('getRequestData')->will($this->returnValue($requestData));
     $this->userContextMock->expects($this->any())->method('getUserId')->will($this->returnValue($userId));
     $this->userContextMock->expects($this->any())->method('getUserType')->will($this->returnValue($userType));
     // serializer should expect overridden params
     $this->serializerMock->expects($this->once())->method('getInputData')->with($this->equalTo('Magento\\Webapi\\Controller\\TestService'), $this->equalTo('testMethod'), $this->equalTo($expectedOverriddenParams));
     $this->_restController->dispatch($this->_requestMock);
 }
Пример #25
0
 public function testAuthorizationFailed()
 {
     $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(false));
     $this->_oauthServiceMock->expects($this->any())->method('validateAccessTokenRequest')->will($this->returnValue('fred'));
     $this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['5', '6']));
     $this->_restController->dispatch($this->_requestMock);
     /** Ensure that response contains proper error message. */
     $expectedMsg = 'Consumer is not authorized to access 5, 6';
     AuthorizationException::NOT_AUTHORIZED;
     $this->assertTrue($this->_responseMock->isException());
     $exceptionArray = $this->_responseMock->getException();
     $this->assertEquals($expectedMsg, $exceptionArray[0]->getMessage());
 }
Пример #26
0
 /**
  * @covers \Magento\Cms\Model\Wysiwyg\Config::getConfig
  * @param array $data
  * @param boolean $isAuthorizationAllowed
  * @param array $expectedResults
  *
  * @dataProvider getConfigDataProvider
  */
 public function testGetConfig($data, $isAuthorizationAllowed, $expectedResults)
 {
     $wysiwygPluginSettings = ['wysiwygPluginSettings' => 'wysiwyg is here'];
     $pluginSettings = ['pluginSettings' => 'plugins are here'];
     $this->backendUrlMock->expects($this->atLeastOnce())->method('getUrl')->withConsecutive(['cms/wysiwyg/directive'], ['cms/wysiwyg_images/index']);
     $this->assetRepoMock->expects($this->atLeastOnce())->method('getUrl')->withConsecutive(['mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'], ['mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css']);
     $this->authorizationMock->expects($this->atLeastOnce())->method('isAllowed')->with('Magento_Cms::media_gallery')->willReturn($isAuthorizationAllowed);
     $this->variableConfigMock->expects($this->any())->method('getWysiwygPluginSettings')->willReturn($wysiwygPluginSettings);
     $this->widgetConfigMock->expects($this->any())->method('getPluginSettings')->willReturn($pluginSettings);
     $config = $this->wysiwygConfig->getConfig($data);
     $this->assertInstanceOf('Magento\\Framework\\Object', $config);
     $this->assertEquals($expectedResults[0], $config->getData('someData'));
     $this->assertEquals($expectedResults[1], $config->getData('wysiwygPluginSettings'));
     $this->assertEquals($expectedResults[2], $config->getData('pluginSettings'));
 }
 /**
  * Check whether notification is displayed
  *
  * @return bool
  */
 public function isDisplayed()
 {
     // Check configuration to see if this should be evaluated further
     if ($this->avaTaxConfig->isModuleEnabled() == false || $this->avaTaxConfig->getTaxMode($this->storeManager->getDefaultStoreView()) != Config::TAX_MODE_ESTIMATE_AND_SUBMIT || $this->avaTaxConfig->getQueueAdminNotificationEnabled() == false) {
         return false;
     }
     // Query the database to get some stats about the queue
     $this->loadQueueStats();
     // Determine if we need to notify the admin user
     if ($this->authorization->isAllowed('ClassyLlama_AvaTax::manage_avatax') && $this->statQueueCount > 0) {
         return true;
     } else {
         return false;
     }
 }
Пример #28
0
 /**
  * Return Wysiwyg config as \Magento\Framework\Object
  *
  * Config options description:
  *
  * enabled:                 Enabled Visual Editor or not
  * hidden:                  Show Visual Editor on page load or not
  * use_container:           Wrap Editor contents into div or not
  * no_display:              Hide Editor container or not (related to use_container)
  * translator:              Helper to translate phrases in lib
  * files_browser_*:         Files Browser (media, images) settings
  * encode_directives:       Encode template directives with JS or not
  *
  * @param array|\Magento\Framework\Object $data Object constructor params to override default config values
  * @return \Magento\Framework\Object
  */
 public function getConfig($data = array())
 {
     $config = new \Magento\Framework\Object();
     $config->setData(array('enabled' => $this->isEnabled(), 'hidden' => $this->isHidden(), 'use_container' => false, 'add_variables' => true, 'add_widgets' => true, 'no_display' => false, 'encode_directives' => true, 'directives_url' => $this->_backendUrl->getUrl('cms/wysiwyg/directive'), 'popup_css' => $this->_assetRepo->getUrl('mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'), 'content_css' => $this->_assetRepo->getUrl('mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css'), 'width' => '100%', 'plugins' => array()));
     $config->setData('directives_url_quoted', preg_quote($config->getData('directives_url')));
     if ($this->_authorization->isAllowed('Magento_Cms::media_gallery')) {
         $config->addData(array('add_images' => true, 'files_browser_window_url' => $this->_backendUrl->getUrl('cms/wysiwyg_images/index'), 'files_browser_window_width' => $this->_windowSize['width'], 'files_browser_window_height' => $this->_windowSize['height']));
     }
     if (is_array($data)) {
         $config->addData($data);
     }
     if ($config->getData('add_variables')) {
         $settings = $this->_variableConfig->getWysiwygPluginSettings($config);
         $config->addData($settings);
     }
     if ($config->getData('add_widgets')) {
         $settings = $this->_widgetConfig->getPluginSettings($config);
         $config->addData($settings);
     }
     return $config;
 }
 /**
  * Return Wysiwyg config as \Magento\Framework\DataObject
  *
  * Config options description:
  *
  * enabled:                 Enabled Visual Editor or not
  * hidden:                  Show Visual Editor on page load or not
  * use_container:           Wrap Editor contents into div or not
  * no_display:              Hide Editor container or not (related to use_container)
  * translator:              Helper to translate phrases in lib
  * files_browser_*:         Files Browser (media, images) settings
  * encode_directives:       Encode template directives with JS or not
  *
  * @param array|\Magento\Framework\DataObject $data Object constructor params to override default config values
  * @return \Magento\Framework\DataObject
  */
 public function getConfig($data = [])
 {
     $config = new \Magento\Framework\DataObject();
     $config->setData(['enabled' => $this->isEnabled(), 'hidden' => $this->isHidden(), 'use_container' => false, 'add_variables' => true, 'add_widgets' => true, 'no_display' => false, 'encode_directives' => true, 'baseStaticUrl' => $this->_assetRepo->getStaticViewFileContext()->getBaseUrl(), 'baseStaticDefaultUrl' => str_replace('index.php/', '', $this->_backendUrl->getBaseUrl()) . $this->filesystem->getUri(DirectoryList::STATIC_VIEW) . '/', 'directives_url' => $this->_backendUrl->getUrl('cms/wysiwyg/directive'), 'popup_css' => $this->_assetRepo->getUrl('mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'), 'content_css' => $this->_assetRepo->getUrl('mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css'), 'width' => '100%', 'height' => '500px', 'plugins' => []]);
     $config->setData('directives_url_quoted', preg_quote($config->getData('directives_url')));
     if ($this->_authorization->isAllowed('Magento_Cms::media_gallery')) {
         $config->addData(['add_images' => true, 'files_browser_window_url' => $this->_backendUrl->getUrl('cms/wysiwyg_images/index'), 'files_browser_window_width' => $this->_windowSize['width'], 'files_browser_window_height' => $this->_windowSize['height']]);
     }
     if (is_array($data)) {
         $config->addData($data);
     }
     if ($config->getData('add_variables')) {
         $settings = $this->_variableConfig->getWysiwygPluginSettings($config);
         $config->addData($settings);
     }
     if ($config->getData('add_widgets')) {
         $settings = $this->_widgetConfig->getPluginSettings($config);
         $config->addData($settings);
     }
     return $config;
 }
Пример #30
0
 /**
  * @covers \Magento\Customer\Controller\Adminhtml\Index\Index::execute
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteWithNewCustomerAndException()
 {
     $subscription = 'false';
     $postValue = ['customer' => ['coolness' => false, 'disable_auto_group_change' => 'false'], 'subscription' => $subscription];
     $filteredData = ['coolness' => false, 'disable_auto_group_change' => 'false'];
     /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $formMock */
     $attributeMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->disableOriginalConstructor()->getMock();
     $attributeMock->expects($this->once())->method('getAttributeCode')->willReturn('coolness');
     $attributeMock->expects($this->once())->method('getFrontendInput')->willReturn('int');
     $attributes = [$attributeMock];
     $this->requestMock->expects($this->exactly(2))->method('getPostValue')->willReturn($postValue);
     $this->requestMock->expects($this->exactly(2))->method('getPost')->willReturnMap([['customer', null, $postValue['customer']], ['address', null, null]]);
     /** @var \Magento\Customer\Model\Metadata\Form|\PHPUnit_Framework_MockObject_MockObject $formMock */
     $formMock = $this->getMockBuilder('Magento\\Customer\\Model\\Metadata\\Form')->disableOriginalConstructor()->getMock();
     $this->formFactoryMock->expects($this->once())->method('create')->with(\Magento\Customer\Api\CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'adminhtml_customer', [], false, \Magento\Customer\Model\Metadata\Form::DONT_IGNORE_INVISIBLE)->willReturn($formMock);
     $formMock->expects($this->once())->method('extractData')->with($this->requestMock, 'customer')->willReturn($filteredData);
     /** @var \Magento\Framework\DataObject|\PHPUnit_Framework_MockObject_MockObject $objectMock */
     $objectMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
     $this->objectFactoryMock->expects($this->once())->method('create')->with(['data' => $postValue])->willReturn($objectMock);
     $objectMock->expects($this->once())->method('getData')->with('customer')->willReturn($postValue['customer']);
     $formMock->expects($this->once())->method('getAttributes')->willReturn($attributes);
     /** @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customerMock */
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $this->customerDataFactoryMock->expects($this->once())->method('create')->willReturn($customerMock);
     $exception = new \Exception(__('Exception'));
     $this->managementMock->expects($this->once())->method('createAccount')->with($customerMock, null, '')->willThrowException($exception);
     $customerMock->expects($this->never())->method('getId');
     $this->authorizationMock->expects($this->never())->method('isAllowed');
     $this->subscriberFactoryMock->expects($this->never())->method('create');
     $this->sessionMock->expects($this->never())->method('unsCustomerData');
     $this->registryMock->expects($this->never())->method('register');
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->messageManagerMock->expects($this->once())->method('addException')->with($exception, __('Something went wrong while saving the customer.'));
     $this->sessionMock->expects($this->once())->method('setCustomerData')->with($postValue);
     /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
     $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $this->redirectFactoryMock->expects($this->once())->method('create')->with([])->willReturn($redirectMock);
     $redirectMock->expects($this->once())->method('setPath')->with('customer/*/new', ['_current' => true])->willReturn(true);
     $this->assertEquals($redirectMock, $this->model->execute());
 }