You are here

public function ShipmentAdminTest::testShipmentConfirmationEmail in Commerce Shipping 8.2

Tests shipment confirmation email.

@group debug

File

tests/src/FunctionalJavascript/ShipmentAdminTest.php, line 748

Class

ShipmentAdminTest
Tests the shipment admin UI.

Namespace

Drupal\Tests\commerce_shipping\FunctionalJavascript

Code

public function testShipmentConfirmationEmail() {

  // Enable email confirmation and set bcc address.
  $this
    ->drupalGet('/admin/commerce/config/shipment-types/default/edit');
  $edit = [
    'sendConfirmation' => 1,
    'confirmationBcc' => 'testBcc@shipping.com',
  ];
  $this
    ->submitForm($edit, 'Save');

  // Add Shipment.
  $this
    ->drupalGet($this->shipmentUri);
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->clickLink('Add shipment');
  $page
    ->fillField('title[0][value]', 'Test shipment');
  $page
    ->hasField('shipment_items[1]');
  $page
    ->checkField('shipment_items[1]');
  $page
    ->hasCheckedField('shipment_items[1]');
  $this
    ->assertRenderedAddress($this->defaultAddress, 'shipping_profile[0][profile]');
  $page
    ->pressButton('Recalculate shipping');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->fillField('tracking_code[0][value]', 'A1234567890');
  $page
    ->pressButton('Save');

  // Email is triggered at Send shipment step.
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Finalize shipment');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->pageTextContains('Are you sure you want to apply this transition?');
  $this
    ->assertSession()
    ->pageTextContains('This action cannot be undone.');
  $this
    ->assertSession()
    ->linkExists('Cancel');

  // Note, there is some odd behavior calling the `press()` method on the
  // button, so after asserting it exists, click via this method.
  $this
    ->click('button:contains("Confirm")');
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Send shipment');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->pageTextContains('This action cannot be undone.');
  $this
    ->click('button:contains("Confirm")');

  // Test email content.
  $email = current($this
    ->getMails());
  $this
    ->assertEquals('testBcc@shipping.com', $email['headers']['Bcc']);
  $this
    ->assertEquals("An item for order #{$this->order->getOrderNumber()} shipped!", $email['subject']);
  $this
    ->assertContains('Bryan Centarro', $email['body']);
  $this
    ->assertContains('9 Drupal Ave', $email['body']);
  $this
    ->assertContains('Greenville, SC', $email['body']);
  $this
    ->assertContains('29616', $email['body']);
  $this
    ->assertContains('Tracking information:', $email['body']);
  $this
    ->assertContains('A1234567890', $email['body']);
}