Skip to content

Commit 4388f34

Browse files
CABI-365::AdobeAdminIms to AdobeIms code migration-updated unit tests
1 parent 668cff7 commit 4388f34

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function execute(?string $accessToken = null) : bool
107107
$accessToken = $session->getAdobeAccessToken();
108108
}
109109
if (!empty($accessToken)) {
110-
return $this->adminLogoutFromIms($accessToken);
110+
return $this->logoutAdminFromIms($accessToken);
111111
}
112112
$accessToken = $accessToken ?? $this->getAccessToken->execute();
113113
if (empty($accessToken)) {
@@ -149,7 +149,7 @@ private function externalLogOut(string $accessToken): void
149149
* @return bool
150150
* @throws LocalizedException
151151
*/
152-
private function adminLogoutFromIms(string $accessToken): bool
152+
private function logoutAdminFromIms(string $accessToken): bool
153153
{
154154
if (!$this->checkUserProfile($accessToken)) {
155155
throw new LocalizedException(

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

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
namespace Magento\AdobeIms\Test\Unit\Model;
1010

1111
use Exception;
12+
use Magento\AdobeIms\Model\GetProfile;
1213
use Magento\AdobeIms\Model\LogOut;
14+
use Magento\Backend\Model\Auth\StorageInterface;
1315
use Magento\AdobeImsApi\Api\ConfigInterface;
14-
use Magento\AdobeImsApi\Api\Data\UserProfileInterface;
1516
use Magento\AdobeImsApi\Api\FlushUserTokensInterface;
1617
use Magento\AdobeImsApi\Api\GetAccessTokenInterface;
17-
use Magento\AdobeImsApi\Api\UserProfileRepositoryInterface;
18-
use Magento\Authorization\Model\UserContextInterface;
18+
use Magento\Backend\Model\Auth;
1919
use Magento\Framework\HTTP\Client\Curl;
2020
use Magento\Framework\HTTP\Client\CurlFactory;
2121
use PHPUnit\Framework\MockObject\MockObject;
@@ -60,6 +60,16 @@ class LogOutTest extends TestCase
6060
*/
6161
private $model;
6262

63+
/**
64+
* @var Auth|MockObject
65+
*/
66+
private $auth;
67+
68+
/**
69+
* @var GetProfile|MockObject
70+
*/
71+
private $profile;
72+
6373
/**
6474
* @inheritdoc
6575
*/
@@ -70,12 +80,16 @@ protected function setUp(): void
7080
$this->loggerInterfaceMock = $this->createMock(LoggerInterface::class);
7181
$this->getToken = $this->createMock(GetAccessTokenInterface::class);
7282
$this->flushTokens = $this->createMock(FlushUserTokensInterface::class);
83+
$this->profile = $this->createMock(GetProfile::class);
84+
$this->auth = $this->createMock(Auth::class);
7385
$this->model = new LogOut(
7486
$this->loggerInterfaceMock,
7587
$this->configInterfaceMock,
7688
$this->curlFactoryMock,
7789
$this->getToken,
78-
$this->flushTokens
90+
$this->flushTokens,
91+
$this->profile,
92+
$this->auth
7993
);
8094
}
8195

@@ -104,7 +118,15 @@ public function testExecute(): void
104118

105119
$this->flushTokens->expects($this->once())
106120
->method('execute');
107-
121+
$session = $this->getMockBuilder(StorageInterface::class)
122+
->addMethods(['getAdobeAccessToken'])
123+
->getMockForAbstractClass();
124+
$session->expects($this->once())
125+
->method('getAdobeAccessToken')
126+
->willReturn(null);
127+
$this->auth->expects($this->once())
128+
->method('getAuthStorage')
129+
->willReturn($session);
108130
$this->assertEquals(true, $this->model->execute());
109131
}
110132

@@ -135,7 +157,15 @@ public function testExecuteWithError(): void
135157

136158
$this->flushTokens->expects($this->never())
137159
->method('execute');
138-
160+
$session = $this->getMockBuilder(StorageInterface::class)
161+
->addMethods(['getAdobeAccessToken'])
162+
->getMockForAbstractClass();
163+
$session->expects($this->once())
164+
->method('getAdobeAccessToken')
165+
->willReturn(null);
166+
$this->auth->expects($this->once())
167+
->method('getAuthStorage')
168+
->willReturn($session);
139169
$this->assertEquals(false, $this->model->execute());
140170
}
141171

@@ -161,7 +191,15 @@ public function testExecuteWithException(): void
161191
$curl->expects($this->once())
162192
->method('getStatus')
163193
->willReturn(self::HTTP_FOUND);
164-
194+
$session = $this->getMockBuilder(StorageInterface::class)
195+
->addMethods(['getAdobeAccessToken'])
196+
->getMockForAbstractClass();
197+
$session->expects($this->once())
198+
->method('getAdobeAccessToken')
199+
->willReturn(null);
200+
$this->auth->expects($this->once())
201+
->method('getAuthStorage')
202+
->willReturn($session);
165203
$this->flushTokens->expects($this->once())
166204
->method('execute')
167205
->willThrowException(new Exception('Could not save user profile.'));

0 commit comments

Comments
 (0)