You are here

public function OrderInvoiceTest::testMailOrderInvoice in Ubercart 8.4

Tests order invoice tab mail invoice.

File

uc_order/tests/src/Functional/OrderInvoiceTest.php, line 128

Class

OrderInvoiceTest
Tests order administration page invoice tab functionality.

Namespace

Drupal\Tests\uc_order\Functional

Code

public function testMailOrderInvoice() {
  $this
    ->drupalLogin($this->adminUser);

  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this
    ->assertSession();

  // Check to make sure the page can be viewed without error.
  $this
    ->drupalGet('admin/store/orders/' . $this->order
    ->id() . '/invoice/mail');
  $assert
    ->statusCodeEquals(200);

  // Check textfield 'email' exists and has customer e-mail filled in.
  $assert
    ->fieldValueEquals('email', $this->order
    ->getEmail());

  // Check button 'Mail invoice' exists and press it - this will send an
  // email using the test_html_mail_collector so we can examine it later.
  $assert
    ->buttonExists('Mail invoice')
    ->press();

  // Examine the collected email and check some of the contents.
  $this
    ->assertMailString('subject', 'Your Order Invoice', 1, 'Order invoice was sent via email');
  $this
    ->assertMailString('body', '<b>Billing Address:</b><br />', 1, 'Markup found in invoice mail.');

  // Make sure the logo image uses an absolute URL.
  // @see https://www.drupal.org/project/drupal/issues/2704597
  $uri = theme_get_setting('logo.url');
  $expected = Url::fromUserInput($uri, [
    'absolute' => TRUE,
  ])
    ->toString();
  $this
    ->assertMailString('body', $expected, 1, 'Logo image has absolute URL.');
}