Skip to content

Commit bf91302

Browse files
ENGCOM-8753: fixed creating admin Integrations #32095
2 parents 627e00b + 67f9650 commit bf91302

File tree

4 files changed

+99
-5
lines changed

4 files changed

+99
-5
lines changed

app/code/Magento/Integration/Controller/Adminhtml/Integration/TokensExchange.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@
88

99
namespace Magento\Integration\Controller\Adminhtml\Integration;
1010

11-
use Magento\Framework\App\Action\HttpPostActionInterface;
11+
use Magento\Framework\App\Action\HttpGetActionInterface;
12+
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Framework\Oauth\Exception;
1214
use Magento\Integration\Controller\Adminhtml\Integration;
1315
use Magento\Integration\Model\Integration as IntegrationModel;
1416

15-
class TokensExchange extends Integration implements HttpPostActionInterface
17+
/**
18+
* Tokens Exchange for integration
19+
*/
20+
class TokensExchange extends Integration implements HttpGetActionInterface
1621
{
1722
/**
1823
* Let the admin know that integration has been sent for activation and token exchange is in process.
1924
*
20-
* @param bool $isReauthorize
25+
* @param bool $isReauthorize
2126
* @param string $integrationName
2227
* @return void
2328
*/
@@ -60,7 +65,7 @@ public function execute()
6065
$popupContent = $this->_response->getBody();
6166
$consumer = $this->_oauthService->loadConsumer($integration->getConsumerId());
6267
if (!$consumer->getId()) {
63-
throw new \Magento\Framework\Oauth\Exception(
68+
throw new Exception(
6469
__(
6570
'A consumer with "%1" ID doesn\'t exist. Verify the ID and try again.',
6671
$integration->getConsumerId()
@@ -74,7 +79,7 @@ public function execute()
7479
'popup_content' => $popupContent,
7580
];
7681
$this->getResponse()->representJson($this->jsonHelper->jsonEncode($result));
77-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
82+
} catch (LocalizedException $e) {
7883
$this->messageManager->addErrorMessage($e->getMessage());
7984
$this->_redirect('*/*');
8085
return;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Integration\Controller\Adminhtml\Integration;
9+
10+
use Magento\Framework\App\Request\Http as HttpRequest;
11+
use Magento\Integration\Api\IntegrationServiceInterface;
12+
use Magento\TestFramework\TestCase\AbstractBackendController;
13+
14+
/**
15+
* Test for \Magento\Integration\Controller\Adminhtml\Integration\TokensExchange.
16+
*
17+
* @magentoAppArea adminhtml
18+
*/
19+
class TokensExchangeTest extends AbstractBackendController
20+
{
21+
private const URL = 'backend/admin/integration/tokensExchange';
22+
23+
/**
24+
* @var IntegrationServiceInterface
25+
*/
26+
private $integrationService;
27+
28+
/**
29+
* @inheritDoc
30+
*/
31+
protected function setUp(): void
32+
{
33+
parent::setUp();
34+
35+
$this->integrationService = $this->_objectManager->get(IntegrationServiceInterface::class);
36+
}
37+
38+
/**
39+
* Activate integration
40+
*
41+
* @magentoDataFixture Magento/Integration/_files/integration_all_data.php
42+
*
43+
* @return void
44+
*/
45+
public function testActivate()
46+
{
47+
$integration = $this->integrationService->findByName('Fixture Integration');
48+
49+
$this->getRequest()->setMethod(HttpRequest::METHOD_GET);
50+
$this->getRequest()->setParams(['id' => $integration->getId()]);
51+
$this->dispatch(self::URL);
52+
53+
$this->assertStringContainsString(
54+
'Please setup or sign in into your 3rd party account to complete setup of this integration.',
55+
$this->getResponse()->getBody()
56+
);
57+
}
58+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Integration\Api\IntegrationServiceInterface;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
$objectManager = Bootstrap::getObjectManager();
12+
$integrationService = $objectManager->get(IntegrationServiceInterface::class);
13+
14+
$data = [
15+
'name' => 'Fixture Integration',
16+
'email' => '[email protected]',
17+
'endpoint' => 'https://example.com/endpoint',
18+
'identity_link_url' => 'https://example.com/link',
19+
'all_resources' => 0,
20+
];
21+
$integrationService->create($data);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
9+
10+
Resolver::getInstance()->requireDataFixture('Magento/Integration/_files/integration_all_permissions_rollback.php');

0 commit comments

Comments
 (0)