Skip to content

Commit 6572d43

Browse files
committed
MC-36971: Create automated test for "Calculation of invoiced child items in "sales_order_item" table for order with configurable product after partial invoice"
1 parent 4ae0f74 commit 6572d43

File tree

1 file changed

+39
-0
lines changed
  • dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice

1 file changed

+39
-0
lines changed

dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/SaveTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
use Magento\Framework\Escaper;
1111
use Magento\Sales\Api\Data\InvoiceInterface;
12+
use Magento\Sales\Api\Data\OrderItemInterface;
1213
use Magento\Sales\Model\Order;
14+
use Magento\Sales\Model\ResourceModel\Order\Item;
1315
use PHPUnit\Framework\Constraint\StringContains;
1416

1517
/**
@@ -28,6 +30,9 @@ class SaveTest extends AbstractInvoiceControllerTest
2830
/** @var Escaper */
2931
private $escaper;
3032

33+
/** @var Item */
34+
private $orderItemResource;
35+
3136
/**
3237
* @inheritdoc
3338
*/
@@ -36,6 +41,7 @@ protected function setUp(): void
3641
parent::setUp();
3742

3843
$this->escaper = $this->_objectManager->get(Escaper::class);
44+
$this->orderItemResource = $this->_objectManager->get(Item::class);
3945
}
4046

4147
/**
@@ -173,6 +179,39 @@ public function testInvoiceWithoutQty(): void
173179
$this->assertErrorResponse($this->escaper->escapeHtml($expectedMessage));
174180
}
175181

182+
/**
183+
* @magentoDataFixture Magento/Sales/_files/order_configurable_product.php
184+
*
185+
* @return void
186+
*/
187+
public function testPartialInvoiceWitConfigurableProduct(): void
188+
{
189+
$order = $this->getOrder('100000001');
190+
$post = $this->hydratePost([$order->getItemsCollection()->getFirstItem()->getId() => '1']);
191+
$this->prepareRequest($post, ['order_id' => $order->getEntityId()]);
192+
$this->dispatch('backend/sales/order_invoice/save');
193+
$this->assertSessionMessages($this->containsEqual((string)__('The invoice has been created.')));
194+
$orderItems = $this->getOrderItemsQtyInvoiced((int)$order->getEntityId());
195+
$this->assertCount(2, $orderItems);
196+
$this->assertEquals($orderItems[0]['qty_invoiced'], $orderItems[1]['qty_invoiced']);
197+
}
198+
199+
/**
200+
* Get order items qty invoiced
201+
*
202+
* @param int $orderId
203+
* @return array
204+
*/
205+
private function getOrderItemsQtyInvoiced(int $orderId): array
206+
{
207+
$connection = $this->orderItemResource->getConnection();
208+
$select = $connection->select()
209+
->from($this->orderItemResource->getMainTable(), OrderItemInterface::QTY_INVOICED)
210+
->where(OrderItemInterface::ORDER_ID . ' = ?', $orderId);
211+
212+
return $connection->fetchAll($select);
213+
}
214+
176215
/**
177216
* @inheritdoc
178217
*/

0 commit comments

Comments
 (0)