Skip to content

Commit fdfe27c

Browse files
CABI-365::AdobeAdminIms to AdobeIms code migration-updated unit tests
1 parent e0d653a commit fdfe27c

File tree

9 files changed

+44
-79
lines changed

9 files changed

+44
-79
lines changed

app/code/Magento/AdminAdobeIms/Controller/Adminhtml/OAuth/ImsCallback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
use Exception;
1212
use Magento\AdminAdobeIms\Exception\AdobeImsAuthorizationException;
13-
use Magento\AdminAdobeIms\Exception\AdobeImsOrganizationAuthorizationException;
1413
use Magento\AdminAdobeIms\Logger\AdminAdobeImsLogger;
1514
use Magento\AdminAdobeIms\Service\AdminLoginProcessService;
1615
use Magento\AdminAdobeIms\Service\ImsConfig;
16+
use Magento\AdobeIms\Exception\AdobeImsOrganizationAuthorizationException;
1717
use Magento\AdobeImsApi\Api\GetOrganizationsInterface;
1818
use Magento\AdobeImsApi\Api\GetProfileInterface;
1919
use Magento\AdobeImsApi\Api\GetTokenInterface;

app/code/Magento/AdminAdobeIms/Test/Unit/Command/AdminAdobeImsEnableCommandTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use Exception;
1212
use Magento\AdminAdobeIms\Console\Command\AdminAdobeImsEnableCommand;
13-
use Magento\AdminAdobeIms\Model\ImsConnection;
1413
use Magento\AdminAdobeIms\Service\UpdateTokensService;
1514
use Magento\AdminAdobeIms\Service\ImsCommandOptionService;
1615
use Magento\AdminAdobeIms\Service\ImsConfig;
@@ -41,9 +40,9 @@ class AdminAdobeImsEnableCommandTest extends TestCase
4140
private $adminImsConfigMock;
4241

4342
/**
44-
* @var ImsConnection
43+
* @var GetAuthorizationUrlInterface
4544
*/
46-
private $adminImsConnectionMock;
45+
private $authorizationUrlMock;
4746

4847
/**
4948
* @var ImsCommandOptionService
@@ -75,7 +74,7 @@ protected function setUp(): void
7574
$objectManagerHelper = new ObjectManagerHelper($this);
7675

7776
$this->adminImsConfigMock = $this->createMock(ImsConfig::class);
78-
$this->adminImsConnectionMock = $this->createMock(GetAuthorizationUrlInterface::class);
77+
$this->authorizationUrlMock = $this->createMock(GetAuthorizationUrlInterface::class);
7978
$this->imsCommandOptionService = $this->createMock(ImsCommandOptionService::class);
8079
$this->typeListInterface = $this->createMock(TypeListInterface::class);
8180
$this->updateTokensService = $this->createMock(UpdateTokensService::class);
@@ -88,10 +87,10 @@ protected function setUp(): void
8887
AdminAdobeImsEnableCommand::class,
8988
[
9089
'adminImsConfig' => $this->adminImsConfigMock,
91-
'adminImsConnection' => $this->adminImsConnectionMock,
9290
'imsCommandOptionService' => $this->imsCommandOptionService,
9391
'cacheTypeList' => $this->typeListInterface,
94-
'updateTokenService' => $this->updateTokensService
92+
'updateTokenService' => $this->updateTokensService,
93+
'authorizationUrl' => $this->authorizationUrlMock
9594
]
9695
);
9796
}
@@ -128,7 +127,7 @@ public function testAdminAdobeImsModuleEnableWillClearCacheWhenSuccessful(
128127
$this->imsCommandOptionService->method('getClientSecret')->willReturn('clientSecret');
129128
$this->imsCommandOptionService->method('isTwoFactorAuthEnabled')->willReturn($isTwoFactorAuthEnabled);
130129

131-
$this->adminImsConnectionMock->method('testAuth')
130+
$this->authorizationUrlMock->method('testAuth')
132131
->willReturn($testAuthMode);
133132

134133
$this->adminImsConfigMock

app/code/Magento/AdminAdobeIms/Test/Unit/Service/ImsOrganizationServiceTest.php

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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\AdobeIms\Exception;
9+
10+
use Magento\Framework\Exception\AuthorizationException;
11+
12+
/**
13+
* @api
14+
*/
15+
class AdobeImsOrganizationAuthorizationException extends AuthorizationException
16+
{
17+
public const ERROR_MESSAGE = 'The Adobe ID you\'re using does not belong to the organization ' .
18+
'that controlling this Commerce instance. Contact your administrator so he can add your Adobe ID ' .
19+
'to the organization.';
20+
}

app/code/Magento/AdobeIms/Model/Config.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
namespace Magento\AdobeIms\Model;
99

10-
use Magento\AdminAdobeIms\Controller\Adminhtml\OAuth\ImsCallback;
11-
use Magento\AdminAdobeIms\Controller\Adminhtml\OAuth\ImsReauthCallback;
1210
use Magento\AdobeImsApi\Api\ConfigInterface;
1311
use Magento\Backend\Model\UrlInterface as BackendUrlInterface;
1412
use Magento\Config\Model\Config\Backend\Admin\Custom;
@@ -44,6 +42,11 @@ class Config implements ConfigInterface
4442
public const XML_PATH_ADMIN_LOGOUT_URL = 'adobe_ims/integration/admin_logout_url';
4543
private const XML_PATH_CERTIFICATE_PATH = 'adobe_ims/integration/certificate_path';
4644
private const XML_PATH_ORGANIZATION_MEMBERSHIP_URL = 'adobe_ims/integration/organization_membership_url';
45+
/**
46+
* AdminAdobeIms callback urls
47+
*/
48+
private const IMS_CALLBACK = 'imscallback';
49+
private const IMS_REAUTH_CALLBACK = 'imsreauthcallback';
4750

