|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2025 Adobe |
| 4 | + * All Rights Reserved. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\GraphQl\Quote; |
| 9 | + |
| 10 | +use Magento\Catalog\Test\Fixture\Product as ProductFixture; |
| 11 | +use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture; |
| 12 | +use Magento\Quote\Test\Fixture\GuestCart; |
| 13 | +use Magento\Quote\Test\Fixture\QuoteIdMask; |
| 14 | +use Magento\TestFramework\Fixture\Config as ConfigFixture; |
| 15 | +use Magento\TestFramework\Fixture\DataFixture; |
| 16 | +use Magento\TestFramework\Fixture\DataFixtureStorage; |
| 17 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
| 18 | +use Magento\TestFramework\TestCase\GraphQlAbstract; |
| 19 | + |
| 20 | +class NotAvailableMessageTest extends GraphQlAbstract |
| 21 | +{ |
| 22 | + /** |
| 23 | + * @var DataFixtureStorage |
| 24 | + */ |
| 25 | + private $fixtures; |
| 26 | + |
| 27 | + protected function setUp(): void |
| 28 | + { |
| 29 | + $this->fixtures = DataFixtureStorageManager::getStorage(); |
| 30 | + } |
| 31 | + |
| 32 | + #[ |
| 33 | + ConfigFixture('cataloginventory/options/enable_inventory_check', false, "store", "default"), |
| 34 | + ConfigFixture('cataloginventory/options/not_available_message', true, "store", "default"), |
| 35 | + DataFixture(ProductFixture::class, as: 'product'), |
| 36 | + DataFixture(GuestCart::class, as: 'cart'), |
| 37 | + DataFixture(QuoteIdMask::class, ['cart_id' => '$cart.id$'], 'quoteIdMask'), |
| 38 | + DataFixture( |
| 39 | + AddProductToCartFixture::class, |
| 40 | + [ |
| 41 | + 'cart_id' => '$cart.id$', |
| 42 | + 'product_id' => '$product.id$', |
| 43 | + 'qty' => 1 |
| 44 | + ] |
| 45 | + ) |
| 46 | + ] |
| 47 | + public function testNotAvailableMessageWithoutInventoryCheck(): void |
| 48 | + { |
| 49 | + $this->assertCartResponse(); |
| 50 | + } |
| 51 | + |
| 52 | + #[ |
| 53 | + ConfigFixture('cataloginventory/options/enable_inventory_check', true, "store", "default"), |
| 54 | + ConfigFixture('cataloginventory/options/not_available_message', true, "store", "default"), |
| 55 | + DataFixture(ProductFixture::class, as: 'product'), |
| 56 | + DataFixture(GuestCart::class, as: 'cart'), |
| 57 | + DataFixture(QuoteIdMask::class, ['cart_id' => '$cart.id$'], 'quoteIdMask'), |
| 58 | + DataFixture( |
| 59 | + AddProductToCartFixture::class, |
| 60 | + [ |
| 61 | + 'cart_id' => '$cart.id$', |
| 62 | + 'product_id' => '$product.id$', |
| 63 | + 'qty' => 1 |
| 64 | + ] |
| 65 | + ) |
| 66 | + ] |
| 67 | + public function testNotAvailableMessageWithInventoryCheck(): void |
| 68 | + { |
| 69 | + $this->assertCartResponse(); |
| 70 | + } |
| 71 | + |
| 72 | + private function assertCartResponse(): void |
| 73 | + { |
| 74 | + $this->assertEquals( |
| 75 | + [ |
| 76 | + 'cart' => [ |
| 77 | + 'itemsV2' => [ |
| 78 | + 'items' => [ |
| 79 | + [ |
| 80 | + 'not_available_message' => null, |
| 81 | + ] |
| 82 | + ] |
| 83 | + ] |
| 84 | + ] |
| 85 | + ], |
| 86 | + $this->graphQlQuery( |
| 87 | + $this->getCartQuery($this->fixtures->get('quoteIdMask')->getMaskedId()) |
| 88 | + ) |
| 89 | + ); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Get cart query with not available message |
| 94 | + * |
| 95 | + * @param string $maskedQuoteId |
| 96 | + * @return string |
| 97 | + */ |
| 98 | + private function getCartQuery(string $maskedQuoteId): string |
| 99 | + { |
| 100 | + return <<<QUERY |
| 101 | + { |
| 102 | + cart(cart_id: "{$maskedQuoteId}") { |
| 103 | + itemsV2 { |
| 104 | + items { |
| 105 | + not_available_message |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + QUERY; |
| 111 | + } |
| 112 | +} |
0 commit comments