You are here

function PaymentCommerceCheckoutWebTestCase::assertCheckout in Payment for Drupal Commerce 7

Same name and namespace in other branches
  1. 7.2 tests/PaymentCommerceCheckoutWebTestCase.test \PaymentCommerceCheckoutWebTestCase::assertCheckout()

Executes the checkout process.

_unavailable

Parameters

integer $product_id:

integer $uid:

integer $pmid:

2 calls to PaymentCommerceCheckoutWebTestCase::assertCheckout()
PaymentCommerceCheckoutWebTestCase::testCheckoutFailed in tests/PaymentCommerceCheckoutWebTestCase.test
Tests the checkout process for a failed payment.
PaymentCommerceCheckoutWebTestCase::testCheckoutSuccess in tests/PaymentCommerceCheckoutWebTestCase.test
Tests the checkout process for a successful payment.

File

tests/PaymentCommerceCheckoutWebTestCase.test, line 128

Class

PaymentCommerceCheckoutWebTestCase

Code

function assertCheckout($product_id, $uid, $pmid, $pmid_unavailable) {
  $previous_order_id = $this
    ->getLastOrderID();

  // Execute the checkout.
  $product = commerce_product_load($product_id);
  $line_item = commerce_product_line_item_new($product);
  $line_item = commerce_cart_product_add($uid, $line_item);
  $values = array(
    'customer_profile_billing[commerce_customer_address][und][0][name_line]' => 'foo',
    'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => 'bar',
    'customer_profile_billing[commerce_customer_address][und][0][locality]' => 'baz',
  );
  $this
    ->drupalPost('checkout', $values, t('Continue to next step'));

  // Confirm that payment methods that do not validate the payment are not
  // available.
  $this
    ->assertNoFieldByXPath("//input[@name='commerce_payment[payment_method]' and @value='payment_commerce_" . $pmid_unavailable . "|commerce_payment_payment_commerce_" . $pmid_unavailable . "']");
  $values = array(
    'commerce_payment[payment_method]' => 'payment_commerce_' . $pmid . '|commerce_payment_payment_commerce_' . $pmid,
    'commerce_payment[payment_details][payment_commerce][field_foo][und][0][value]' => 'bar',
  );
  $this
    ->drupalPost(NULL, $values, t('Continue to next step'));
  $this
    ->drupalPost(NULL, $values, t('Continue to next step'));

  // Confirm the new order.
  $new_order_id = $this
    ->getLastOrderID();
  $this
    ->assertNotEqual($previous_order_id, $new_order_id);
  $pids = payment_commerce_pids_load($new_order_id);
  if ($this
    ->assertTrue($pids)) {
    $payment = entity_load_single('payment', reset($pids));
    $this
      ->assertTrue((bool) $payment);
    if ($payment) {

      // Check the payment status.
      $this
        ->assertEqual($payment
        ->getStatus()->status, $payment->method->controller_data['status']);

      // Check that the Commerce Payment transaction has an instance ID.
      $transaction_id = payment_commerce_transaction_id_load($payment->pid);
      $transaction = commerce_payment_transaction_load($transaction_id);
      $this
        ->assertTrue($transaction->instance_id);
      $this
        ->assertNotIdentical(strpos($transaction->instance_id, '|'), FALSE);
    }
    $order = commerce_order_load($new_order_id);
    $this
      ->assertEqual($payment->uid, $order->uid);
    $this
      ->assertEqual($payment->field_foo['und'][0]['value'], 'bar');
  }
}