|
14 | 14 |
|
15 | 15 | class VariablesSupportQueryTest extends GraphQlAbstract
|
16 | 16 | {
|
17 |
| - /** |
18 |
| - * @var ObjectManager |
19 |
| - */ |
20 |
| - private $objectManager; |
21 |
| - |
22 | 17 | /**
|
23 | 18 | * @var ProductRepositoryInterface
|
24 | 19 | */
|
25 | 20 | private $productRepository;
|
26 | 21 |
|
27 | 22 | protected function setUp()
|
28 | 23 | {
|
29 |
| - $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
30 |
| - $this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class); |
| 24 | + $this->productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class); |
31 | 25 | }
|
32 | 26 |
|
33 | 27 | /**
|
34 |
| - * Tests that Introspection is disabled when not in developer mode |
35 |
| - * |
36 |
| - * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_all_fields.php |
37 |
| - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 28 | + * @magentoApiDataFixture Magento/Catalog/_files/products_list.php |
38 | 29 | */
|
39 | 30 | public function testQueryObjectVariablesSupport()
|
40 | 31 | {
|
41 |
| - $productSku = 'simple'; |
| 32 | + $productSku = 'simple-249'; |
| 33 | + $minPrice = 153; |
42 | 34 |
|
43 | 35 | $query
|
44 | 36 | = <<<'QUERY'
|
45 |
| -query GetProductsQuery($page: Int, $filterInput: ProductFilterInput){ |
| 37 | +query GetProductsQuery($pageSize: Int, $filterInput: ProductFilterInput, $priceSort: SortEnum) { |
46 | 38 | products(
|
47 |
| - pageSize: 10 |
48 |
| - currentPage: $page |
| 39 | + pageSize: $pageSize |
49 | 40 | filter: $filterInput
|
50 |
| - sort: {} |
| 41 | + sort: {price: $priceSort} |
51 | 42 | ) {
|
52 | 43 | items {
|
53 |
| - name |
| 44 | + sku |
| 45 | + price { |
| 46 | + minimalPrice { |
| 47 | + amount { |
| 48 | + value |
| 49 | + currency |
| 50 | + } |
| 51 | + } |
| 52 | + } |
54 | 53 | }
|
55 | 54 | }
|
56 | 55 | }
|
57 | 56 | QUERY;
|
| 57 | + |
58 | 58 | $variables = [
|
59 |
| - 'page' => 1, |
| 59 | + 'pageSize' => 1, |
| 60 | + 'priceSort' => 'ASC', |
60 | 61 | 'filterInput' => [
|
61 |
| - 'sku' => [ |
62 |
| - 'like' => '%simple%' |
63 |
| - ] |
64 |
| - ] |
| 62 | + 'min_price' => [ |
| 63 | + 'gt' => 150, |
| 64 | + ], |
| 65 | + ], |
65 | 66 | ];
|
66 | 67 |
|
67 | 68 | $response = $this->graphQlQuery($query, $variables);
|
68 | 69 | /** @var \Magento\Catalog\Model\Product $product */
|
69 | 70 | $product = $this->productRepository->get($productSku, false, null, true);
|
70 | 71 |
|
71 |
| - $this->assertArrayHasKey('products', $response); |
72 |
| - $this->assertArrayHasKey('items', $response['products']); |
73 |
| - $this->assertEquals(1, count($response['products']['items'])); |
74 |
| - $this->assertArrayHasKey(0, $response['products']['items']); |
75 |
| - $this->assertFields($product, $response['products']['items'][0]); |
76 |
| - } |
77 |
| - |
78 |
| - /** |
79 |
| - * @param ProductInterface $product |
80 |
| - * @param array $actualResponse |
81 |
| - */ |
82 |
| - private function assertFields($product, $actualResponse) |
83 |
| - { |
84 |
| - $assertionMap = [ |
85 |
| - ['response_field' => 'name', 'expected_value' => $product->getName()], |
86 |
| - ]; |
87 |
| - |
88 |
| - $this->assertResponseFields($actualResponse, $assertionMap); |
| 72 | + self::assertArrayHasKey('products', $response); |
| 73 | + self::assertArrayHasKey('items', $response['products']); |
| 74 | + self::assertEquals(1, count($response['products']['items'])); |
| 75 | + self::assertArrayHasKey(0, $response['products']['items']); |
| 76 | + self::assertEquals($product->getSku(), $response['products']['items'][0]['sku']); |
| 77 | + self::assertEquals( |
| 78 | + $minPrice, |
| 79 | + $response['products']['items'][0]['price']['minimalPrice']['amount']['value'] |
| 80 | + ); |
89 | 81 | }
|
90 | 82 | }
|
0 commit comments