Commit 5eaa89ff authored by bobbyaldol's avatar bobbyaldol Committed by bobbyaldol

Issue #1678544 by bobbyaldol: Tests for Order Example module added

parent 50dc1849
......@@ -4,3 +4,4 @@ package = Commerce (contrib)
dependencies[] = commerce_order
dependencies[] = commerce_cart
core = 7.x
files[] = order_example.test
<?php
/**
*@file
* This file contains tests for the Order Example Module.
*/
class OrderExampleTestCase extends CommerceBaseTestCase{
public static function getInfo(){
return array(
'name' => 'Order Example',
'description' => 'Tests the functionality of the Order Example.',
'group' => 'Commerce (contrib)',
);
}
/**
*Set up the necessary modules and users for testing.
*/
function setUp(){
$modules = parent::setUpHelper('all',array('order_example'));
parent::setUp($modules);
// User creation.
$this->site_admin = $this->createSiteAdmin();
//Check if the default product type is available else create it.
$product_types = commerce_product_types();
if(empty($product_types['product'])){
$this->createDummyProductType('product');
commerce_product_types_reset();
}
cache_clear_all(); //Just in case required.
}
/**
*Test the functionality of the Order Example's order creation with the "checkbox" unchecked.
*/
function testOrderExampleCreateOrderUnchecked(){
//User Login
$this->drupalLogin($this->site_admin);
$this->drupalGet('commerce_examples/order_example');
$this->assertText('Order Example',t('Order Example Page Loaded'));
$this->assertText('Order creation',t('Order Creation fieldset present'));
$this->assertText('Super-simple Add-to-cart',t('Add to Cart fieldset present'));
$sku = 'order_example_product';
$title = 'Order Example Product';
$product = $this->createDummyProduct($sku,$title);
$this->drupalPost(NULL,array('product_to_add' => $sku),t('Create or update an order with this product'));
$order = commerce_cart_order_load($this->site_admin->uid);
$this->assertNotNull($order,t('The order is loaded'));
// Reset the cache as we don't want to keep the lock.
entity_get_controller('commerce_order')->resetCache();
//Check if the order loaded has the right status as we created.
$this->assertEqual($order->status,'checkout_checkout');
$this->drupalGet('admin/commerce/orders/'.$order->order_id);
$this->assertText($product->title, t('Product !product_title is present in the cart', array('!product_title' => $product->title)));
}
/**
*Test the functionality of the Order Example's order creation with the "checkbox" checked.
*/
function testOrderExampleCreateOrderChecked(){
//User Login
$this->drupalLogin($this->site_admin);
//Create Dummy order so that we can check if the module is adding products to the current cart or not.
$this->createDummyOrder($this->site_admin->uid);
$this->drupalGet('commerce_examples/order_example');
$this->assertText('Order Example',t('Order Example Page Loaded'));
$this->assertText('Order creation',t('Order Creation fieldset present'));
$this->assertText('Super-simple Add-to-cart',t('Add to Cart fieldset present'));
$sku = 'order_example_product';
$title = 'Order Example Product';
$product = $this->createDummyProduct($sku,$title);
$this->drupalPost(NULL,array('product_to_add' => $sku,'use_cart' => TRUE),t('Create or update an order with this product'));
$order = commerce_cart_order_load($this->site_admin->uid);
$this->assertNotNull($order,t('The order is loaded'));
// Reset the cache as we don't want to keep the lock.
entity_get_controller('commerce_order')->resetCache();
//Check if the order loaded has the right status as we created.
$this->assertEqual($order->status,'cart');
$this->drupalGet('admin/commerce/orders/'.$order->order_id);
$this->assertText($product->title, t('Product !product_title is present in the cart', array('!product_title' => $product->title)));
}
/**
* Tests the Order Examples add to cart functionality.
*/
function testOrderExampleAddToCart(){
$this->drupalLogin($this->site_admin);
$this->drupalGet('commerce_examples/order_example');
$this->assertText(t('Order Example'));
//Create Dummy product to add to cart later.
$sku = 'order_example_product';
$title = 'Order Example Product';
$product = $this->createDummyProduct($sku,$title);
$this->drupalPost(NULL,array('addcart_product' => $sku),t('Add this item to cart'));
$this->assertText($title.' added to your cart.');
$order = commerce_cart_order_load($this->site_admin->uid);
$this->assertNotNull($order,t('The order is loaded'));
// Reset the cache as we don't want to keep the lock.
entity_get_controller('commerce_order')->resetCache();
//Check if the order loaded has the right status as we created.
$this->assertEqual($order->status,'cart');
$this->drupalGet('admin/commerce/orders/'.$order->order_id);
$this->assertText($product->title, t('Product !product_title is present in the cart', array('!product_title' => $product->title)));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment