/**
  * @dataProvider getValidTokenData
  */
 public function testValidToken($userType, $userId, $expectedUserType, $expectedUserId)
 {
     $bearerToken = 'bearer1234';
     $this->request->expects($this->once())->method('getHeader')->with('Authorization')->will($this->returnValue("Bearer {$bearerToken}"));
     $token = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token')->disableOriginalConstructor()->setMethods(['loadByToken', 'getId', 'getUserType', 'getCustomerId', 'getAdminId', '__wakeup'])->getMock();
     $this->tokenFactory->expects($this->once())->method('create')->will($this->returnValue($token));
     $token->expects($this->once())->method('loadByToken')->with($bearerToken)->will($this->returnSelf());
     $token->expects($this->once())->method('getId')->will($this->returnValue(1));
     $token->expects($this->once())->method('getUserType')->will($this->returnValue($userType));
     $integration = $this->getMockBuilder('Magento\\Integration\\Model\\Integration')->disableOriginalConstructor()->setMethods(['getId', '__wakeup'])->getMock();
     switch ($userType) {
         case UserContextInterface::USER_TYPE_INTEGRATION:
             $integration->expects($this->once())->method('getId')->will($this->returnValue($userId));
             $this->integrationService->expects($this->once())->method('findByConsumerId')->will($this->returnValue($integration));
             break;
         case UserContextInterface::USER_TYPE_ADMIN:
             $token->expects($this->once())->method('getAdminId')->will($this->returnValue($userId));
             break;
         case UserContextInterface::USER_TYPE_CUSTOMER:
             $token->expects($this->once())->method('getCustomerId')->will($this->returnValue($userId));
             break;
     }
     $this->assertEquals($expectedUserType, $this->tokenUserContext->getUserType());
     $this->assertEquals($expectedUserId, $this->tokenUserContext->getUserId());
     /* check again to make sure that the above methods were only called once */
     $this->assertEquals($expectedUserType, $this->tokenUserContext->getUserType());
     $this->assertEquals($expectedUserId, $this->tokenUserContext->getUserId());
 }
Exemple #2
0
 /**
  * Test generate uri with wsdl param as true
  */
 public function testGenerateUriWithNoWsdlParam()
 {
     $param = "testModule1AllSoapAndRest:V1,testModule2AllSoapNoRest:V1";
     $serviceKey = \Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_SERVICES;
     $this->_requestMock->expects($this->any())->method('getParam')->will($this->returnValue($param));
     $expectedResult = "http://magento.com/soap/storeCode?{$serviceKey}={$param}";
     $actualResult = $this->_soapServer->generateUri(false);
     $this->assertEquals($expectedResult, urldecode($actualResult), 'URI (without WSDL param) generated is invalid.');
 }
 public function testCall()
 {
     $requestedServices = ['requestedServices'];
     $this->_requestMock->expects($this->once())->method('getRequestedServices')->will($this->returnValue($requestedServices));
     $this->_dataObjectConverter->expects($this->once())->method('convertStdObjectToArray')->will($this->returnValue(['field' => 1]));
     $operationName = 'soapOperation';
     $className = 'Magento\\Framework\\DataObject';
     $methodName = 'testMethod';
     $isSecure = false;
     $aclResources = [['Magento_TestModule::resourceA']];
     $this->_apiConfigMock->expects($this->once())->method('getServiceMethodInfo')->with($operationName, $requestedServices)->will($this->returnValue([ServiceMetadata::KEY_CLASS => $className, ServiceMetadata::KEY_METHOD => $methodName, ServiceMetadata::KEY_IS_SECURE => $isSecure, ServiceMetadata::KEY_ACL_RESOURCES => $aclResources]));
     $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
     $serviceMock = $this->getMockBuilder($className)->disableOriginalConstructor()->setMethods([$methodName])->getMock();
     $serviceResponse = ['foo' => 'bar'];
     $serviceMock->expects($this->once())->method($methodName)->will($this->returnValue($serviceResponse));
     $this->_objectManagerMock->expects($this->once())->method('get')->with($className)->will($this->returnValue($serviceMock));
     $this->_serviceInputProcessorMock->expects($this->once())->method('process')->will($this->returnArgument(2));
     /** Execute SUT. */
     $this->assertEquals(['result' => $serviceResponse], $this->_handler->__call($operationName, [(object) ['field' => 1]]));
 }
 /**
  * Mock getParam() of request object to return given value.
  *
  * @param $param
  * @param $value
  */
 protected function _mockGetParam($param, $value)
 {
     $this->_requestMock->expects($this->any())->method('getParam')->with($param)->will($this->returnValue($value));
 }