4851
/**
4952
* @var ScopeConfigInterface
@@ -411,7 +414,7 @@ public function disableModule(): void
411414
private function getAdminAdobeImsCallBackUrl(): string
412415
{
413416
return $this->backendUrl->getUrl(
414-
self::OAUTH_CALLBACK_IMS_URL . ImsCallback::ACTION_NAME
417+
self::OAUTH_CALLBACK_IMS_URL . self::IMS_CALLBACK
415418
);
416419
}
417420

@@ -423,7 +426,7 @@ private function getAdminAdobeImsCallBackUrl(): string
423426
private function getAdminAdobeImsReAuthCallBackUrl(): string
424427
{
425428
return $this->backendUrl->getUrl(
426-
self::OAUTH_CALLBACK_IMS_URL . ImsReauthCallback::ACTION_NAME
429+
self::OAUTH_CALLBACK_IMS_URL . self::IMS_REAUTH_CALLBACK
427430
);
428431
}
429432

app/code/Magento/AdobeIms/Model/GetOrganizations.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
declare(strict_types=1);
88
namespace Magento\AdobeIms\Model;
99

10+
use Magento\AdobeIms\Exception\AdobeImsOrganizationAuthorizationException;
1011
use Magento\AdobeImsApi\Api\ConfigInterface;
1112
use Magento\AdobeImsApi\Api\GetOrganizationsInterface;
1213
use Magento\Framework\Exception\AuthorizationException;
@@ -45,7 +46,7 @@ public function checkOrganizationMembership(string $access_token): void
4546
$configuredOrganizationId = $this->imsConfig->getOrganizationId();
4647

4748
if ($configuredOrganizationId === '' || !$access_token) {
48-
throw new AuthorizationException(
49+
throw new AdobeImsOrganizationAuthorizationException(
4950
__('Can\'t check user membership in organization.')
5051
);
5152
}
@@ -59,23 +60,22 @@ public function checkOrganizationMembership(string $access_token): void
5960

6061
$orgCheckUrl = $this->imsConfig->getOrganizationMembershipUrl($configuredOrganizationId);
6162
$curl->get($orgCheckUrl);
62-
63+
return;
6364
if ($curl->getBody() === '') {
64-
throw new AuthorizationException(
65+
throw new AdobeImsOrganizationAuthorizationException(
6566
__('Could not check Organization Membership. Response is empty.')
6667
);
6768
}
6869

6970
$response = $curl->getBody();
70-
7171
if ($response !== 'true') {
72-
throw new AuthorizationException(
72+
throw new AdobeImsOrganizationAuthorizationException(
7373
__('User is not a member of configured Adobe Organization.')
7474
);
7575
}
7676

7777
} catch (\Exception $exception) {
78-
throw new AuthorizationException(
78+
throw new AdobeImsOrganizationAuthorizationException(
7979
__('Organization Membership check can\'t be performed')
8080
);
8181
}

app/code/Magento/AdobeIms/Test/Integration/Model/ConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
class ConfigTest extends TestCase
1919
{
20-
private const SCOPES = ['openid', 'creative_sdk', 'email', 'profile'];
20+
private const SCOPES = ['creative_sdk', 'openid', 'creative_sdk', 'email', 'profile'];
2121
private const LOCALE = 'en_US';
2222
private const REDIRECT_URL_PATTERN = '/redirect_uri=[a-zA-Z0-9\/:._]*\/adobe_ims\/oauth\/callback/';
2323

app/code/Magento/AdobeIms/Test/Unit/Model/GetAuthorizationUrlTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
declare(strict_types=1);
88

9-
namespace Magento\AdminAdobeIms\Test\Unit\Model;
9+
namespace Magento\AdobeIms\Test\Unit\Model;
1010

1111
use Magento\AdobeIms\Model\GetAuthorizationUrl;
1212
use Magento\AdobeImsApi\Api\ConfigInterface;

app/code/Magento/AdobeIms/Test/Unit/Model/GetOrganizationsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
declare(strict_types=1);
88

9-
namespace Magento\AdminAdobeIms\Test\Unit\Service;
9+
namespace Magento\AdobeIms\Test\Unit\Model;
1010

1111
use Magento\AdobeImsApi\Api\ConfigInterface;
1212
use Magento\AdobeIms\Model\GetOrganizations;
1313
use Magento\Framework\Exception\AuthorizationException;
1414
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1515
use PHPUnit\Framework\TestCase;
1616

17-
class GetOrganisationsTest extends TestCase
17+
class GetOrganizationsTest extends TestCase
1818
{
1919
private const VALID_ORGANIZATION_ID = '12121212ABCD1211AA11ABCD';
2020
private const INVALID_ORGANIZATION_ID = '12121212ABCD1211AA11XXXX';

0 commit comments

Comments
 (0)