|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\CatalogInventory\Model\Plugin; |
| 10 | + |
| 11 | +use Magento\CatalogInventory\Api\Data\StockItemInterface; |
| 12 | + |
| 13 | +/** |
| 14 | + * @magentoAppArea adminhtml |
| 15 | + */ |
| 16 | +class ProductSearchTest extends \Magento\TestFramework\TestCase\AbstractBackendController |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @var array |
| 20 | + */ |
| 21 | + private $stockItemData = [ |
| 22 | + StockItemInterface::QTY => 555, |
| 23 | + StockItemInterface::MANAGE_STOCK => true, |
| 24 | + StockItemInterface::IS_IN_STOCK => false, |
| 25 | + ]; |
| 26 | + |
| 27 | + /** |
| 28 | + * @magentoDataFixture Magento/Catalog/_files/product_simple.php |
| 29 | + * @magentoConfigFixture current_store cataloginventory/options/show_out_of_stock 1 |
| 30 | + */ |
| 31 | + public function testExecute() : void |
| 32 | + { |
| 33 | + $productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() |
| 34 | + ->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); |
| 35 | + $product = $productRepository->get('simple'); |
| 36 | + $product->setQuantityAndStockStatus($this->stockItemData); |
| 37 | + $product->save(); |
| 38 | + $this->getRequest() |
| 39 | + ->setPostValue('searchKey', 'simple') |
| 40 | + ->setPostValue('page', 1) |
| 41 | + ->setPostValue('limit', 50); |
| 42 | + $this->dispatch('backend/catalog/product/search'); |
| 43 | + $responseBody = $this->getResponse()->getBody(); |
| 44 | + $this->assertContains( |
| 45 | + '"options":{"1":{"value":"1","label":"Simple Product","is_active":1,"path":"simple","optgroup":false}', |
| 46 | + $responseBody |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @magentoDataFixture Magento/Catalog/_files/product_simple.php |
| 52 | + * @magentoConfigFixture current_store cataloginventory/options/show_out_of_stock 0 |
| 53 | + */ |
| 54 | + public function testExecuteNotShowOutOfStock() : void |
| 55 | + { |
| 56 | + $productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() |
| 57 | + ->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); |
| 58 | + $product = $productRepository->get('simple'); |
| 59 | + $product->setQuantityAndStockStatus($this->stockItemData); |
| 60 | + $product->save(); |
| 61 | + $this->getRequest() |
| 62 | + ->setPostValue('searchKey', 'simple') |
| 63 | + ->setPostValue('page', 1) |
| 64 | + ->setPostValue('limit', 50); |
| 65 | + $this->dispatch('backend/catalog/product/search'); |
| 66 | + $responseBody = $this->getResponse()->getBody(); |
| 67 | + $this->assertNotContains( |
| 68 | + '"options":{"1":{"value":"1","label":"Simple Product","is_active":1,"path":"simple","optgroup":false}', |
| 69 | + $responseBody |
| 70 | + ); |
| 71 | + } |
| 72 | +} |
0 commit comments