public function CommerceDiscountUsageTest::testCommerceDiscountUsagePercentageProductDiscount in Commerce Discount 7
Test percentage product discounts.
File
- tests/
commerce_discount_usage.test, line 107 - Commerce Discounts usage tests.
Class
- CommerceDiscountUsageTest
- Testing commerce discount usage module functionality.
Code
public function testCommerceDiscountUsagePercentageProductDiscount() {
$this
->createUsageDiscount('product_discount', 'percentage', 5, 1);
// Create an 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 added as a component to the line item.
$price = commerce_price_wrapper_value($order_wrapper->commerce_line_items
->get(0), 'commerce_unit_price');
$this
->assertEqual($price['data']['components'][1]['price']['amount'], -50, 'Percentage product discount is added as a price component to the line item.');
commerce_order_save($order);
// 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 added as a component to the line item.
$price = commerce_price_wrapper_value($order_wrapper->commerce_line_items
->get(0), 'commerce_unit_price');
$this
->assertTrue(count($price['data']['components']) === 1, 'Percentage product discount is ignored after maximal usage.');
}