|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\GraphQl\Catalog\Options\Uid; |
| 9 | + |
| 10 | +use Exception; |
| 11 | +use Magento\TestFramework\Helper\Bootstrap; |
| 12 | +use Magento\TestFramework\Helper\CompareArraysRecursively; |
| 13 | +use Magento\TestFramework\TestCase\GraphQlAbstract; |
| 14 | + |
| 15 | +/** |
| 16 | + * Test for customizable product options. |
| 17 | + */ |
| 18 | +class CustomizableOptionsTest extends GraphQlAbstract |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var CompareArraysRecursively |
| 22 | + */ |
| 23 | + private $compareArraysRecursively; |
| 24 | + |
| 25 | + /** |
| 26 | + * @inheritDoc |
| 27 | + */ |
| 28 | + protected function setUp(): void |
| 29 | + { |
| 30 | + $objectManager = Bootstrap::getObjectManager(); |
| 31 | + $this->compareArraysRecursively = $objectManager->create(CompareArraysRecursively::class); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @magentoApiDataFixture Magento/Catalog/_files/product_with_options.php |
| 36 | + * |
| 37 | + * @param array $optionDataProvider |
| 38 | + * |
| 39 | + * @dataProvider getProductCustomizableOptionsProvider |
| 40 | + * @throws Exception |
| 41 | + */ |
| 42 | + public function testQueryCustomizableOptions(array $optionDataProvider): void |
| 43 | + { |
| 44 | + $productSku = 'simple'; |
| 45 | + $query = $this->getQuery($productSku); |
| 46 | + $response = $this->graphQlQuery($query); |
| 47 | + $responseProduct = reset($response['products']['items']); |
| 48 | + self::assertNotEmpty($responseProduct['options']); |
| 49 | + |
| 50 | + foreach ($optionDataProvider as $key => $data) { |
| 51 | + $this->compareArraysRecursively->execute($data, $responseProduct[$key]); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Get query. |
| 57 | + * |
| 58 | + * @param string $sku |
| 59 | + * |
| 60 | + * @return string |
| 61 | + */ |
| 62 | + private function getQuery(string $sku): string |
| 63 | + { |
| 64 | + return <<<QUERY |
| 65 | +query { |
| 66 | + products(filter: { sku: { eq: "$sku" } }) { |
| 67 | + items { |
| 68 | + ... on CustomizableProductInterface { |
| 69 | + options { |
| 70 | + option_id |
| 71 | + title |
| 72 | + ... on CustomizableDateOption { |
| 73 | + value { |
| 74 | + type |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | +} |
| 82 | +QUERY; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Get product customizable options provider. |
| 87 | + * |
| 88 | + * @return array |
| 89 | + */ |
| 90 | + public function getProductCustomizableOptionsProvider(): array |
| 91 | + { |
| 92 | + return [ |
| 93 | + 'products' => [ |
| 94 | + 'items' => [ |
| 95 | + 'options' => [ |
| 96 | + [ |
| 97 | + 'title' => 'test_option_code_1' |
| 98 | + ], |
| 99 | + [ |
| 100 | + 'title' => 'area option' |
| 101 | + ], |
| 102 | + [ |
| 103 | + 'title' => 'file option' |
| 104 | + ], |
| 105 | + [ |
| 106 | + 'title' => 'radio option' |
| 107 | + ], |
| 108 | + [ |
| 109 | + 'title' => 'multiple option' |
| 110 | + ], |
| 111 | + [ |
| 112 | + 'title' => 'date option', |
| 113 | + 'values' => [ |
| 114 | + 'type' => 'date' |
| 115 | + ] |
| 116 | + ], |
| 117 | + [ |
| 118 | + 'title' => 'date_time option', |
| 119 | + 'values' => [ |
| 120 | + 'type' => 'date_time' |
| 121 | + ] |
| 122 | + ], |
| 123 | + [ |
| 124 | + 'title' => 'time option', |
| 125 | + 'values' => [ |
| 126 | + 'type' => 'time' |
| 127 | + ] |
| 128 | + ] |
| 129 | + ] |
| 130 | + ] |
| 131 | + ] |
| 132 | + ]; |
| 133 | + } |
| 134 | +} |
0 commit comments