public function OrderIntegrationTest::testPlace in Commerce Invoice 8.2
Tests that an invoice is generated when an order is placed.
File
- tests/
src/ Kernel/ OrderIntegrationTest.php, line 101
Class
- OrderIntegrationTest
- Tests integration with order events.
Namespace
Drupal\Tests\commerce_invoice\KernelCode
public function testPlace() {
// Ensure that no invoice is generated when the automatic invoice generation
// is turned off for this order type.
$this->order
->getState()
->applyTransitionById('place');
$this->order
->save();
$invoices = $this->invoiceStorage
->loadMultiple();
$this
->assertEquals(0, count($invoices));
$order_type = OrderType::load('default');
$order_type
->setThirdPartySetting('commerce_invoice', 'invoice_type', 'default');
$order_type
->setThirdPartySetting('commerce_invoice', 'order_placed_generation', TRUE);
$order_type
->save();
$this->order = $this
->reloadEntity($this->order);
$this->order
->set('state', 'draft');
$this->order
->setRefreshState(OrderInterface::REFRESH_SKIP);
$this->order
->save();
$this->order
->getState()
->applyTransitionById('place');
$this->order
->save();
$this->order = $this
->reloadEntity($this->order);
$invoices = $this->invoiceStorage
->loadMultiple();
$this
->assertEquals(1, count($invoices));
/** @var \Drupal\commerce_invoice\Entity\InvoiceInterface $invoice */
$invoice = reset($invoices);
$invoice_billing_profile = $invoice
->getBillingProfile();
$this
->assertNotEmpty($invoice
->getBillingProfile());
$this
->assertTrue($invoice_billing_profile
->equalToProfile($this->order
->getBillingProfile()));
$this
->assertEquals($this->order
->getCustomerId(), $invoice
->getCustomerId());
$this
->assertEquals([
$this->order,
], $invoice
->getOrders());
$this
->assertEquals($this->store, $invoice
->getStore());
$this
->assertEquals($this->order
->getTotalPrice(), $invoice
->getTotalPrice());
$this
->assertCount(1, $invoice
->getItems());
$this
->assertCount(0, $invoice
->getAdjustments());
}