当前位置: 首页>>代码示例>>PHP>>正文


PHP AuthorizationInterface::expects方法代码示例

本文整理汇总了PHP中Magento\Framework\AuthorizationInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthorizationInterface::expects方法的具体用法?PHP AuthorizationInterface::expects怎么用?PHP AuthorizationInterface::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\AuthorizationInterface的用法示例。


在下文中一共展示了AuthorizationInterface::expects方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testExecute

 /**
  * @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);
 }
开发者ID:zhangjiachao,项目名称:magento2,代码行数:16,代码来源:RestrictAdminBillingAgreementUsageTest.php

示例2: testFilterAclElements

 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);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:12,代码来源:AclTest.php

示例3: testGetMethodAllStoresInvalid

 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());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:10,代码来源:RestTest.php

示例4: testBuildOutputDataArrayWithPermission

 /**
  * @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);
 }
开发者ID:opexsw,项目名称:magento2,代码行数:25,代码来源:ExtensionAttributesProcessorTest.php

示例5: testOverrideParams

 /**
  * @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);
 }
开发者ID:buskamuza,项目名称:magento2-skeleton,代码行数:21,代码来源:RestTest.php

示例6: testAuthorizationFailed

 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());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:RestTest.php

示例7: testGetConfig

 /**
  * @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'));
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:23,代码来源:ConfigTest.php

示例8: testExecuteWithNewCustomerAndException

 /**
  * @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());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:44,代码来源:SaveTest.php

示例9: testGetConfig

 /**
  * @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->backendUrlMock->expects($this->once())->method('getBaseUrl')->willReturn('localhost/index.php/');
     $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->filesystemMock->expects($this->once())->method('getUri')->willReturn('pub/static');
     /** @var \Magento\Framework\View\Asset\ContextInterface|\PHPUnit_Framework_MockObject_MockObject $contextMock */
     $contextMock = $this->getMock(\Magento\Framework\View\Asset\ContextInterface::class);
     $contextMock->expects($this->once())->method('getBaseUrl')->willReturn('localhost/pub/static/');
     $this->assetRepoMock->expects($this->once())->method('getStaticViewFileContext')->willReturn($contextMock);
     $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\\DataObject', $config);
     $this->assertEquals($expectedResults[0], $config->getData('someData'));
     $this->assertEquals($expectedResults[1], $config->getData('wysiwygPluginSettings'));
     $this->assertEquals($expectedResults[2], $config->getData('pluginSettings'));
     $this->assertEquals('localhost/pub/static/', $config->getData('baseStaticUrl'));
     $this->assertEquals('localhost/pub/static/', $config->getData('baseStaticDefaultUrl'));
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:31,代码来源:ConfigTest.php

示例10: testGetAfterElementHtml

 public function testGetAfterElementHtml()
 {
     $model = $this->objectManager->getObject('Magento\\Catalog\\Block\\Adminhtml\\Product\\Helper\\Form\\Category', ['authorization' => $this->authorization]);
     $this->authorization->expects($this->any())->method('isAllowed')->will($this->returnValue(false));
     $this->assertEmpty($model->getAfterElementHtml());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:6,代码来源:CategoryTest.php

示例11: testGetUrl

 /**
  * @param bool $isAllowed
  * @param null|bool $url
  * @dataProvider permissionProvider
  */
 public function testGetUrl($isAllowed, $url)
 {
     $this->authorizationMock->expects($this->once())->method('isAllowed')->with('Magento_Sales::sales_invoice', null)->willReturn($isAllowed);
     $this->assertEquals($url, $this->urlGenerator->getUrl(new \Magento\Framework\DataObject()));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:10,代码来源:UrlGeneratorTest.php

示例12: testModifyMeta

 public function testModifyMeta()
 {
     $this->registryMock->expects($this->once())->method('registry')->with('use_wrapper')->willReturn(true);
     $this->authorizationMock->expects($this->once())->method('isAllowed')->with('Magento_Catalog::attributes_attributes')->willReturn(true);
     $this->assertArrayHasKey('add_attribute_modal', $this->getModel()->modifyMeta([]));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:6,代码来源:AttributesTest.php


注:本文中的Magento\Framework\AuthorizationInterface::expects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。