function UbercartCartCheckoutTestCase::testCheckoutRoleAssignment in Ubercart 6.2
Same name and namespace in other branches
- 7.3 uc_cart/tests/uc_cart.test \UbercartCartCheckoutTestCase::testCheckoutRoleAssignment()
File
- uc_cart/
uc_cart.test, line 393 - Shopping cart and checkout tests.
Class
- UbercartCartCheckoutTestCase
- Tests the cart and checkout functionality.
Code
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_result(db_query("SELECT uid FROM {uc_orders} ORDER BY order_id DESC"));
$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.');
// 4 e-mails: new account, customer invoice, admin invoice, role assignment
$mails = $this
->drupalGetMails();
$this
->assertEqual(count($mails), 4, '4 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.');
// 3 e-mails: customer invoice, admin invoice, role assignment
$mails = $this
->drupalGetMails();
$this
->assertEqual(count($mails), 3, '3 e-mails were sent.');
variable_del('drupal_test_email_collector');
}