You are here

public function InvoiceAdminTest::testPayInvoiceOperation in Commerce Invoice 8.2

Tests the "Pay invoice" operation.

File

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

Class

InvoiceAdminTest
Tests the invoice admin UI.

Namespace

Drupal\Tests\commerce_invoice\Functional

Code

public function testPayInvoiceOperation() {
  $invoice_item = $this
    ->createEntity('commerce_invoice_item', [
    'type' => 'commerce_product_variation',
    'unit_price' => new Price('10', 'USD'),
    'quantity' => 1,
  ]);
  $invoice = $this
    ->createEntity('commerce_invoice', [
    'type' => 'default',
    'invoice_number' => $this
      ->randomString(),
    'invoice_items' => $invoice_item,
    'store_id' => $this->store
      ->id(),
    'orders' => [
      $this->order
        ->id(),
    ],
    'total_paid' => new Price('10', 'USD'),
  ]);
  $payment_form_url = $invoice
    ->toUrl('payment-form')
    ->toString();

  // Ensure the "Pay invoice" operation is not shown for a paid invoice.
  $this
    ->drupalGet($this->collectionUrl);
  $this
    ->assertSession()
    ->linkByHrefNotExists($payment_form_url);
  $invoice
    ->setTotalPaid(new Price(0, 'USD'));
  $invoice
    ->save();
  $this
    ->getSession()
    ->reload();
  $this
    ->assertSession()
    ->linkByHrefExists($payment_form_url);
  $this
    ->drupalGet($payment_form_url);
  $this
    ->assertSession()
    ->buttonExists(t('Pay'));
  $this
    ->assertSession()
    ->linkExists('Cancel');
  $this
    ->submitForm([], t('Pay'));
  $this
    ->getSession()
    ->reload();
  $this
    ->assertSession()
    ->linkByHrefNotExists($payment_form_url);
}