You are here

class UbercartCartCheckoutTestCase in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 uc_cart/uc_cart.test \UbercartCartCheckoutTestCase

Tests the cart and checkout functionality.

Hierarchy

Expanded class hierarchy of UbercartCartCheckoutTestCase

File

uc_cart/tests/uc_cart.test, line 11
Shopping cart and checkout tests.

View source
class UbercartCartCheckoutTestCase extends UbercartTestHelper {
  public static function getInfo() {
    return array(
      'name' => 'Cart and checkout',
      'description' => 'Ensures the cart and checkout process is functioning for both anonymous and authenticated users.',
      'group' => 'Ubercart',
    );
  }

  /**
   * Overrides DrupalWebTestCase::setUp().
   */
  protected function setUp($modules = array(), $permissions = array()) {
    $modules = array(
      'uc_payment',
      'uc_payment_pack',
      'uc_roles',
    );
    $permissions = array(
      'administer permissions',
    );
    parent::setUp($modules, $permissions);
  }

  /**
   * Creates a new order.
   */
  protected function createOrder($fields = array()) {
    $order = uc_order_new();
    foreach ($fields as $key => $value) {
      $order->{$key} = $value;
    }
    if (empty($order->primary_email)) {
      $order->primary_email = $this
        ->randomString() . '@example.org';
    }
    if (!isset($fields['products'])) {
      $item = clone $this->product;
      $item->qty = 1;
      $item->price = $item->sell_price;
      $item->data = array();
      $order->products = array(
        $item,
      );
    }
    $order->order_total = uc_order_get_total($order, TRUE);
    $order->line_items = uc_order_load_line_items($order, TRUE);
    uc_order_save($order);
    return $order;
  }

  /**
   * Tests cart API.
   */
  public function testCartApi() {

    // Test the empty cart.
    $items = uc_cart_get_contents();
    $this
      ->assertEqual($items, array(), 'Cart is an empty array.');

    // Add an item to the cart.
    uc_cart_add_item($this->product->nid);
    $items = uc_cart_get_contents();
    $this
      ->assertEqual(count($items), 1, 'Cart contains one item.');
    $item = reset($items);
    $this
      ->assertEqual($item->nid, $this->product->nid, 'Cart item nid is correct.');
    $this
      ->assertEqual($item->qty, 1, 'Cart item quantity is correct.');

    // Add more of the same item.
    $qty = mt_rand(1, 100);
    uc_cart_add_item($this->product->nid, $qty);
    $items = uc_cart_get_contents();
    $this
      ->assertEqual(count($items), 1, 'Updated cart contains one item.');
    $item = reset($items);
    $this
      ->assertEqual($item->qty, $qty + 1, 'Updated cart item quantity is correct.');

    // Set the quantity and data.
    $qty = mt_rand(1, 100);
    $item->qty = $qty;
    $item->data['updated'] = TRUE;
    uc_cart_update_item($item);
    $items = uc_cart_get_contents();
    $item = reset($items);
    $this
      ->assertEqual($item->qty, $qty, 'Set cart item quantity is correct.');
    $this
      ->assertTrue($item->data['updated'], 'Set cart item data is correct.');

    // Add an item with different data to the cart.
    uc_cart_add_item($this->product->nid, 1, array(
      'test' => TRUE,
    ));
    $items = uc_cart_get_contents();
    $this
      ->assertEqual(count($items), 2, 'Updated cart contains two items.');

    // Remove the items.
    foreach ($items as $item) {
      uc_cart_remove_item($item->nid, NULL, $item->data);
    }

    // @todo Remove the need for this.
    uc_cart_get_contents(NULL, 'rebuild');
    $items = uc_cart_get_contents();
    $this
      ->assertEqual(count($items), 0, 'Cart is empty after removal.');

    // Empty the cart.
    uc_cart_add_item($this->product->nid);
    uc_cart_empty();
    $items = uc_cart_get_contents();
    $this
      ->assertEqual($items, array(), 'Cart is emptied correctly.');
  }

