public function CommerceDiscountUsageTest::testCommerceDiscountUsagePercentageOrderDiscount in Commerce Discount 7
Test percentage order discounts.
File
- tests/
commerce_discount_usage.test, line 60 - Commerce Discounts usage tests.
Class
- CommerceDiscountUsageTest
- Testing commerce discount usage module functionality.
Code
public function testCommerceDiscountUsagePercentageOrderDiscount() {
// Testing percentage discount.
// Create a percentage order discount of 5% limited to one use.
$this
->createUsageDiscount('order_discount', 'percentage', 5, 1);
// Create a completed order.
$order = $this
->createDummyOrder($this->store_customer->uid, array(
$this->product->product_id => 1,
), 'completed');
// Recalculate discounts.
$order_wrapper = commerce_cart_order_refresh($order);
// Check if the discount was applied on the order total price.
$this
->assertTrue($order_wrapper->commerce_order_total->amount
->value() == 950, 'Percentage order discount is deducted correctly.');
// Create another order to make sure the discount isn't applied again.
$order = $this
->createDummyOrder($this->store_customer2->uid, array(
$this->product->product_id => 1,
), 'completed');
// Recalculate discounts.
$order_wrapper = commerce_cart_order_refresh($order);
// Check if the discount was applied on the order total price.
$this
->assertTrue($order_wrapper->commerce_order_total->amount
->value() == 1000, 'Percentage order discount is ignored after maximal usage.');
}