You are here

public function PurchaseOrderTest::testPurchaseOrderCheckout in Commerce Purchase Order 8

Tests anonymous and authenticated checkout.

File

tests/src/Functional/PurchaseOrderTest.php, line 113

Class

PurchaseOrderTest
Tests the checkout of an order.

Namespace

Drupal\Tests\commerce_purchase_order\Functional

Code

public function testPurchaseOrderCheckout() {

  // Anonymous.
  $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
    ->assertCheckoutProgressStep('Login');
  $this
    ->submitForm([], 'Continue as Guest');
  $this
    ->assertCheckoutProgressStep('Order information');
  $this
    ->submitForm([
    'payment_information[add_payment_method][payment_details][number]' => 'a99',
    'contact_information[email]' => 'guest@example.com',
    'contact_information[email_confirm]' => 'guest@example.com',
    'payment_information[add_payment_method][billing_information][address][0][address][given_name]' => 'John',
    'payment_information[add_payment_method][billing_information][address][0][address][family_name]' => 'Smith',
    'payment_information[add_payment_method][billing_information][address][0][address][organization]' => 'Centarro',
    'payment_information[add_payment_method][billing_information][address][0][address][address_line1]' => '9 Drupal Ave',
    'payment_information[add_payment_method][billing_information][address][0][address][postal_code]' => '94043',
    'payment_information[add_payment_method][billing_information][address][0][address][locality]' => 'Mountain View',
    'payment_information[add_payment_method][billing_information][address][0][address][administrative_area]' => 'CA',
  ], 'Continue to review');
  $this
    ->assertCheckoutProgressStep('Review');
  $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');

  // Authenticated.
  $this
    ->drupalLogin($this->adminUser);
  $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()
    ->pageTextContains('Order Summary');
  $this
    ->assertCheckoutProgressStep('Order information');
  $this
    ->submitForm([
    'payment_information[add_payment_method][payment_details][number]' => 'b99',
    'payment_information[add_payment_method][billing_information][address][0][address][given_name]' => 'John',
    'payment_information[add_payment_method][billing_information][address][0][address][family_name]' => 'Smith',
    'payment_information[add_payment_method][billing_information][address][0][address][organization]' => 'Centarro',
    'payment_information[add_payment_method][billing_information][address][0][address][address_line1]' => '9 Drupal Ave',
    'payment_information[add_payment_method][billing_information][address][0][address][postal_code]' => '94043',
    'payment_information[add_payment_method][billing_information][address][0][address][locality]' => 'Mountain View',
    'payment_information[add_payment_method][billing_information][address][0][address][administrative_area]' => 'CA',
  ], 'Continue to review');
  $this
    ->assertCheckoutProgressStep('Review');
  $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 2');
  $this
    ->assertSession()
    ->pageTextContainsOnce('Sample payment instructions.');
  $this
    ->assertSession()
    ->pageTextContains('0 items');
}