  /**
   * Tests basic cart functionality.
   */
  public function testCart() {
    module_enable(array(
      'uc_cart_entity_test',
    ));

    // Test the empty cart.
    $this
      ->drupalGet('cart');
    $this
      ->assertText('There are no products in your shopping cart.');

    // Add an item to the cart.
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    $this
      ->assertText($this->product->title . ' added to your shopping cart.');
    $this
      ->assertText('hook_uc_cart_item_insert fired');

    // Test the cart page.
    $this
      ->drupalGet('cart');
    $this
      ->assertText($this->product->title, t('The product is in the cart.'));
    $this
      ->assertFieldByName('items[0][qty]', 1, t('The product quantity is 1.'));

    // Add the item again.
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    $this
      ->assertText('Your item(s) have been updated.');
    $this
      ->assertText('hook_uc_cart_item_update fired');

    // Test the cart page again.
    $this
      ->drupalGet('cart');
    $this
      ->assertFieldByName('items[0][qty]', 2, t('The product quantity is 2.'));

    // Update the quantity.
    $qty = mt_rand(3, 100);
    $this
      ->drupalPost('cart', array(
      'items[0][qty]' => $qty,
    ), t('Update cart'));
    $this
      ->assertText('Your cart has been updated.');
    $this
      ->assertFieldByName('items[0][qty]', $qty, t('The product quantity was updated.'));
    $this
      ->assertText('hook_uc_cart_item_update fired');

    // Update the quantity to zero.
    $this
      ->drupalPost('cart', array(
      'items[0][qty]' => 0,
    ), t('Update cart'));
    $this
      ->assertText('Your cart has been updated.');
    $this
      ->assertText('There are no products in your shopping cart.');
    $this
      ->assertText('hook_uc_cart_item_delete fired');

    // Test the remove item button.
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    $this
      ->drupalPost('cart', array(), t('Remove'));
    $this
      ->assertText($this->product->title . ' removed from your shopping cart.');
    $this
      ->assertText('There are no products in your shopping cart.');
    $this
      ->assertText('hook_uc_cart_item_delete fired');
  }

  /**
   * Tests that anonymous cart is merged into authenticated cart upon login.
   */
  public function testCartMerge() {

    // Add an item to the cart as an anonymous user.
    $this
      ->drupalLogin($this->customer);
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    $this
      ->assertText($this->product->title . ' added to your shopping cart.');
    $this
      ->drupalLogout();

    // Add an item to the cart as an anonymous user.
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    $this
      ->assertText($this->product->title . ' added to your shopping cart.');

    // Log in and check the items are merged.
    $this
      ->drupalLogin($this->customer);
    $this
      ->drupalGet('cart');
    $this
      ->assertText($this->product->title, t('The product remains in the cart after logging in.'));
    $this
      ->assertFieldByName('items[0][qty]', 2, t('The product quantity is 2.'));
  }

  /**
   * Tests that cart automatically removes products that have been deleted.
   */
  public function testDeletedCartItem() {

    // Add a product to the cart, then delete the node.
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    node_delete($this->product->nid);

    // Test that the cart is empty.
    $this
      ->drupalGet('cart');
    $this
      ->assertText('There are no products in your shopping cart.');
    $this
      ->assertEqual(uc_cart_get_total_qty(), 0, 'There are no items in the cart.');
  }

  /**
   * Tests Rule integration for uc_cart_maximum_product_qty reaction rule.
   */
  public function testMaximumQuantityRule() {

    // Enable the example maximum quantity rule.
    $rule = rules_config_load('uc_cart_maximum_product_qty');
    $rule->active = TRUE;
    $rule
      ->save();

    // Try to add more items than allowed to the cart.
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    $this
      ->drupalPost('cart', array(
      'items[0][qty]' => 11,
    ), t('Update cart'));

    // Test the restriction was applied.
    $this
      ->assertText('You are only allowed to order a maximum of 10 of ' . $this->product->title . '.');
    $this
      ->assertFieldByName('items[0][qty]', 10);
  }

