Skip to content

Commit e0d653a

Browse files
CABI-365::AdobeAdminIms to AdobeIms code migration-updated unit test and config fetch details
1 parent 23ba532 commit e0d653a

File tree

2 files changed

+99
-18
lines changed

2 files changed

+99
-18
lines changed

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public function getPrivateKey(): string
118118
public function getTokenUrl(): string
119119
{
120120
return str_replace(
121-
['#{tokenUrl}'],
122-
[$this->getImsUrl('imsUrl')],
121+
['#{imsUrl}'],
122+
[$this->getImsUrl()],
123123
$this->scopeConfig->getValue(self::XML_PATH_TOKEN_URL)
124124
);
125125
}
@@ -130,9 +130,9 @@ public function getTokenUrl(): string
130130
public function getAuthUrl(): string
131131
{
132132
return str_replace(
133-
['#{authUrl}','#{client_id}', '#{redirect_uri}', '#{scope}', '#{locale}'],
133+
['#{imsUrl}','#{client_id}', '#{redirect_uri}', '#{scope}', '#{locale}'],
134134
[
135-
$this->getImsUrl('imsUrl'),
135+
$this->getImsUrl(),
136136
$this->getApiKey(),
137137
$this->getCallBackUrl(),
138138
$this->getScopes(),
@@ -170,8 +170,8 @@ public function getLogoutUrl(string $accessToken, string $redirectUrl = '') : st
170170
$redirectUrl = 'self';
171171
}
172172
return str_replace(
173-
['#{logoutUrl}', '#{access_token}', '#{redirect_uri}'],
174-
[$this->getImsUrl('imsUrl'), $accessToken, $redirectUrl],
173+
['#{imsUrl}', '#{access_token}', '#{redirect_uri}'],
174+
[$this->getImsUrl(), $accessToken, $redirectUrl],
175175
$this->scopeConfig->getValue(self::XML_PATH_LOGOUT_URL) ?? ''
176176
);
177177
}
@@ -196,8 +196,8 @@ public function getProfileImageUrl(): string
196196
public function getProfileUrl(): string
197197
{
198198
return str_replace(
199-
['#{client_id}'],
200-
[$this->getApiKey()],
199+
['#{imsUrl}', '#{client_id}'],
200+
[$this->getImsUrl(), $this->getApiKey()],
201201
$this->scopeConfig->getValue(self::XML_PATH_PROFILE_URL)
202202
);
203203
}
@@ -212,8 +212,8 @@ public function getProfileUrl(): string
212212
public function getValidateTokenUrl(string $code, string $tokenType): string
213213
{
214214
return str_replace(
215-
['#{token}', '#{client_id}', '#{token_type}'],
216-
[$code, $this->getApiKey(), $tokenType],
215+
['#{imsUrl}', '#{token}', '#{client_id}', '#{token_type}'],
216+
[$this->getImsUrl(), $code, $this->getApiKey(), $tokenType],
217217
$this->scopeConfig->getValue(self::XML_PATH_VALIDATE_TOKEN_URL)
218218
);
219219
}
@@ -231,8 +231,9 @@ public function getAdminAdobeImsAuthUrl(?string $clientId): string
231231
}
232232

