RevokeCustomerTokenTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\GraphQl\Customer;
  8. use Magento\Integration\Api\CustomerTokenServiceInterface;
  9. use Magento\TestFramework\ObjectManager;
  10. use Magento\TestFramework\TestCase\GraphQlAbstract;
  11. /**
  12. * Test for revoke customer token mutation
  13. */
  14. class RevokeCustomerTokenTest extends GraphQlAbstract
  15. {
  16. /**
  17. * @magentoApiDataFixture Magento/Customer/_files/customer.php
  18. */
  19. public function testRevokeCustomerTokenValidCredentials()
  20. {
  21. $query = <<<QUERY
  22. mutation {
  23. revokeCustomerToken {
  24. result
  25. }
  26. }
  27. QUERY;
  28. $userName = 'customer@example.com';
  29. $password = 'password';
  30. /** @var CustomerTokenServiceInterface $customerTokenService */
  31. $customerTokenService = ObjectManager::getInstance()->get(CustomerTokenServiceInterface::class);
  32. $customerToken = $customerTokenService->createCustomerAccessToken($userName, $password);
  33. $headerMap = ['Authorization' => 'Bearer ' . $customerToken];
  34. $response = $this->graphQlQuery($query, [], '', $headerMap);
  35. $this->assertTrue($response['revokeCustomerToken']['result']);
  36. }
  37. /**
  38. * @expectedException \Exception
  39. * @expectedExceptionMessage The current customer isn't authorized.
  40. */
  41. public function testRevokeCustomerTokenForGuestCustomer()
  42. {
  43. $query = <<<QUERY
  44. mutation {
  45. revokeCustomerToken {
  46. result
  47. }
  48. }
  49. QUERY;
  50. $this->graphQlQuery($query, [], '');
  51. }
  52. }