GenerateCustomerTokenTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\TestFramework\TestCase\GraphQlAbstract;
  9. use PHPUnit\Framework\TestResult;
  10. /**
  11. * Class GenerateCustomerTokenTest
  12. * @package Magento\GraphQl\Customer
  13. */
  14. class GenerateCustomerTokenTest extends GraphQlAbstract
  15. {
  16. /**
  17. * Verify customer token with valid credentials
  18. *
  19. * @magentoApiDataFixture Magento/Customer/_files/customer.php
  20. */
  21. public function testGenerateCustomerValidToken()
  22. {
  23. $userName = 'customer@example.com';
  24. $password = 'password';
  25. $mutation
  26. = <<<MUTATION
  27. mutation {
  28. generateCustomerToken(
  29. email: "{$userName}"
  30. password: "{$password}"
  31. ) {
  32. token
  33. }
  34. }
  35. MUTATION;
  36. $response = $this->graphQlQuery($mutation);
  37. $this->assertArrayHasKey('generateCustomerToken', $response);
  38. $this->assertInternalType('array', $response['generateCustomerToken']);
  39. }
  40. /**
  41. * Verify customer with invalid credentials
  42. */
  43. public function testGenerateCustomerTokenWithInvalidCredentials()
  44. {
  45. $userName = 'customer@example.com';
  46. $password = 'bad-password';
  47. $mutation
  48. = <<<MUTATION
  49. mutation {
  50. generateCustomerToken(
  51. email: "{$userName}"
  52. password: "{$password}"
  53. ) {
  54. token
  55. }
  56. }
  57. MUTATION;
  58. $this->expectException(\Exception::class);
  59. $this->expectExceptionMessage('GraphQL response contains errors: The account sign-in' . ' ' .
  60. 'was incorrect or your account is disabled temporarily. Please wait and try again later.');
  61. $this->graphQlQuery($mutation);
  62. }
  63. }