|
| 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 | +} |
0 commit comments