VariablesSupportQueryTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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;
  8. use Magento\TestFramework\Helper\Bootstrap;
  9. use Magento\TestFramework\TestCase\GraphQlAbstract;
  10. use Magento\Catalog\Api\ProductRepositoryInterface;
  11. class VariablesSupportQueryTest extends GraphQlAbstract
  12. {
  13. /**
  14. * @var ProductRepositoryInterface
  15. */
  16. private $productRepository;
  17. protected function setUp()
  18. {
  19. $this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
  20. }
  21. /**
  22. * @magentoApiDataFixture Magento/Catalog/_files/products_list.php
  23. */
  24. public function testQueryObjectVariablesSupport()
  25. {
  26. $productSku = 'simple-249';
  27. $minPrice = 153;
  28. $query
  29. = <<<'QUERY'
  30. query GetProductsQuery($pageSize: Int, $filterInput: ProductFilterInput, $priceSort: SortEnum) {
  31. products(
  32. pageSize: $pageSize
  33. filter: $filterInput
  34. sort: {price: $priceSort}
  35. ) {
  36. items {
  37. sku
  38. price {
  39. minimalPrice {
  40. amount {
  41. value
  42. currency
  43. }
  44. }
  45. }
  46. }
  47. }
  48. }
  49. QUERY;
  50. $variables = [
  51. 'pageSize' => 1,
  52. 'priceSort' => 'ASC',
  53. 'filterInput' => [
  54. 'min_price' => [
  55. 'gt' => 150,
  56. ],
  57. ],
  58. ];
  59. $response = $this->graphQlQuery($query, $variables);
  60. /** @var \Magento\Catalog\Model\Product $product */
  61. $product = $this->productRepository->get($productSku, false, null, true);
  62. self::assertArrayHasKey('products', $response);
  63. self::assertArrayHasKey('items', $response['products']);
  64. self::assertEquals(1, count($response['products']['items']));
  65. self::assertArrayHasKey(0, $response['products']['items']);
  66. self::assertEquals($product->getSku(), $response['products']['items'][0]['sku']);
  67. self::assertEquals(
  68. $minPrice,
  69. $response['products']['items'][0]['price']['minimalPrice']['amount']['value']
  70. );
  71. }
  72. }