|
7 | 7 |
|
8 | 8 | use Magento\Catalog\Api\Data\ProductTierPriceInterface;
|
9 | 9 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
| 10 | +use Magento\Catalog\Model\Product\Attribute\Source\Status; |
10 | 11 | use Magento\Customer\Api\CustomerRepositoryInterface;
|
11 | 12 | use Magento\Customer\Model\Session as CustomerSession;
|
12 | 13 | use Magento\Framework\Api\FilterBuilder;
|
|
17 | 18 | use Magento\TestFramework\Helper\Bootstrap;
|
18 | 19 |
|
19 | 20 | /**
|
20 |
| - * Class SessionTest |
| 21 | + * Checkout Session model test. |
21 | 22 | *
|
22 | 23 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
23 | 24 | */
|
@@ -54,6 +55,35 @@ protected function setUp()
|
54 | 55 | $this->checkoutSession = $this->objectManager->create(Session::class);
|
55 | 56 | }
|
56 | 57 |
|
| 58 | + /** |
| 59 | + * Tests that quote items and totals are correct when product becomes unavailable. |
| 60 | + * |
| 61 | + * @magentoDataFixture Magento/Customer/_files/customer.php |
| 62 | + * @magentoDataFixture Magento/Sales/_files/quote.php |
| 63 | + * @magentoAppIsolation enabled |
| 64 | + */ |
| 65 | + public function testGetQuoteWithUnavailableProduct() |
| 66 | + { |
| 67 | + $reservedOrderId = 'test01'; |
| 68 | + $quoteGrandTotal = 10; |
| 69 | + |
| 70 | + $quote = $this->getQuote($reservedOrderId); |
| 71 | + $this->assertEquals(1, $quote->getItemsCount()); |
| 72 | + $this->assertCount(1, $quote->getItems()); |
| 73 | + $this->assertEquals($quoteGrandTotal, $quote->getShippingAddress()->getBaseGrandTotal()); |
| 74 | + |
| 75 | + $productRepository = $this->objectManager->get(ProductRepositoryInterface::class); |
| 76 | + $product = $productRepository->get('simple'); |
| 77 | + $product->setStatus(Status::STATUS_DISABLED); |
| 78 | + $productRepository->save($product); |
| 79 | + $this->checkoutSession->setQuoteId($quote->getId()); |
| 80 | + $quote = $this->checkoutSession->getQuote(); |
| 81 | + |
| 82 | + $this->assertEquals(0, $quote->getItemsCount()); |
| 83 | + $this->assertEmpty($quote->getItems()); |
| 84 | + $this->assertEquals(0, $quote->getShippingAddress()->getBaseGrandTotal()); |
| 85 | + } |
| 86 | + |
57 | 87 | /**
|
58 | 88 | * Test covers case when quote is not yet initialized and customer data is set to checkout session model.
|
59 | 89 | *
|
|
0 commit comments