  /**
   * Tests the checkout process.
   */
  public function testCheckout() {

    // Allow customer to specify username and password,
    // but don't log in after checkout.
    $settings = array(
      'uc_cart_new_account_name' => TRUE,
      'uc_cart_new_account_password' => TRUE,
      'uc_new_customer_login' => FALSE,
    );
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->drupalPost('admin/store/settings/checkout', $settings, t('Save configuration'));
    $this
      ->drupalLogout();
    $new_user = new stdClass();
    $new_user->name = $this
      ->randomName(20);
    $new_user->pass_raw = $this
      ->randomName(20);

    // Test as anonymous user.
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    $this
      ->checkout(array(
      'panes[customer][new_account][name]' => $new_user->name,
      'panes[customer][new_account][pass]' => $new_user->pass_raw,
      'panes[customer][new_account][pass_confirm]' => $new_user->pass_raw,
    ));
    $this
      ->assertRaw('Your order is complete!');
    $this
      ->assertText($new_user->name, 'Username is shown on screen.');
    $this
      ->assertNoText($new_user->pass_raw, 'Password is not shown on screen.');

    // Check that cart is now empty.
    $this
      ->drupalGet('cart');
    $this
      ->assertText('There are no products in your shopping cart.');

    // Test new account email.
    $mail = $this
      ->drupalGetMails(array(
      'id' => 'user_register_no_approval_required',
    ));
    $mail = array_pop($mail);
    $this
      ->assertTrue(strpos($mail['body'], $new_user->name) !== FALSE, 'Mail body contains username.');

    // Test invoice email.
    $mail = $this
      ->drupalGetMails(array(
      'subject' => 'Your Order at Ubercart',
    ));
    $mail = array_pop($mail);
    $this
      ->assertTrue(strpos($mail['body'], $new_user->name) !== FALSE, 'Invoice body contains username.');
    $this
      ->assertFalse(strpos($mail['body'], $new_user->pass_raw) !== FALSE, 'Mail body does not contain password.');

    // Check that the password works.
    $this
      ->drupalLogout();
    $this
      ->drupalLogin($new_user);

    // Test again as authenticated user.
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    $this
      ->checkout();
    $this
      ->assertRaw('Your order is complete!');
    $this
      ->assertRaw('While logged in');

    // Test again with generated username and password.
    $this
      ->drupalLogout();
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    $this
      ->checkout();
    $this
      ->assertRaw('Your order is complete!');

    // Test new account email.
    $mail = $this
      ->drupalGetMails(array(
      'id' => 'user_register_no_approval_required',
    ));
    $mail = array_pop($mail);
    $new_user = new stdClass();
    $new_user->name = $mail['params']['account']->name;
    $new_user->pass_raw = $mail['params']['account']->password;
    $this
      ->assertTrue(!empty($new_user->name), 'New username is not empty.');
    $this
      ->assertTrue(!empty($new_user->pass_raw), 'New password is not empty.');
    $this
      ->assertTrue(strpos($mail['body'], $new_user->name) !== FALSE, 'Mail body contains username.');

    // Test invoice email.
    $mail = $this
      ->drupalGetMails(array(
      'subject' => 'Your Order at Ubercart',
    ));
    $mail = array_pop($mail);
    $this
      ->assertTrue(strpos($mail['body'], $new_user->name) !== FALSE, 'Invoice body contains username.');
    $this
      ->assertTrue(strpos($mail['body'], $new_user->pass_raw) !== FALSE, 'Invoice body contains password.');

    // We can check the password now we know it.
    $this
      ->assertText($new_user->name, 'Username is shown on screen.');
    $this
      ->assertText($new_user->pass_raw, 'Password is shown on screen.');

    // Check that the password works.
    $this
      ->drupalLogout();
    $this
      ->drupalLogin($new_user);

    // Test again with an existing email address.
    $this
      ->drupalLogout();
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    $this
      ->checkout(array(
      'panes[customer][primary_email]' => $this->customer->mail,
    ));
    $this
      ->assertRaw('Your order is complete!');
    $this
      ->assertRaw('order has been attached to the account we found');
  }

  /**
   * Tests generating a new account at checkout.
   */
  public function testCheckoutNewUsername() {

    // Configure the checkout for this test.
    $this
      ->drupalLogin($this->adminUser);
    $settings = array(
      // Allow customer to specify username.
      'uc_cart_new_account_name' => TRUE,
      // Disable address panes.
      'uc_pane_delivery_enabled' => FALSE,
      'uc_pane_billing_enabled' => FALSE,
    );
    $this
      ->drupalPost('admin/store/settings/checkout/panes', $settings, t('Save configuration'));
    $this
      ->drupalLogout();

    // Test with an account that already exists.
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    $edit = array(
      'panes[customer][primary_email]' => $this
        ->randomName(8) . '@example.com',
      'panes[customer][new_account][name]' => $this->adminUser->name,
    );
    $this
      ->drupalPost('cart/checkout', $edit, 'Review order');
    $this
      ->assertText('The username ' . $this->adminUser->name . ' is already taken.');

    // Let the account be automatically created instead.
    $edit = array(
      'panes[customer][primary_email]' => $this
        ->randomName(8) . '@example.com',
      'panes[customer][new_account][name]' => '',
    );
    $this
      ->drupalPost('cart/checkout', $edit, 'Review order');
    $this
      ->drupalPost(NULL, array(), 'Submit order');
    $this
      ->assertText('Your order is complete!');
    $this
      ->assertText('A new account has been created');
  }

  /**
   * Tests blocked user checkout.
   */
  public function testCheckoutBlockedUser() {

    // Block user after checkout.
    $settings = array(
      'uc_new_customer_status_active' => FALSE,
    );
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->drupalPost('admin/store/settings/checkout', $settings, t('Save configuration'));
    $this
      ->drupalLogout();

    // Test as anonymous user.
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    $this
      ->checkout();
    $this
      ->assertRaw('Your order is complete!');

    // Test new account email.
    $mail = $this
      ->drupalGetMails(array(
      'id' => 'user_register_pending_approval',
    ));
    $this
      ->assertTrue(!empty($mail), 'Blocked user email found.');
    $mail = $this
      ->drupalGetMails(array(
      'id' => 'user_register_no_approval_required',
    ));
    $this
      ->assertTrue(empty($mail), 'No unblocked user email found.');
  }

