You are here

public function CheckoutAddressbookTest::testCheckout in Drupal Commerce Connector for AvaTax 8

Tests anonymous checkout and inline form expanded.

@covers \Drupal\commerce_avatax\CustomerProfileAlter

File

tests/src/FunctionalJavascript/CheckoutAddressbookTest.php, line 173

Class

CheckoutAddressbookTest
Tests the address.

Namespace

Drupal\Tests\commerce_avatax\FunctionalJavascript

Code

public function testCheckout() {
  $this
    ->drupalLogout();
  $this
    ->drupalGet($this->product
    ->toUrl());
  $this
    ->submitForm([], 'Add to cart');
  $this
    ->assertSession()
    ->pageTextContains('1 item');
  $cart_link = $this
    ->getSession()
    ->getPage()
    ->findLink('your cart');
  $cart_link
    ->click();
  $this
    ->submitForm([], 'Checkout');
  $this
    ->assertSession()
    ->pageTextNotContains('Order Summary');
  $this
    ->submitForm([], 'Continue as Guest');
  $address = [
    'given_name' => 'John',
    'family_name' => 'Smith',
    'address_line1' => '2000 Main Stree',
    'locality' => 'Irvine',
    'administrative_area' => 'CA',
    'postal_code' => '92610',
  ];
  $address_prefix = 'shipping_information[shipping_profile][address][0][address]';
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->fillField('contact_information[email]', 'guest@example.com');
  $page
    ->fillField($address_prefix . '[country_code]', 'US');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  foreach ($address as $property => $value) {
    $page
      ->fillField($address_prefix . '[' . $property . ']', $value);
  }
  $this
    ->assertSession()
    ->waitForText('Shipping method');
  $this
    ->submitForm([], 'Continue to review');
  $this
    ->assertSession()
    ->waitForText('Confirm your shipping address', 45);
  $this
    ->assertSession()
    ->pageTextContains('Use recommended');
  $this
    ->assertSession()
    ->pageTextContains('Your shipping address is different from the post office records. We suggest you accept the recommended address to avoid shipping delays.');
  $this
    ->getSession()
    ->getPage()
    ->findButton('Use recommended')
    ->click();
  $this
    ->assertSession()
    ->waitForText('United States');

  // Validate that new profile is there.
  $this
    ->assertSession()
    ->pageTextNotContains($address['address_line1']);
  $this
    ->assertSession()
    ->pageTextNotContains($address['postal_code']);
  $this
    ->assertSession()
    ->pageTextContains('2000 Main St');
  $this
    ->assertSession()
    ->pageTextContains('92614-7202');
  $this
    ->assertSession()
    ->pageTextContains('Contact information');
  $this
    ->assertSession()
    ->pageTextContains('Payment information');
  $this
    ->assertSession()
    ->pageTextContains('Order Summary');
  $this
    ->submitForm([], 'Pay and complete purchase');
  $this
    ->assertSession()
    ->pageTextContains('Your order number is 1. You can view your order on your account page when logged in.');
  $this
    ->assertSession()
    ->pageTextContains('0 items');

  /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
  $order = Order::load(1);
  $profiles = $order
    ->collectProfiles();
  $shipping = $profiles['shipping'];

  /** @var \Drupal\address\Plugin\Field\FieldType\AddressItem $address */
  $address = $shipping
    ->get('address')
    ->first();
  $this
    ->assert('2000 Main St', $address
    ->getAddressLine1());
  $this
    ->assert('92614-7202', $address
    ->getPostalCode());
}