|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Copyright © Magento, Inc. All rights reserved. |
4 | | - * See COPYING.txt for license details. |
| 3 | + * Copyright 2017 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
6 | 8 | namespace Magento\Sales\Model\Order; |
7 | 9 |
|
8 | | -class ItemTest extends \PHPUnit\Framework\TestCase |
| 10 | +use Magento\Catalog\Test\Fixture\Product as ProductFixture; |
| 11 | +use Magento\Catalog\Test\Fixture\ProductStock as ProductStockFixture; |
| 12 | +use Magento\Checkout\Test\Fixture\PlaceOrder as PlaceOrderFixture; |
| 13 | +use Magento\Checkout\Test\Fixture\SetBillingAddress as SetBillingAddressFixture; |
| 14 | +use Magento\Checkout\Test\Fixture\SetDeliveryMethod as SetDeliveryMethodFixture; |
| 15 | +use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethodFixture; |
| 16 | +use Magento\Checkout\Test\Fixture\SetShippingAddress as SetShippingAddressFixture; |
| 17 | +use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture; |
| 18 | +use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture; |
| 19 | +use Magento\Sales\Model\Order; |
| 20 | +use Magento\Sales\Test\Fixture\Creditmemo as CreditmemoFixture; |
| 21 | +use Magento\Sales\Test\Fixture\Invoice as InvoiceFixture; |
| 22 | +use Magento\Sales\Test\Fixture\Shipment as ShipmentFixture; |
| 23 | +use Magento\TestFramework\Fixture\DataFixture; |
| 24 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
| 25 | +use PHPUnit\Framework\TestCase; |
| 26 | + |
| 27 | +/** |
| 28 | + * Test for the Order Item model |
| 29 | + * |
| 30 | + * @suppressWarnings(PHPMD.CouplingBetweenObjects) |
| 31 | + */ |
| 32 | +class ItemTest extends TestCase |
9 | 33 | { |
10 | 34 | /** |
11 | 35 | * @param string $options |
@@ -35,4 +59,71 @@ public static function getProductOptionsDataProvider() |
35 | 59 | ], |
36 | 60 | ]; |
37 | 61 | } |
| 62 | + |
| 63 | + /** |
| 64 | + * Test getSimpleQtyToShip method |
| 65 | + * |
| 66 | + * @magentoDbIsolation disabled |
| 67 | + * @magentoAppArea adminhtml |
| 68 | + * @magentoConfigFixture default/catalog/seo/generate_category_product_rewrites 0 |
| 69 | + */ |
| 70 | + #[ |
| 71 | + DataFixture(ProductFixture::class, as: 'product'), |
| 72 | + DataFixture(ProductStockFixture::class, ['prod_id' => '$product.id$', 'prod_qty' => 100, 'is_in_stock' => 1]), |
| 73 | + DataFixture(GuestCartFixture::class, as: 'cart'), |
| 74 | + DataFixture( |
| 75 | + AddProductToCartFixture::class, |
| 76 | + ['cart_id' => '$cart.id$', 'product_id' => '$product.id$', 'qty' => 10] |
| 77 | + ), |
| 78 | + DataFixture( |
| 79 | + SetBillingAddressFixture::class, |
| 80 | + ['cart_id' => '$cart.id$', 'address' => ['email' => 'guest@example.com']] |
| 81 | + ), |
| 82 | + DataFixture( |
| 83 | + SetShippingAddressFixture::class, |
| 84 | + ['cart_id' => '$cart.id$', 'address' => ['email' => 'guest@example.com']] |
| 85 | + ), |
| 86 | + DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$cart.id$']), |
| 87 | + DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$cart.id$']), |
| 88 | + DataFixture(PlaceOrderFixture::class, ['cart_id' => '$cart.id$'], 'order'), |
| 89 | + DataFixture(InvoiceFixture::class, ['order_id' => '$order.id$'], 'invoice'), |
| 90 | + DataFixture( |
| 91 | + ShipmentFixture::class, |
| 92 | + ['order_id' => '$order.id$', 'items' => [['product_id' => '$product.id$', 'qty' => 1]]] |
| 93 | + ), |
| 94 | + DataFixture( |
| 95 | + CreditmemoFixture::class, |
| 96 | + ['order_id' => '$order.id$', 'items' => [['product_id' => '$product.id$', 'qty' => 2]]] |
| 97 | + ), |
| 98 | + DataFixture( |
| 99 | + ShipmentFixture::class, |
| 100 | + ['order_id' => '$order.id$', 'items' => [['product_id' => '$product.id$', 'qty' => 1]]] |
| 101 | + ), |
| 102 | + DataFixture( |
| 103 | + CreditmemoFixture::class, |
| 104 | + ['order_id' => '$order.id$', 'items' => [['product_id' => '$product.id$', 'qty' => 2]]] |
| 105 | + ) |
| 106 | + ] |
| 107 | + public function testGetSimpleQtyToShip() |
| 108 | + { |
| 109 | + $fixtures = DataFixtureStorageManager::getStorage(); |
| 110 | + |
| 111 | + /** @var Order $order */ |
| 112 | + $order = $fixtures->get('order'); |
| 113 | + |
| 114 | + // Get order item |
| 115 | + $orderItems = $order->getItems(); |
| 116 | + /** @var Item $orderItem */ |
| 117 | + $orderItem = reset($orderItems); |
| 118 | + |
| 119 | + // Verify quantities |
| 120 | + $this->assertEquals(10, $orderItem->getQtyOrdered(), 'Qty ordered should be 10'); |
| 121 | + $this->assertEquals(10, $orderItem->getQtyInvoiced(), 'Qty invoiced should be 10'); |
| 122 | + $this->assertEquals(2, $orderItem->getQtyShipped(), 'Qty shipped should be 2'); |
| 123 | + $this->assertEquals(4, $orderItem->getQtyRefunded(), 'Qty refunded should be 4'); |
| 124 | + |
| 125 | + // Assert getSimpleQtyToShip value |
| 126 | + // Qty to ship = Qty ordered (10) - Qty shipped (2) - Qty refunded (4) = 4 |
| 127 | + $this->assertEquals(4, $orderItem->getSimpleQtyToShip(), 'Simple qty to ship should be 3'); |
| 128 | + } |
38 | 129 | } |
0 commit comments