public function testSaveActionUpdateIntegration() { $integrationId = $this->_integration->getId(); $integrationName = $this->_integration->getName(); $this->getRequest()->setParam('id', $integrationId); $url = 'http://magento.ll/endpoint_url'; $this->getRequest()->setPostValue(['name' => $integrationName, 'email' => '*****@*****.**', 'authentication' => '1', 'endpoint' => $url, 'current_password' => Bootstrap::ADMIN_PASSWORD]); $this->dispatch('backend/admin/integration/save'); $this->assertSessionMessages($this->equalTo(["The integration '{$integrationName}' has been saved."]), \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS); $this->assertRedirect($this->stringContains('backend/admin/integration/index/')); }
/** * Creates a dummy integration for use in dispatched methods under testing */ private function _createDummyIntegration() { /** @var $factory \Magento\Integration\Model\IntegrationFactory */ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $factory = $objectManager->create('Magento\\Integration\\Model\\IntegrationFactory'); $this->_integration = $factory->create()->setName(md5(rand()))->save(); /** Grant permissions to integrations */ /** @var \Magento\Integration\Service\V1\AuthorizationService $authorizationService */ $authorizationService = $objectManager->create('Magento\\Integration\\Service\\V1\\AuthorizationService'); $authorizationService->grantAllPermissions($this->_integration->getId()); }
/** * Creates a dummy integration for use in dispatched methods under testing */ private function _createDummyIntegration() { /** @var $factory \Magento\Integration\Model\Integration\Factory */ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $factory = $objectManager->create('Magento\\Integration\\Model\\Integration\\Factory'); $this->_integration = $factory->create()->setName(md5(rand()))->save(); /** Grant permissions to integrations */ /** @var \Magento\Authz\Model\UserIdentifier\Factory $userIdentifierFactory */ $userIdentifierFactory = $objectManager->create('Magento\\Authz\\Model\\UserIdentifier\\Factory'); /** @var \Magento\Authz\Service\AuthorizationV1 $authzService */ $userIdentifier = $userIdentifierFactory->create(\Magento\Authz\Model\UserIdentifier::USER_TYPE_INTEGRATION, $this->_integration->getId()); $authzService = $objectManager->create('Magento\\Authz\\Service\\AuthorizationV1'); $authzService->grantAllPermissions($userIdentifier); }
/** * Persist API permissions. * * Permissions are expected to be set to integration object by 'resource' key. * If 'all_resources' is set and is evaluated to true, permissions to all resources will be granted. * * @param IntegrationModel $integration * @return void */ protected function _saveApiPermissions(IntegrationModel $integration) { if ($integration->getId()) { if ($integration->getData('all_resources')) { $this->integrationAuthorizationService->grantAllPermissions($integration->getId()); } elseif (is_array($integration->getData('resource'))) { $this->integrationAuthorizationService->grantPermissions($integration->getId(), $integration->getData('resource')); } else { $this->integrationAuthorizationService->grantPermissions($integration->getId(), []); } } }
/** * Persist API permissions. * * Permissions are expected to be set to integration object by 'resource' key. * If 'all_resources' is set and is evaluated to true, permissions to all resources will be granted. * * @param IntegrationModel $integration * @return void */ protected function _saveApiPermissions(IntegrationModel $integration) { if ($integration->getId()) { $userIdentifier = $this->_createUserIdentifier($integration->getId()); if ($integration->getData('all_resources')) { $this->_authzService->grantAllPermissions($userIdentifier); } else { if (is_array($integration->getData('resource'))) { $this->_authzService->grantPermissions($userIdentifier, $integration->getData('resource')); } else { $this->_authzService->grantPermissions($userIdentifier, array()); } } } }
public function testLoadActiveIntegrationByConsumerId() { $integration = $this->integration->getResource()->selectActiveIntegrationByConsumerId($this->consumer->getId()); $this->assertEquals($this->integration->getId(), $integration['integration_id']); }
/** * Add oAuth token and token secret. * * @param IntegrationModel $integration * @return void */ protected function _addOauthTokenData(IntegrationModel $integration) { if ($integration->getId()) { $accessToken = $this->_oauthService->getAccessToken($integration->getConsumerId()); if ($accessToken) { $integration->setData('token', $accessToken->getToken()); $integration->setData('token_secret', $accessToken->getSecret()); } } }