  /**
   * Tests logging in the customer after checkout.
   */
  public function testCheckoutLogin() {

    // Log in after checkout.
    variable_set('uc_new_customer_login', TRUE);

    // Test checkout.
    $this
      ->drupalGet('node/' . $this->product->nid);
    $this
      ->drupalPost(NULL, array(), t('Add to cart'));
    $this
      ->assertNotNull($this->session_id, 'Session ID is set.');
    $session_id = $this->session_id;
    $this
      ->checkout();
    $this
      ->assertRaw('Your order is complete!');
    $this
      ->assertRaw('you are already logged in');

    // Confirm login.
    $this
      ->assertNotNull($this->session_id, 'Session ID is set.');
    $this
      ->assertNotIdentical($this->session_id, $session_id, 'Session ID has changed.');
    $this
      ->drupalGet('<front>');
    $this
      ->assertText('My account', 'User is logged in.');

    // Check that cart is now empty.
    $this
      ->drupalGet('cart');
    $this
      ->assertText('There are no products in your shopping cart.');
  }

  /**
   * Tests checkout complete functioning.
   */
  public function testCheckoutComplete() {

    // Payment notification is received first.
    $order_data = array(
      'primary_email' => 'simpletest@ubercart.org',
    );
    $order = $this
      ->createOrder($order_data);
    uc_payment_enter($order->order_id, 'SimpleTest', $order->order_total);
    $output = uc_cart_complete_sale($order);

    // Check that a new account was created.
    $this
      ->assertTrue(strpos($output['#message'], 'new account has been created') !== FALSE, 'Checkout message mentions new account.');

    // 2 e-mails: new account, customer invoice.
    $mails = $this
      ->drupalGetMails();
    $this
      ->assertEqual(count($mails), 2, '2 e-mails were sent.');
    variable_del('drupal_test_email_collector');
    $password = $mails[0]['params']['account']->password;
    $this
      ->assertTrue(!empty($password), 'New password is not empty.');

    // In D7, new account emails do not contain the password.

    //$this->assertTrue(strpos($mails[0]['body'], $password) !== FALSE, 'Mail body contains password.');

    // Different user, sees the checkout page first.
    $order_data = array(
      'primary_email' => 'simpletest2@ubercart.org',
    );
    $order = $this
      ->createOrder($order_data);
    $output = uc_cart_complete_sale($order, TRUE);
    uc_payment_enter($order->order_id, 'SimpleTest', $order->order_total);

    // 2 e-mails: new account, customer invoice.
    $mails = $this
      ->drupalGetMails();
    $this
      ->assertEqual(count($mails), 2, '2 e-mails were sent.');
    variable_del('drupal_test_email_collector');
    $password = $mails[0]['params']['account']->password;
    $this
      ->assertTrue(!empty($password), 'New password is not empty.');

    // In D7, new account emails do not contain the password.

    //$this->assertTrue(strpos($mails[0]['body'], $password) !== FALSE, 'Mail body contains password.');

    // Same user, new order.
    $order = $this
      ->createOrder($order_data);
    $output = uc_cart_complete_sale($order, TRUE);
    uc_payment_enter($order->order_id, 'SimpleTest', $order->order_total);

    // Check that no new account was created.
    $this
      ->assertTrue(strpos($output['#message'], 'order has been attached to the account') !== FALSE, 'Checkout message mentions existing account.');

    // 1 e-mail: customer invoice.
    $mails = $this
      ->drupalGetMails();
    $this
      ->assertEqual(count($mails), 1, '1 e-mail was sent.');
    variable_del('drupal_test_email_collector');
  }
  public function testCheckoutRoleAssignment() {

    // Add role assignment to the test product.
    $rid = $this
      ->drupalCreateRole(array(
      'access content',
    ));
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->drupalPost('node/' . $this->product->nid . '/edit/features', array(
      'feature' => 'role',
    ), t('Add'));
    $this
      ->drupalPost(NULL, array(
      'uc_roles_role' => $rid,
    ), t('Save feature'));

    // Process an anonymous, shippable order.
    $item = clone $this->product;
    $item->qty = 1;
    $item->price = $item->sell_price;
    $item->data = array(
      'shippable' => TRUE,
    );
    $order = $this
      ->createOrder(array(
      'products' => array(
        $item,
      ),
    ));
    uc_payment_enter($order->order_id, 'SimpleTest', $order->order_total);

    // Find the order uid.
    $uid = db_query("SELECT uid FROM {uc_orders} ORDER BY order_id DESC")
      ->fetchField();
    $account = user_load($uid);
    $this
      ->assertTrue(isset($account->roles[$rid]), 'New user was granted role.');
    $order = uc_order_load($order->order_id);
    $this
      ->assertEqual($order->order_status, 'payment_received', 'Shippable order was set to payment received.');

    // 3 e-mails: new account, customer invoice, role assignment.
    $mails = $this
      ->drupalGetMails();
    $this
      ->assertEqual(count($mails), 3, '3 e-mails were sent.');
    variable_del('drupal_test_email_collector');

    // Test again with an existing email address and a non-shippable order.
    $item->data = array(
      'shippable' => FALSE,
    );
    $order = $this
      ->createOrder(array(
      'primary_email' => $this->customer->mail,
      'products' => array(
        $item,
      ),
    ));
    uc_payment_enter($order->order_id, 'SimpleTest', $order->order_total);
    $account = user_load($this->customer->uid);
    $this
      ->assertTrue(isset($account->roles[$rid]), 'Existing user was granted role.');
    $order = uc_order_load($order->order_id);
    $this
      ->assertEqual($order->order_status, 'completed', 'Non-shippable order was set to completed.');

    // 2 e-mails: customer invoice, role assignment.
    $mails = $this
      ->drupalGetMails();
    $this
      ->assertEqual(count($mails), 2, '2 e-mails were sent.');
    variable_del('drupal_test_email_collector');
  }

