You are here

public function InvoiceAdminTest::testInvoiceAddForm in Commerce Invoice 8.2

Tests the invoice add form.

File

tests/src/Functional/InvoiceAdminTest.php, line 239

Class

InvoiceAdminTest
Tests the invoice admin UI.

Namespace

Drupal\Tests\commerce_invoice\Functional

Code

public function testInvoiceAddForm() {
  $assert_session = $this
    ->assertSession();
  $this->order
    ->set('state', 'completed');
  $this->order
    ->save();
  $this
    ->drupalGet($this->orderInvoiceAddUrl);

  // Check that the invoice items were pre-populated with the order items.
  $assert_session
    ->elementsCount('css', 'tr.ief-row-entity', 1);
  $assert_session
    ->elementContains('css', 'td.inline-entity-form-commerce_invoice_item-quantity', '2.00');
  $assert_session
    ->elementContains('css', 'td.inline-entity-form-commerce_invoice_item-unit_price', '$10.00');

  // Check that the invoice adjustments were pre-populated with the order
  // adjustments.
  $assert_session
    ->optionExists('adjustments[0][type]', 'Custom');
  $assert_session
    ->fieldValueEquals('adjustments[0][definition][label]', 'Random fee');
  $assert_session
    ->fieldValueEquals('adjustments[0][definition][amount][number]', '2.00');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Save');
  $assert_session
    ->pageTextContains('The invoice 1 has been successfully saved.');
}