public function CommerceDiscountTest::testCommerceDiscountPercentageProductDiscount in Commerce Discount 7
Test percentage product discounts.
File
- tests/
commerce_discount.test, line 278 - Commerce Discounts tests.
Class
- CommerceDiscountTest
- Testing commerce discounts functionality.
Code
public function testCommerceDiscountPercentageProductDiscount() {
$discount = $this
->createDiscount('product_discount', 'percentage', 5);
// Create an order.
$order = $this
->createDummyOrder($this->store_customer->uid, array(
$this->product->product_id => 1,
), 'completed');
$order_wrapper = commerce_cart_order_refresh($order);
// Check if the discount was added as a component to the line item.
$price = $order_wrapper->commerce_line_items
->get(0)->commerce_unit_price
->value();
$this
->assertEqual($price['data']['components'][1]['price']['amount'], -50, 'Percentage product discount is added as a price component to the line item.');
$this
->assertEqual($price['amount'], 950, 'Line item amount with Percentage product discount is correct.');
$order_wrapper = commerce_cart_order_refresh($order);
// Check if the discount was added as a component to the line item.
$price = $order_wrapper->commerce_line_items
->get(0)->commerce_unit_price
->value();
$this
->assertEqual($price['data']['components'][1]['price']['amount'], -50, 'Percentage product discount is added as a price component to the line item even after refresh.');
$this
->assertEqual($price['amount'], 950, 'Line item amount with Percentage product discount is correct even after refresh.');
// Disable the discount.
$discount->status = FALSE;
entity_save('commerce_discount', $discount);
$order_wrapper = commerce_cart_order_refresh($order);
// Check if the discount was added as a component to the line item.
$price_data = $order_wrapper->commerce_line_items
->get(0)->commerce_unit_price
->value();
$this
->assertEqual($price_data['amount'], 1000, 'Line item amount without Percentage product discount is correct.');
}