233233
return str_replace(
234-
['#{client_id}', '#{redirect_uri}', '#{scope}', '#{locale}'],
234+
['#{imsUrl}', '#{client_id}', '#{redirect_uri}', '#{scope}', '#{locale}'],
235235
[
236+
$this->getImsUrl(),
236237
$clientId,
237238
$this->getAdminAdobeImsCallBackUrl(),
238239
$this->getAdminScopes(),
@@ -250,8 +251,9 @@ public function getAdminAdobeImsAuthUrl(?string $clientId): string
250251
public function getAdminAdobeImsReAuthUrl(): string
251252
{
252253
return str_replace(
253-
['#{client_id}', '#{redirect_uri}', '#{scope}', '#{locale}'],
254+
['#{imsUrl}', '#{client_id}', '#{redirect_uri}', '#{scope}', '#{locale}'],
254255
[
256+
$this->getImsUrl(),
255257
$this->getApiKey(),
256258
$this->getAdminAdobeImsReAuthCallBackUrl(),
257259
$this->getAdminScopes(),
@@ -270,8 +272,8 @@ public function getAdminAdobeImsReAuthUrl(): string
270272
public function getBackendLogoutUrl(string $accessToken) : string
271273
{
272274
return str_replace(
273-
['#{logoutUrl}', '#{access_token}', '#{client_secret}', '#{client_id}'],
274-
[$this->getImsUrl('imsUrl'), $accessToken, $this->getPrivateKey(), $this->getApiKey()],
275+
['#{imsUrl}', '#{access_token}', '#{client_secret}', '#{client_id}'],
276+
[$this->getImsUrl(), $accessToken, $this->getPrivateKey(), $this->getApiKey()],
275277
$this->scopeConfig->getValue(self::XML_PATH_ADMIN_LOGOUT_URL)
276278
);
277279
}
@@ -284,7 +286,11 @@ public function getBackendLogoutUrl(string $accessToken) : string
284286
*/
285287
public function getCertificateUrl(string $fileName): string
286288
{
287-
return $this->scopeConfig->getValue(self::XML_PATH_CERTIFICATE_PATH) . $fileName;
289+
return str_replace(
290+
['#{certificateUrl}'],
291+
[$this->getImsUrl('certificateUrl')],
292+
$this->scopeConfig->getValue(self::XML_PATH_CERTIFICATE_PATH) . $fileName
293+
);
288294
}
289295

290296
/**
@@ -296,8 +302,8 @@ public function getCertificateUrl(string $fileName): string
296302
public function getOrganizationMembershipUrl(string $orgId): string
297303
{
298304
return str_replace(
299-
['#{org_id}'],
300-
[$orgId],
305+
['#{organizationMembershipUrl}', '#{org_id}'],
306+
[$this->getImsUrl('organizationMembershipUrl'), $orgId],
301307
$this->scopeConfig->getValue(self::XML_PATH_ORGANIZATION_MEMBERSHIP_URL)
302308
);
303309
}
@@ -332,7 +338,7 @@ private function getAdminScopes(): string
332338
* @param string $urlType
333339
* @return string
334340
*/
335-
private function getImsUrl(string $urlType): string
341+
private function getImsUrl(string $urlType = 'imsUrl'): string
336342
{
337343
return $this->scopeConfig->getValue(self::XML_CONFIG_PATH . $urlType);
338344
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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\Test\Unit\Model;
9+
10+
use Magento\AdobeIms\Model\GetProfile;
11+
use Magento\AdobeImsApi\Api\ConfigInterface;
12+
use Magento\Framework\HTTP\Client\Curl;
13+
use Magento\Framework\HTTP\Client\CurlFactory;
14+
use Magento\Framework\Serialize\Serializer\Json;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class GetProfileTest extends TestCase
18+
{
19+
/**
20+
* @var ConfigInterface|mixed|\PHPUnit\Framework\MockObject\MockObject
21+
*/
22+
private $configMock;
23+
/**
24+
* @var CurlFactory|mixed|\PHPUnit\Framework\MockObject\MockObject
25+
*/
26+
private $curlFactoryMock;
27+
/**
28+
* @var Json|mixed|\PHPUnit\Framework\MockObject\MockObject
29+
*/
30+
private $jsonMock;
31+
/**
32+
* @var GetProfile
33+
*/
34+
private GetProfile $profile;
35+
36+
/**
37+
* Prepare test objects.
38+
*/
39+
protected function setUp(): void
40+
{
41+
$this->configMock = $this->createMock(ConfigInterface::class);
42+
$this->curlFactoryMock = $this->createMock(CurlFactory::class);
43+
$this->jsonMock = $this->createMock(Json::class);
44+
$this->profile = new GetProfile(
45+
$this->configMock,
46+
$this->curlFactoryMock,
47+
$this->jsonMock
48+
);
49+
}
50+
51+
/**
52+
* Test validate token
53+
*/
54+
public function testGetProfile()
55+
{
56+
$curl = $this->createMock(Curl::class);
57+
$this->curlFactoryMock->expects($this->once())
58+
->method('create')
59+
->willReturn($curl);
60+
$curl->expects($this->exactly(3))
61+
->method('addHeader')
62+
->willReturn(null);
63+
$this->configMock->expects($this->once())
64+
->method('getProfileUrl')
65+
->willReturn('http://www.some.url.com');
66+
$curl->expects($this->exactly(2))
67+
->method('getBody')
68+
->willReturn(null);
69+
$data = ['email' => '[email protected]', 'name' => 'Name'];
70+
$this->jsonMock->expects($this->once())
71+
->method('unserialize')
72+
->willReturn($data);
73+
$this->assertEquals($data, $this->profile->getProfile('ftXdatRdsafga'));
74+
}
75+
}

0 commit comments

Comments
 (0)