You are here

public function InvoiceAdminTest::testInvoiceListing in Commerce Invoice 8.2

Tests the Invoices listing with and without the view.

File

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

Class

InvoiceAdminTest
Tests the invoice admin UI.

Namespace

Drupal\Tests\commerce_invoice\Functional

Code

public function testInvoiceListing() {
  $invoice_collection_route = Url::fromRoute('entity.commerce_invoice.collection');
  $this
    ->drupalGet($invoice_collection_route);
  $this
    ->assertSession()
    ->pageTextContains('There are no invoices yet.');
  $invoice = $this
    ->createEntity('commerce_invoice', [
    'type' => 'default',
    'invoice_number' => $this
      ->randomString(),
    'store_id' => $this->store
      ->id(),
    'orders' => [
      $this->order
        ->id(),
    ],
    'total_price' => new Price('10', 'USD'),
  ]);
  $this
    ->getSession()
    ->reload();
  $this
    ->assertSession()
    ->pageTextNotContains('There are no invoices yet.');
  $this
    ->assertSession()
    ->pageTextContains($invoice
    ->label());
  $this
    ->assertSession()
    ->linkExists('Download');
  $this
    ->assertSession()
    ->linkExists('Pay');

  // Ensure the listing works without the view.
  View::load('commerce_invoices')
    ->delete();
  \Drupal::service('router.builder')
    ->rebuild();
  $this
    ->drupalGet($invoice_collection_route);
  $this
    ->assertSession()
    ->pageTextNotContains('There are no invoices yet.');
  $this
    ->assertSession()
    ->pageTextContains($invoice
    ->label());
  $invoice
    ->delete();
  $this
    ->getSession()
    ->reload();
  $this
    ->assertSession()
    ->pageTextContains('There are no invoices yet.');
}