  /**
   * Tests that cart orders are marked abandoned after a timeout.
   */
  public function testCartOrderTimeout() {
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    $this
      ->drupalPost('cart', array(), 'Checkout');
    $this
      ->assertText(t('Enter your billing address and information here.'), t('Viewed cart page: Billing pane has been displayed.'));

    // Build the panes.
    $zone_id = db_query_range('SELECT zone_id FROM {uc_zones} WHERE zone_country_id = :country ORDER BY rand()', 0, 1, array(
      'country' => variable_get('uc_store_country', 840),
    ))
      ->fetchField();
    $oldname = $this
      ->randomName(10);
    $edit = array(
      'panes[delivery][delivery_first_name]' => $oldname,
      'panes[delivery][delivery_last_name]' => $this
        ->randomName(10),
      'panes[delivery][delivery_street1]' => $this
        ->randomName(10),
      'panes[delivery][delivery_city]' => $this
        ->randomName(10),
      'panes[delivery][delivery_zone]' => $zone_id,
      'panes[delivery][delivery_postal_code]' => mt_rand(10000, 99999),
      'panes[billing][billing_first_name]' => $this
        ->randomName(10),
      'panes[billing][billing_last_name]' => $this
        ->randomName(10),
      'panes[billing][billing_street1]' => $this
        ->randomName(10),
      'panes[billing][billing_city]' => $this
        ->randomName(10),
      'panes[billing][billing_zone]' => $zone_id,
      'panes[billing][billing_postal_code]' => mt_rand(10000, 99999),
    );

    // If the email address has not been set, and the user has not logged in,
    // add a primary email address.
    if (!isset($edit['panes[customer][primary_email]']) && !$this->loggedInUser) {
      $edit['panes[customer][primary_email]'] = $this
        ->randomName(8) . '@example.com';
    }

    // Submit the checkout page.
    $this
      ->drupalPost('cart/checkout', $edit, t('Review order'));
    $order_id = db_query("SELECT order_id FROM {uc_orders} WHERE delivery_first_name = :name", array(
      ':name' => $oldname,
    ))
      ->fetchField();
    if ($order_id) {

      // Go to a different page, then back to order to make sure
      // order_id is the same.
      $this
        ->drupalGet('<front>');
      $this
        ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
      $this
        ->drupalPost('cart', array(), 'Checkout');
      $this
        ->assertRaw($oldname, 'Customer name was unchanged.');
      $this
        ->drupalPost('cart/checkout', $edit, t('Review order'));
      $new_order_id = db_query("SELECT order_id FROM {uc_orders} WHERE delivery_first_name = :name", array(
        ':name' => $edit['panes[delivery][delivery_first_name]'],
      ))
        ->fetchField();
      $this
        ->assertEqual($order_id, $new_order_id, 'Original order_id was reused.');

      // Jump 10 minutes into the future.
      db_update('uc_orders')
        ->fields(array(
        'modified' => time() - UC_CART_ORDER_TIMEOUT - 1,
      ))
        ->condition('order_id', $order_id)
        ->execute();
      $old_order = uc_order_load($order_id);

      // Go to a different page, then back to order to verify that we are
      // using a new order.
      $this
        ->drupalGet('<front>');
      $this
        ->drupalPost('cart', array(), 'Checkout');
      $this
        ->assertNoRaw($oldname, 'Customer name was cleared after timeout.');
      $newname = $this
        ->randomName(10);
      $edit['panes[delivery][delivery_first_name]'] = $newname;
      $this
        ->drupalPost('cart/checkout', $edit, t('Review order'));
      $new_order_id = db_query("SELECT order_id FROM {uc_orders} WHERE delivery_first_name = :name", array(
        ':name' => $newname,
      ))
        ->fetchField();
      $this
        ->assertNotEqual($order_id, $new_order_id, 'New order was created after timeout.');

      // Verify that the status of old order is abandoned.
      $old_order = uc_order_load($order_id, TRUE);
      $this
        ->assertEqual($old_order->order_status, 'abandoned', 'Original order was marked abandoned.');
    }
    else {
      $this
        ->fail('No order was created.');
    }
  }

