|
11 | 11 | use Magento\Catalog\Api\Data\ProductInterface;
|
12 | 12 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
13 | 13 | use Magento\Catalog\Model\Product;
|
14 |
| -use Magento\ConfigurableProduct\Model\Product\Type\Configurable; |
| 14 | +use Magento\CatalogInventory\Model\Stock\Status; |
15 | 15 | use Magento\TestFramework\Helper\Bootstrap;
|
16 | 16 |
|
17 | 17 | /**
|
@@ -465,6 +465,40 @@ protected function _getAttributeByCode($code)
|
465 | 465 | );
|
466 | 466 | }
|
467 | 467 |
|
| 468 | + /** |
| 469 | + * @magentoAppIsolation enabled |
| 470 | + * @dataProvider allowProductsDataProvider |
| 471 | + */ |
| 472 | + public function testGetSalableUsedProducts($isInStock, $status, $expectedCount) |
| 473 | + { |
| 474 | + /** @var ProductRepositoryInterface $productRepository */ |
| 475 | + $productRepository = Bootstrap::getObjectManager()->create(ProductRepositoryInterface::class); |
| 476 | + $childProduct = $productRepository->get('simple_10'); |
| 477 | + $childProduct->setStatus($status); |
| 478 | + $stockItem = $childProduct->getExtensionAttributes()->getStockItem(); |
| 479 | + $stockItem->setIsInStock($isInStock); |
| 480 | + $productRepository->save($childProduct); |
| 481 | + |
| 482 | + $products = $this->model->getSalableUsedProducts($this->product); |
| 483 | + $this->assertCount($expectedCount, $products); |
| 484 | + foreach ($products as $product) { |
| 485 | + $this->assertInstanceOf('Magento\Catalog\Model\Product', $product); |
| 486 | + } |
| 487 | + } |
| 488 | + |
| 489 | + /** |
| 490 | + * @return array |
| 491 | + */ |
| 492 | + public function allowProductsDataProvider() |
| 493 | + { |
| 494 | + return [ |
| 495 | + [Status::STATUS_OUT_OF_STOCK, false, 1], |
| 496 | + [Status::STATUS_OUT_OF_STOCK, true, 1], |
| 497 | + [Status::STATUS_IN_STOCK, false, 1], |
| 498 | + [Status::STATUS_IN_STOCK, true, 2], |
| 499 | + ]; |
| 500 | + } |
| 501 | + |
468 | 502 | /**
|
469 | 503 | * Select one of the options and "prepare for cart" with a proper buy request
|
470 | 504 | *
|
|
0 commit comments