Skip to content

Commit f7c5d98

Browse files
committed
Merge remote-tracking branch 'origin/MC-32713' into 2.4-develop-com-pr11
2 parents 3bad18e + 7be2671 commit f7c5d98

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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\Customer\Controller\Adminhtml\Customer;
9+
10+
use Magento\Framework\App\Request\Http as HttpRequest;
11+
use Magento\Framework\Escaper;
12+
use Magento\Framework\Message\MessageInterface;
13+
use Magento\TestFramework\TestCase\AbstractBackendController;
14+
15+
/**
16+
* Invalidate customer token tests.
17+
*
18+
* @magentoAppArea adminhtml
19+
* @magentoDbIsolation enabled
20+
*/
21+
class InvalidateTokenTest extends AbstractBackendController
22+
{
23+
/** @var Escaper */
24+
private $escaper;
25+
26+
/**
27+
* @inheritdoc
28+
*/
29+
protected function setUp()
30+
{
31+
parent::setUp();
32+
33+
$this->escaper = $this->_objectManager->get(Escaper::class);
34+
}
35+
36+
/**
37+
* @magentoDataFixture Magento/Integration/_files/customer_with_integration_token.php
38+
*
39+
* @return void
40+
*/
41+
public function testInvalidateCustomerToken(): void
42+
{
43+
$customerId = 1;
44+
$this->getRequest()->setParam('customer_id', $customerId)->setMethod(HttpRequest::METHOD_GET);
45+
$this->dispatch('backend/customer/customer/invalidateToken');
46+
$this->assertRedirect($this->stringContains('backend/customer/index/edit/id/' . $customerId));
47+
$message = $this->escaper->escapeHtml('You have revoked the customer\'s tokens.');
48+
$this->assertSessionMessages($this->equalTo([(string)__($message)]), MessageInterface::TYPE_SUCCESS);
49+
}
50+
51+
/**
52+
* @magentoDataFixture Magento/Customer/_files/customer.php
53+
*
54+
* @return void
55+
*/
56+
public function testInvalidateCustomerWithoutToken(): void
57+
{
58+
$customerId = 1;
59+
$this->getRequest()->setParam('customer_id', $customerId)->setMethod(HttpRequest::METHOD_GET);
60+
$this->dispatch('backend/customer/customer/invalidateToken');
61+
$this->assertRedirect($this->stringContains('backend/customer/index/edit/id/' . $customerId));
62+
$this->assertSessionMessages(
63+
$this->equalTo([(string)__('This customer has no tokens.')]),
64+
MessageInterface::TYPE_ERROR
65+
);
66+
}
67+
68+
/**
69+
* @return void
70+
*/
71+
public function testInvalidateCustomerTokenWithoutParams(): void
72+
{
73+
$this->getRequest()->setMethod(HttpRequest::METHOD_GET);
74+
$this->dispatch('backend/customer/customer/invalidateToken');
75+
$this->assertRedirect($this->stringContains('backend/customer/index/index'));
76+
$message = $this->escaper->escapeHtml('We can\'t find a customer to revoke.');
77+
$this->assertSessionMessages($this->equalTo([(string)__($message)]), MessageInterface::TYPE_ERROR);
78+
}
79+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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\CustomerTokenServiceInterface;
9+
10+
require __DIR__ . '/../../../Magento/Customer/_files/customer.php';
11+
12+
/** @var CustomerTokenServiceInterface $customerTokenService */
13+
$customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
14+
15+
$customerTokenService->createCustomerAccessToken($customer->getEmail(), $customer->getPassword());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
require __DIR__ . '/../../../Magento/Customer/_files/customer_rollback.php';

0 commit comments

Comments
 (0)