  /**
   * Tests functioning of customer information pane on checkout page.
   */
  public function testCustomerInformationCheckoutPane() {

    // Log in as a customer and add an item to the cart.
    $this
      ->drupalLogin($this->customer);
    $this
      ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
    $this
      ->drupalPost('cart', array(), 'Checkout');

    // Test the customer information pane.
    $mail = $this->customer->mail;
    $this
      ->assertText('Customer information');
    $this
      ->assertText('Order information will be sent to your account e-mail listed below.');
    $this
      ->assertText('E-mail address: ' . $mail);

    // Use the 'edit' link to change the email address on the account.
    $new_mail = $this
      ->randomName() . '@example.com';
    $this
      ->clickLink('edit');
    $data = array(
      'current_pass' => $this->customer->pass_raw,
      'mail' => $new_mail,
    );
    $this
      ->drupalPost(NULL, $data, 'Save');

    // Test the updated email address.
    $this
      ->assertText('Order information will be sent to your account e-mail listed below.');
    $this
      ->assertNoText('E-mail address: ' . $mail);
    $this
      ->assertText('E-mail address: ' . $new_mail);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalWebTestCase::$additionalCurlOptions protected property Additional cURL options.
DrupalWebTestCase::$content protected property The content of the page currently loaded in the internal browser.
DrupalWebTestCase::$cookieFile protected property The current cookie file used by cURL.
DrupalWebTestCase::$cookies protected property The cookies of the page currently loaded in the internal browser.
DrupalWebTestCase::$curlHandle protected property The handle of the current cURL connection.
DrupalWebTestCase::$drupalSettings protected property The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser.
DrupalWebTestCase::$elements protected property The parsed version of the page.
DrupalWebTestCase::$generatedTestFiles protected property Whether the files were copied to the test files directory.
DrupalWebTestCase::$headers protected property The headers of the page currently loaded in the internal browser.
DrupalWebTestCase::$httpauth_credentials protected property HTTP authentication credentials (<username>:<password>).
DrupalWebTestCase::$httpauth_method protected property HTTP authentication method
DrupalWebTestCase::$loggedInUser protected property The current user logged in using the internal browser.
DrupalWebTestCase::$originalShutdownCallbacks protected property The original shutdown handlers array, before it was cleaned for testing purposes.
DrupalWebTestCase::$originalUser protected property The original user, before it was changed to a clean uid = 1 for testing purposes.
DrupalWebTestCase::$plainTextContent protected property The content of the page currently loaded in the internal browser (plain text version).
DrupalWebTestCase::$profile protected property The profile to install as a basis for testing. 20
DrupalWebTestCase::$redirect_count protected property The number of redirects followed during the handling of a request.
DrupalWebTestCase::$session_id protected property The current session ID, if available.
DrupalWebTestCase::$session_name protected property The current session name, if available.
DrupalWebTestCase::$url protected property The URL currently loaded in the internal browser.
DrupalWebTestCase::assertField protected function Asserts that a field exists with the given name or ID.
DrupalWebTestCase::assertFieldById protected function Asserts that a field exists in the current page with the given ID and value.
DrupalWebTestCase::assertFieldByName protected function Asserts that a field exists in the current page with the given name and value.
DrupalWebTestCase::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
DrupalWebTestCase::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
DrupalWebTestCase::assertLink protected function Pass if a link with the specified label is found, and optional with the specified index.
DrupalWebTestCase::assertLinkByHref protected function Pass if a link containing a given href (part) is found.
DrupalWebTestCase::assertMail protected function Asserts that the most recently sent e-mail message has the given value.
DrupalWebTestCase::assertMailPattern protected function Asserts that the most recently sent e-mail message has the pattern in it.
DrupalWebTestCase::assertMailString protected function Asserts that the most recently sent e-mail message has the string in it.
DrupalWebTestCase::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
DrupalWebTestCase::assertNoField protected function Asserts that a field does not exist with the given name or ID.
DrupalWebTestCase::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
DrupalWebTestCase::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
DrupalWebTestCase::assertNoFieldByXPath protected function Asserts that a field doesn't exist or its value doesn't match, by XPath.
DrupalWebTestCase::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
DrupalWebTestCase::assertNoLink protected function Pass if a link with the specified label is not found.
DrupalWebTestCase::assertNoLinkByHref protected function Pass if a link containing a given href (part) is not found.
DrupalWebTestCase::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
DrupalWebTestCase::assertNoPattern protected function Will trigger a pass if the perl regex pattern is not present in raw content.
DrupalWebTestCase::assertNoRaw protected function Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertNoResponse protected function Asserts the page did not return the specified response code.
DrupalWebTestCase::assertNoText protected function Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertNoTitle protected function Pass if the page title is not the given string.
DrupalWebTestCase::assertNoUniqueText protected function Pass if the text is found MORE THAN ONCE on the text version of the page.
DrupalWebTestCase::assertOptionSelected protected function Asserts that a select option in the current page is checked.
DrupalWebTestCase::assertPattern protected function Will trigger a pass if the Perl regex pattern is found in the raw content.
DrupalWebTestCase::assertRaw protected function Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertResponse protected function Asserts the page responds with the specified response code.
DrupalWebTestCase::assertText protected function Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertTextHelper protected function Helper for assertText and assertNoText.
DrupalWebTestCase::assertThemeOutput protected function Asserts themed output.
DrupalWebTestCase::assertTitle protected function Pass if the page title is the given string.
DrupalWebTestCase::assertUniqueText protected function Pass if the text is found ONLY ONCE on the text version of the page.
DrupalWebTestCase::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
DrupalWebTestCase::assertUrl protected function Pass if the internal browser's URL matches the given path.
DrupalWebTestCase::buildXPathQuery protected function Builds an XPath query.
DrupalWebTestCase::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
DrupalWebTestCase::checkForMetaRefresh protected function Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive.
DrupalWebTestCase::checkPermissions protected function Check to make sure that the array of permissions are valid.
DrupalWebTestCase::clickLink protected function Follows a link by name.
DrupalWebTestCase::constructFieldXpath protected function Helper function: construct an XPath for the given set of attributes and value.
DrupalWebTestCase::copySetupCache protected function Copy the setup cache from/to another table and files directory.
DrupalWebTestCase::cronRun protected function Runs cron in the Drupal installed by Simpletest.
DrupalWebTestCase::curlClose protected function Close the cURL handler and unset the handler.
DrupalWebTestCase::curlExec protected function Initializes and executes a cURL request.
DrupalWebTestCase::curlHeaderCallback protected function Reads headers and registers errors received from the tested site.
DrupalWebTestCase::curlInitialize protected function Initializes the cURL connection.
DrupalWebTestCase::drupalCompareFiles protected function Compare two files based on size and file name.
DrupalWebTestCase::drupalCreateContentType protected function Creates a custom content type based on default settings.
DrupalWebTestCase::drupalCreateNode protected function Creates a node based on default settings.
DrupalWebTestCase::drupalCreateRole protected function Creates a role with specified permissions.
DrupalWebTestCase::drupalCreateUser protected function Create a user with a given set of permissions.
DrupalWebTestCase::drupalGet protected function Retrieves a Drupal path or an absolute path.
DrupalWebTestCase::drupalGetAJAX protected function Retrieve a Drupal path or an absolute path and JSON decode the result.
DrupalWebTestCase::drupalGetContent protected function Gets the current raw HTML of requested page.
DrupalWebTestCase::drupalGetHeader protected function Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed…
DrupalWebTestCase::drupalGetHeaders protected function Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the…
DrupalWebTestCase::drupalGetMails protected function Gets an array containing all e-mails sent during this test case.
DrupalWebTestCase::drupalGetNodeByTitle function Get a node from the database based on its title.
DrupalWebTestCase::drupalGetSettings protected function Gets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::drupalGetTestFiles protected function Get a list files that can be used in tests.
DrupalWebTestCase::drupalGetToken protected function Generate a token for the currently logged in user.
DrupalWebTestCase::drupalHead protected function Retrieves only the headers for a Drupal path or an absolute path.
DrupalWebTestCase::drupalLogin protected function Log in a user with the internal browser.
DrupalWebTestCase::drupalLogout protected function
DrupalWebTestCase::drupalPost protected function Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser.
DrupalWebTestCase::drupalPostAJAX protected function Execute an Ajax submission.
DrupalWebTestCase::drupalSetContent protected function Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page.
DrupalWebTestCase::drupalSetSettings protected function Sets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::getAbsoluteUrl protected function Takes a path and returns an absolute path.
DrupalWebTestCase::getAllOptions protected function Get all option elements, including nested options, in a select.
DrupalWebTestCase::getSelectedItem protected function Get the selected value from a select field.
DrupalWebTestCase::getSetupCacheKey protected function Returns the cache key used for the setup caching.
DrupalWebTestCase::getUrl protected function Get the current URL from the cURL handler.
DrupalWebTestCase::handleForm protected function Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type.
DrupalWebTestCase::loadSetupCache protected function Copies the cached tables and files for a cached installation setup.
DrupalWebTestCase::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
DrupalWebTestCase::preloadRegistry protected function Preload the registry from the testing site.
DrupalWebTestCase::prepareDatabasePrefix protected function Generates a database prefix for running tests.
DrupalWebTestCase::prepareEnvironment protected function Prepares the current environment for running the test.
DrupalWebTestCase::recursiveDirectoryCopy protected function Recursively copy one directory to another.
DrupalWebTestCase::refreshVariables protected function Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. 1
DrupalWebTestCase::resetAll protected function Reset all data structures after having enabled new modules.
DrupalWebTestCase::storeSetupCache protected function Store the installation setup to a cache.
DrupalWebTestCase::tearDown protected function Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. 6
DrupalWebTestCase::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
DrupalWebTestCase::xpath protected function Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.
DrupalWebTestCase::__construct function Constructor for DrupalWebTestCase. Overrides DrupalTestCase::__construct 1
UbercartCartCheckoutTestCase::createOrder protected function Creates a new order.
UbercartCartCheckoutTestCase::getInfo public static function
UbercartCartCheckoutTestCase::setUp protected function Overrides DrupalWebTestCase::setUp(). Overrides UbercartTestHelper::setUp
UbercartCartCheckoutTestCase::testCart public function Tests basic cart functionality.
UbercartCartCheckoutTestCase::testCartApi public function Tests cart API.
UbercartCartCheckoutTestCase::testCartMerge public function Tests that anonymous cart is merged into authenticated cart upon login.
UbercartCartCheckoutTestCase::testCartOrderTimeout public function Tests that cart orders are marked abandoned after a timeout.
UbercartCartCheckoutTestCase::testCheckout public function Tests the checkout process.
UbercartCartCheckoutTestCase::testCheckoutBlockedUser public function Tests blocked user checkout.
UbercartCartCheckoutTestCase::testCheckoutComplete public function Tests checkout complete functioning.
UbercartCartCheckoutTestCase::testCheckoutLogin public function Tests logging in the customer after checkout.
UbercartCartCheckoutTestCase::testCheckoutNewUsername public function Tests generating a new account at checkout.
UbercartCartCheckoutTestCase::testCheckoutRoleAssignment public function
UbercartCartCheckoutTestCase::testCustomerInformationCheckoutPane public function Tests functioning of customer information pane on checkout page.
UbercartCartCheckoutTestCase::testDeletedCartItem public function Tests that cart automatically removes products that have been deleted.
UbercartCartCheckoutTestCase::testMaximumQuantityRule public function Tests Rule integration for uc_cart_maximum_product_qty reaction rule.
UbercartTestHelper::$adminUser protected property User with privileges to do everything.
UbercartTestHelper::$customer protected property Authenticated but unprivileged user.
UbercartTestHelper::$product protected property Test product.
UbercartTestHelper::assertAjaxHelper protected function Helper function to test for text in a drupal ajax response.
UbercartTestHelper::assertAjaxRaw protected function Assert that the specified text is present in the raw drupal ajax response.
UbercartTestHelper::assertAjaxText protected function Assert that the specified text is present in the plain text version of the html that would be inserted into the page if this ajax response were executed.
UbercartTestHelper::assertNoAjaxRaw protected function Assert that the specified text is not present in the raw drupal ajax response.
UbercartTestHelper::assertNoAjaxText protected function Assert that the specified text is not present in the plain text version of the html that would be inserted into the page if this ajax response were executed.
UbercartTestHelper::checkout protected function Executes the checkout process.
UbercartTestHelper::createProduct protected function Creates a new product.
UbercartTestHelper::createProductClass protected function Creates a new product class.
UbercartTestHelper::findMail protected function Assert that an email was sent with a specific subject line.
UbercartTestHelper::populateCheckoutForm protected function Helper function to fill-in required fields on the checkout page.
UbercartTestHelper::ucPostAJAX protected function Extends drupalPostAjax() to replace additional content on the page after an ajax submission.