CountryTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\Directory;
  8. use Magento\TestFramework\TestCase\GraphQlAbstract;
  9. /**
  10. * Test the GraphQL endpoint's Coutries query
  11. */
  12. class CountryTest extends GraphQlAbstract
  13. {
  14. public function testGetCountry()
  15. {
  16. $query = <<<QUERY
  17. query {
  18. country(id: "US") {
  19. id
  20. two_letter_abbreviation
  21. three_letter_abbreviation
  22. full_name_locale
  23. full_name_english
  24. available_regions {
  25. id
  26. code
  27. name
  28. }
  29. }
  30. }
  31. QUERY;
  32. $result = $this->graphQlQuery($query);
  33. $this->assertArrayHasKey('country', $result);
  34. $this->assertArrayHasKey('id', $result['country']);
  35. $this->assertArrayHasKey('two_letter_abbreviation', $result['country']);
  36. $this->assertArrayHasKey('three_letter_abbreviation', $result['country']);
  37. $this->assertArrayHasKey('full_name_locale', $result['country']);
  38. $this->assertArrayHasKey('full_name_english', $result['country']);
  39. $this->assertArrayHasKey('available_regions', $result['country']);
  40. $this->assertArrayHasKey('id', $result['country']['available_regions'][0]);
  41. $this->assertArrayHasKey('code', $result['country']['available_regions'][0]);
  42. $this->assertArrayHasKey('name', $result['country']['available_regions'][0]);
  43. }
  44. /**
  45. * @expectedException \Exception
  46. * @expectedExceptionMessage GraphQL response contains errors: The country isn't available.
  47. */
  48. public function testGetCountryNotFoundException()
  49. {
  50. $query = <<<QUERY
  51. query {
  52. country(id: "BLAH") {
  53. id
  54. two_letter_abbreviation
  55. three_letter_abbreviation
  56. full_name_locale
  57. full_name_english
  58. available_regions {
  59. id
  60. code
  61. name
  62. }
  63. }
  64. }
  65. QUERY;
  66. $this->graphQlQuery($query);
  67. }
  68. }