function CommerceRecurringTestCase::testCommerceRecurringCronOrderCreation in Commerce Recurring Framework 7.2
Test cron run and order creation on recurring entity date base.
File
- tests/
commerce_recurring.test, line 326 - Unit tests for the commerce recurring module.
Class
- CommerceRecurringTestCase
- @file Unit tests for the commerce recurring module.
Code
function testCommerceRecurringCronOrderCreation() {
// Create a recurring entity.
$product = $this
->createRecurringProduct();
$product_wrapper = entity_metadata_wrapper('commerce_product', $product);
$line_item = commerce_cart_product_add_by_id($product->product_id, 1, TRUE, $this->customer->uid);
$recurring_entity = $this
->createRecurringEntity($product);
$initial_order = commerce_order_load($line_item->order_id);
$initial_order->commerce_customer_billing = (array) $this
->createDummyCustomerProfile('billing', $this->customer->uid);
$initial_order->status = 'completed';
commerce_order_save($initial_order);
commerce_cart_order_ids_reset();
// Run cron.
drupal_cron_run();
// Check if the order has been correctly created and it's linked to the
// recurring entity.
$recurring_entities = entity_load('commerce_recurring', array(
$recurring_entity->id,
), array(), TRUE);
$recurring_entity = reset($recurring_entities);
$recurring_wrapper = entity_metadata_wrapper('commerce_recurring', $recurring_entity);
// The order is the second one now.
$order_wrapper = $recurring_wrapper->commerce_recurring_order
->get(1);
$order = $order_wrapper
->value();
$this
->assertTrue(isset($order), t('New order has been created for the recurring entity'));
$this
->assertEqual($order->data['recurring_entity'], $recurring_entity->id, t('Recurring id is associated with the order'));
$this
->assertEqual($order_wrapper->commerce_order_total->amount
->value(), $product_wrapper->commerce_recurring_rec_price->amount
->value(), t('Total price is calculated ok'));
$this
->assertEqual($order->status, 'recurring_pending', t('Order is created in recurring_pending status'));
$first_order = $recurring_wrapper->commerce_recurring_order
->get(0)
->value();
$this
->assertEqual($order->commerce_customer_billing, $first_order->commerce_customer_billing, t('Customer profile information gets copied from the initial order to the recurring one'));
$user_current_cart = commerce_cart_order_load($this->customer->uid);
$this
->assertTrue(empty($user_current_cart), t('Customer cart is empty after creating a recurring order'));
}