|
| 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\Bundle; |
| 9 | + |
| 10 | +use Magento\Bundle\Test\Fixture\Link as BundleSelectionFixture; |
| 11 | +use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture; |
| 12 | +use Magento\Bundle\Test\Fixture\Product as BundleProductFixture; |
| 13 | +use Magento\Catalog\Test\Fixture\Category as CategoryFixture; |
| 14 | +use Magento\Catalog\Test\Fixture\Product as ProductFixture; |
| 15 | +use Magento\CatalogInventory\Model\Configuration as CatalogInventoryConfiguration; |
| 16 | +use Magento\TestFramework\Fixture\Config as ConfigFixture; |
| 17 | +use Magento\TestFramework\Fixture\DataFixture; |
| 18 | +use Magento\TestFramework\TestCase\GraphQlAbstract; |
| 19 | + |
| 20 | +class CategoryListTest extends GraphQlAbstract |
| 21 | +{ |
| 22 | + #[ |
| 23 | + ConfigFixture(CatalogInventoryConfiguration::XML_PATH_SHOW_OUT_OF_STOCK, '1'), |
| 24 | + DataFixture(CategoryFixture::class, ['url_path' => 'cat1'], 'cat1'), |
| 25 | + DataFixture(ProductFixture::class, ['sku' => 's1', 'stock_item' => ['is_in_stock' => false]], 's1'), |
| 26 | + DataFixture(ProductFixture::class, ['sku' => 's2'], 's2'), |
| 27 | + DataFixture(BundleSelectionFixture::class, ['sku' => '$s1.sku$', 'price' => 10, 'price_type' => 0], 'link1'), |
| 28 | + DataFixture(BundleSelectionFixture::class, ['sku' => '$s2.sku$', 'price' => 20, 'price_type' => 0], 'link2'), |
| 29 | + DataFixture(BundleOptionFixture::class, ['product_links' => ['$link1$', '$link2$']], 'opt1'), |
| 30 | + DataFixture( |
| 31 | + BundleProductFixture::class, |
| 32 | + ['sku' => 'bundle1', 'category_ids' => ['$cat1.id$'], '_options' => ['$opt1$']], |
| 33 | + 'bundle1' |
| 34 | + ), |
| 35 | + ] |
| 36 | + public function testOutOfStockBundleSelectionWithEnabledShowOutOfStock(): void |
| 37 | + { |
| 38 | + $query = $this->getQuery('cat1'); |
| 39 | + $response = $this->graphQlQuery($query); |
| 40 | + self::assertNotEmpty($response['categoryList']); |
| 41 | + $categoryList = $response['categoryList'][0]; |
| 42 | + self::assertNotEmpty($categoryList['products']['items']); |
| 43 | + $bundle = $categoryList['products']['items'][0]; |
| 44 | + self::assertEquals('bundle1', $bundle['sku']); |
| 45 | + self::assertCount(2, $bundle['items'][0]['options']); |
| 46 | + self::assertEquals('s1', $bundle['items'][0]['options'][0]['product']['sku']); |
| 47 | + self::assertEquals('s2', $bundle['items'][0]['options'][1]['product']['sku']); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @param string $urlPath |
| 52 | + * @return string |
| 53 | + */ |
| 54 | + private function getQuery(string $urlPath): string |
| 55 | + { |
| 56 | + $query = <<<QUERY |
| 57 | +{ |
| 58 | + categoryList(filters: {url_path: {eq: "$urlPath"}}) { |
| 59 | + id |
| 60 | + name |
| 61 | + products { |
| 62 | + total_count |
| 63 | + items { |
| 64 | + sku |
| 65 | + ... on BundleProduct { |
| 66 | + items { |
| 67 | + options { |
| 68 | + product { |
| 69 | + sku |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | +} |
| 78 | +QUERY; |
| 79 | + |
| 80 | + return $query; |
| 81 | + } |
| 82 | +} |
0 commit comments