public function InvoiceSubscriberTest::testPreTransition in Commerce Invoice 8.2
Tests that applying the paid transition sets the invoice total paid.
File
- tests/
src/ Kernel/ InvoiceSubscriberTest.php, line 73
Class
- InvoiceSubscriberTest
- Tests the InvoiceSubscriber.
Namespace
Drupal\Tests\commerce_invoice\KernelCode
public function testPreTransition() {
$invoice_item = InvoiceItem::create([
'type' => 'test',
]);
$invoice_item
->populateFromOrderItem($this->orderItem);
$invoice_item
->save();
$invoice = Invoice::create([
'type' => 'default',
'store_id' => $this->store
->id(),
'invoice_items' => [
$invoice_item,
],
'orders' => [
$this->order,
],
]);
$invoice
->save();
$this
->assertEquals(new Price('12.00', 'USD'), $invoice
->getTotalPrice());
$this
->assertEquals(new Price('0', 'USD'), $invoice
->getTotalPaid());
$this
->assertEquals(new Price('0', 'USD'), $this->order
->getTotalPaid());
$invoice
->getState()
->applyTransitionById('pay');
$invoice
->save();
$this
->assertEquals(new Price('12.00', 'USD'), $invoice
->getTotalPaid());
$this
->assertEquals(new Price('12.00', 'USD'), $this->order
->getTotalPaid());
}