Skip to content

Commit 331bf4e

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-86690' into 2.3-develop-pr9
2 parents 82fa678 + ee53c5a commit 331bf4e

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

app/code/Magento/Vault/Model/CustomerTokenManagement.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ public function __construct(
4040
*/
4141
public function getCustomerSessionTokens()
4242
{
43-
$vaultPayments = [];
44-
4543
$customerId = $this->session->getCustomerId();
46-
if (!$customerId) {
47-
return $vaultPayments;
44+
if (!$customerId || $this->session->isLoggedIn() === false) {
45+
return [];
4846
}
4947

5048
return $this->tokenManagement->getVisibleAvailableTokens($customerId);

app/code/Magento/Vault/Test/Unit/Model/CustomerTokenManagementTest.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,30 @@ protected function setUp()
4343
);
4444
}
4545

46-
public function testGetCustomerSessionTokensNonRegisteredCustomer()
46+
/**
47+
* @param int|null $customerId
48+
* @param bool $isLoggedCustomer
49+
* @return void
50+
* @dataProvider getCustomerSessionTokensNegativeDataProvider
51+
*/
52+
public function testGetCustomerSessionTokensNegative($customerId, bool $isLoggedCustomer)
4753
{
48-
$this->customerSession->expects(self::once())
49-
->method('getCustomerId')
50-
->willReturn(null);
54+
$this->customerSession->method('getCustomerId')->willReturn($customerId);
55+
$this->customerSession->method('isLoggedIn')->willReturn($isLoggedCustomer);
56+
$this->paymentTokenManagement->expects(static::never())->method('getVisibleAvailableTokens');
5157

52-
$this->paymentTokenManagement->expects(static::never())
53-
->method('getVisibleAvailableTokens');
54-
55-
$this->tokenManagement->getCustomerSessionTokens();
58+
static::assertEquals([], $this->tokenManagement->getCustomerSessionTokens());
5659
}
5760

58-
public function testGetCustomerSessionTokensForNotExistsCustomer()
61+
/**
62+
* @return array
63+
*/
64+
public function getCustomerSessionTokensNegativeDataProvider()
5965
{
60-
$this->customerSession->expects(static::once())
61-
->method('getCustomerId')
62-
->willReturn(null);
63-
64-
$this->paymentTokenManagement->expects(static::never())
65-
->method('getVisibleAvailableTokens');
66-
67-
$this->tokenManagement->getCustomerSessionTokens();
66+
return [
67+
'not registered customer' => [null, false],
68+
'not logged in customer' => [1, false],
69+
];
6870
}
6971

7072
public function testGetCustomerSessionTokens()
@@ -77,6 +79,10 @@ public function testGetCustomerSessionTokens()
7779
->method('getCustomerId')
7880
->willReturn($customerId);
7981

82+
$this->customerSession->expects(static::once())
83+
->method('isLoggedIn')
84+
->willReturn(true);
85+
8086
$this->paymentTokenManagement->expects(static::once())
8187
->method('getVisibleAvailableTokens')
8288
->with($customerId)

0 commit comments

Comments
 (0)