diff --git a/commerce_discount.info b/commerce_discount.info
index 082e6a3..26ec861 100644
--- a/commerce_discount.info
+++ b/commerce_discount.info
@@ -32,7 +32,14 @@ files[] = includes/views/handlers/commerce_discount_handler_field_operations_dro
 files[] = includes/views/handlers/commerce_discount_handler_field_commerce_discount_analytics.inc
 
 ; Simple tests
-files[] = commerce_discount.test
+files[] = tests/commerce_discount.test
+files[] = tests/commerce_discount_base.test
+files[] = tests/commerce_discount_conditions.test
+files[] = tests/commerce_discount_date.test
+files[] = tests/commerce_discount_date_ui.test
+files[] = tests/commerce_discount_ui.test
+files[] = tests/commerce_discount_usage.test
+files[] = tests/commerce_discount_usage_ui.test
 
 test_dependencies[] = addressfield
 test_dependencies[] = commerce_shipping
diff --git a/commerce_discount.test b/commerce_discount.test
deleted file mode 100644
index c42895f..0000000
--- a/commerce_discount.test
+++ /dev/null
@@ -1,1407 +0,0 @@
-<?php
-
-/**
- * @file
- * Commerce Discounts tests.
- */
-
-/**
- * Base class for commerce discount tests.
- */
-class CommerceDiscountTestBase extends CommerceBaseTestCase {
-
-  /**
-   * Don't need most of default core modules.
-   */
-  protected $profile = 'minimal';
-
-  /**
-   * Dummy commerce_product and related product node.
-   */
-  protected $product;
-  protected $product_node;
-
-  /**
-   * User accounts for testing.
-   */
-  protected $store_admin;
-  protected $store_customer;
-
-  /**
-   * Allows submodules to define themselves for setup.
-   *
-   * @var string
-   */
-  protected $sub_module;
-
-  /**
-   * Overrides CommerceBaseTestCase::permissionBuilder().
-   */
-  protected function permissionBuilder($set) {
-    $permissions = parent::permissionBuilder($set);
-
-    switch ($set) {
-      case 'store admin':
-      case 'site admin':
-        $permissions[] = 'administer commerce discounts';
-        break;
-    }
-
-    return $permissions;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function setUp() {
-    // Enable all commerce modules + commerce_discount.
-    $modules = parent::setUpHelper('all');
-
-    $modules[] = 'commerce_discount';
-    if ($this->sub_module) {
-      $modules[] = $this->sub_module;
-    }
-    parent::setUp($modules);
-
-    // User creation for different operations.
-    $this->store_admin = $this->createStoreAdmin();
-    $this->store_customer = $this->createStoreCustomer();
-
-    // Create a dummy product.
-    $this->product = $this->createDummyProduct('PROD-01', 'Product One', 1000);
-
-    // Create a dummy product display content type.
-    $this->createDummyProductDisplayContentType();
-
-    // Create a product display node.
-    $this->product_node = $this->createDummyProductNode(array($this->product->product_id), 'Product One node');
-
-    // Set the default country to US.
-    variable_set('site_default_country', 'US');
-  }
-
-  /**
-   * Create a discount.
-   *
-   * @param string $discount_type
-   *   The discount type; Either 'order_discount' or 'product_discount'.
-   * @param string $offer_type
-   *   The discount offer type; Either 'fixed_amount' or 'percentage'.
-   * @param int|array $amount
-   *   The discount offer amount, percentage or product ids array.
-   * @param string $name
-   *   Discount name - Optional. If given, CANNOT start with a number.
-   * @param string $component_title
-   *   Component title - Optional.
-   *
-   * @return object
-   *   The newly created commerce_discount entity.
-   */
-  protected function createDiscount($discount_type, $offer_type, $amount, $name = '', $component_title = '', $sort_order = 10) {
-    // Create the discount offer.
-    $commerce_discount_offer = entity_create('commerce_discount_offer', array('type' => $offer_type));
-    $offer_wrapper = entity_metadata_wrapper('commerce_discount_offer', $commerce_discount_offer);
-    switch ($offer_type) {
-      case 'fixed_amount':
-        $offer_wrapper->commerce_fixed_amount->amount = $amount;
-        $offer_wrapper->commerce_fixed_amount->currency_code = 'USD';
-        break;
-
-      case 'percentage':
-        $offer_wrapper->commerce_percentage = $amount;
-        break;
-
-      case 'free_products':
-        // Product ids array should be provided for $amount.
-        $offer_wrapper->commerce_free_products = $amount;
-        break;
-    }
-
-    $offer_wrapper->save();
-
-    // Provide default name.
-    $name = $name ? $name : $discount_type . '_' . $offer_type;
-    $component_title = $component_title ? $component_title : $name;
-
-    // Create the discount.
-    $values = array(
-      'name' => $name,
-      'label' => $name,
-      'type' => $discount_type,
-      'sort_order' => $sort_order,
-      'component_title' => $component_title,
-      'status' => TRUE,
-      'export_status' => TRUE,
-    );
-    $commerce_discount = entity_create('commerce_discount', $values);
-    $discount_wrapper = entity_metadata_wrapper('commerce_discount', $commerce_discount);
-    $discount_wrapper->commerce_discount_offer = $commerce_discount_offer;
-    $discount_wrapper->save();
-
-    return $discount_wrapper->value();
-  }
-
-  /**
-   * Determines whether or not a discount has been applied to an order.
-   *
-   * @param $discount_name
-   *   The machine-name of the discount to look for.
-   * @param $order
-   *   The order object to inspect for the discount.
-   *
-   * @return bool
-   *   Boolean indicating whether or not the discount is applied to the order.
-   */
-  public function discountAppliedToOrder($discount_name, $order) {
-    // Fetch the list of discounts applied to the order based on the price
-    // components in its order total array.
-    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
-    $order_total = $order_wrapper->commerce_order_total->value();
-    $applied_discounts = commerce_discount_get_discounts_applied_to_price($order_total);
-
-    // Look for the given discount in the list of applied discounts.
-    return in_array($discount_name, $applied_discounts);
-  }
-}
-
-/**
- * Testing commerce discounts UI and functionality.
- */
-class CommerceDiscountTest extends CommerceDiscountTestBase {
-  /**
-   * Implementation of getInfo().
-   */
-  public static function getInfo() {
-    return array(
-      'name' => 'Discounts',
-      'description' => 'Test discounts UI and functionality',
-      'group' => 'Commerce Discount',
-    );
-  }
-
-  /**
-   * Access to commerce discounts admin.
-   */
-  public function testCommerceDiscountUIAccessDiscountsListing() {
-    // Login with customer.
-    $this->drupalLogin($this->store_customer);
-    // Check the access to the profiles listing.
-    $this->drupalGet('admin/commerce/discounts');
-    $this->assertResponse(403, 'The store customer has no access to discounts administration.');
-
-    // Login with store admin.
-    $this->drupalLogin($this->store_admin);
-    // Check the access to the profiles listing.
-    $this->drupalGet('admin/commerce/discounts');
-    $this->assertResponse(200, 'The store admin has access to discounts administration.');
-
-    // Check the message of no discounts available.
-    $this->assertText(t('No discounts found.'), "'No discounts found.' message is displayed");
-    // Check the add customer profile link.
-    $this->assertRaw(l(t('Add discount'), 'admin/commerce/discounts/add'), "'Add discount' link is present in the page");
-  }
-
-  /**
-   * Test the add discount UI.
-   */
-  public function testCommerceDiscountUIAddDiscount() {
-    // Login with normal user.
-    $this->drupalLogin($this->store_customer);
-
-    // Access to the admin discount creation page.
-    $this->drupalGet('admin/commerce/discounts/add');
-
-    $this->assertResponse(403, 'Normal user is not able to add a discount using the admin interface');
-
-    // Login with store admin.
-    $this->drupalLogin($this->store_admin);
-
-    // Access to the admin discount creation page.
-    $this->drupalGet('admin/commerce/discounts/add');
-
-    $this->assertResponse(200, 'Store admin user is allowed to add a discount using the admin interface');
-
-    // Check the integrity of the add form.
-    $this->assertFieldByName('commerce_discount_type', NULL, 'Discount type field is present');
-    $this->assertFieldByName('label', NULL, 'Label field is present');
-    $this->assertFieldByName('component_title', NULL, 'Name field is present');
-    $this->assertFieldByName('commerce_discount_fields[commerce_discount_offer][und][form][type]', NULL, 'Offer type field is present');
-    $this->assertFieldByName('commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]', NULL, 'Amount field is present');
-    $this->assertFieldByName('status', NULL, 'Status field is present');
-    $this->assertFieldById('edit-submit', t('Save discount'), 'Save discount button is present');
-
-    // Try to save the product and check validation messages.
-    $this->drupalPost(NULL, array(), t('Save discount'));
-
-    $this->assertText(t('Admin title field is required.'), 'Validation message for missing label.');
-    $this->assertText(t('Machine-readable name field is required.'), 'Validation message for missing machine-name.');
-    $this->assertText(t('Fixed amount field is required.'), 'Validation message for missing amount.');
-
-    // Load a clean discount add form.
-    $this->drupalGet('admin/commerce/discounts/add');
-    // Create a discount.
-    $values = array(
-      'label' => 'Order discount - fixed',
-      'name' => 'order_discount_fixed',
-      'component_title' => 'Order discount',
-      'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => 12.77,
-    );
-    $this->drupalPost(NULL, $values, t('Save discount'));
-
-    // Load the discount and wrap it.
-    $discount = entity_load_single('commerce_discount', 1);
-    $discount_wrapper = entity_metadata_wrapper('commerce_discount', $discount);
-
-    // Check the stored discount.
-    $this->assertEqual($discount->label, $values['label'], 'Label stored correctly.');
-    $this->assertEqual($discount->name, 'discount_' . $values['name'], 'Name stored correctly.');
-    $this->assertEqual($discount->export_status, 1, 'Active stored correctly.');
-    $this->assertEqual($discount->component_title, $values['component_title'], 'Name for customer stored correctly.');
-    $this->assertEqual($discount->status, 1, 'Enabled stored correctly.');
-
-    $this->assertEqual($discount_wrapper->commerce_discount_offer->getBundle(), 'fixed_amount', 'Offer type stored correctly.');
-    $this->assertEqual($discount_wrapper->commerce_discount_offer->commerce_fixed_amount->amount->value(), 1277, 'Amount stored correctly.');
-
-    // Check the discounts listing.
-    $this->assertUrl('admin/commerce/discounts', array(), 'Landing page after save is the discounts list.');
-    $this->assertText($values['label'], 'Label of the discount is present.');
-    $this->assertText($values['component_title'], 'Name of the discount is present.');
-  }
-
-  /**
-   * Test the Edit discount UI.
-   */
-  public function testCommerceDiscountUIEditDiscount() {
-    // Create a discount.
-    $discount = $this->createDiscount('order_discount', 'fixed_amount', 300);
-
-    // Login with normal user.
-    $this->drupalLogin($this->store_customer);
-
-    // Access to the admin discount edit page.
-    $this->drupalGet('admin/commerce/discounts/manage/' . $discount->name);
-    $this->assertResponse(403, 'Normal user is not able to edit a discount using the admin interface');
-
-    // Login with store admin.
-    $this->drupalLogin($this->store_admin);
-
-    // Access to the admin discount edit page.
-    $this->drupalGet('admin/commerce/discounts/manage/' . $discount->name);
-    $this->assertResponse(200, 'Store admin user is allowed to edit a discount using the admin interface');
-
-    // Check the integrity of the add form.
-    $this->assertFieldByName('commerce_discount_type', NULL, 'Discount type field is present');
-    $this->assertFieldByName('label', NULL, 'Label field is present');
-    $this->assertFieldByName('component_title', NULL, 'Name field is present');
-    $this->assertFieldByName('commerce_discount_fields[commerce_discount_offer][und][form][type]', NULL, 'Offer type field is present');
-    $this->assertFieldByName('commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]', NULL, 'Amount field is present');
-    $this->assertFieldByName('status', NULL, 'Status field is present');
-    $this->assertFieldById('edit-submit', t('Save discount'), 'Save discount button is present');
-    $this->assertFieldById('edit-delete', t('Delete discount'), 'Delete discount button is present');
-
-    // Empty values for validation assertions.
-    $values = array(
-      'label' => '',
-      'name' => '',
-      'component_title' => '',
-      'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => '',
-    );
-
-    // Try to save the product and check validation messages.
-    $this->drupalPost(NULL, $values, t('Save discount'));
-
-    $this->assertText(t('Admin title field is required.'), 'Validation message for missing label.');
-    $this->assertText(t('Machine-readable name field is required.'), 'Validation message for missing machine-name.');
-    $this->assertText(t('Fixed amount field is required.'), 'Validation message for missing amount.');
-
-    // Discount new values.
-    $values = array(
-      'label' => 'Order discount - fixed',
-      'name' => 'order_discount_fixed',
-      'component_title' => 'Order discount',
-      'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => 12.77,
-    );
-    $this->drupalPost(NULL, $values, t('Save discount'));
-
-    // Load the discount and wrap it.
-    $discounts = entity_load('commerce_discount', array($discount->discount_id), $conditions = array(), $reset = TRUE);
-    $discount = reset($discounts);
-    $discount_wrapper = entity_metadata_wrapper('commerce_discount', $discount);
-
-    // Check the stored discount.
-    $this->assertEqual($discount->label, $values['label'], 'Label stored correctly.');
-    $this->assertEqual($discount->name, 'discount_' . $values['name'], 'Name stored correctly.');
-    $this->assertEqual($discount->component_title, $values['component_title'], 'Name for customer stored correctly.');
-    $this->assertEqual($discount->status, 1, 'Enabled stored correctly.');
-
-    $this->assertEqual($discount_wrapper->commerce_discount_offer->getBundle(), 'fixed_amount', 'Offer type stored correctly.');
-    $this->assertEqual($discount_wrapper->commerce_discount_offer->commerce_fixed_amount->amount->value(), 1277, 'Amount stored correctly.');
-
-    // Check the discounts listing.
-    $this->assertUrl('admin/commerce/discounts', array(), 'Landing page after save is the discounts list.');
-    $this->assertText($values['label'], 'Label of the discount is present.');
-    $this->assertText($values['component_title'], 'Name of the discount is present.');
-  }
-
-  /**
-   * Test the delete discount UI.
-   */
-  public function testCommerceDiscountUIDeleteDiscount() {
-    // Create a discount.
-    $discount = $this->createDiscount('order_discount', 'fixed_amount', 300);
-
-    // Login with normal user.
-    $this->drupalLogin($this->store_customer);
-
-    // Access to the admin discount edit page.
-    $this->drupalGet('admin/commerce/discounts/manage/' . $discount->name . '/delete');
-
-    $this->assertResponse(403, 'Normal user is not able to delete a discount using the admin interface');
-
-    // Login with store admin.
-    $this->drupalLogin($this->store_admin);
-
-    // Access to the admin discount edit page.
-    $this->drupalGet('admin/commerce/discounts/manage/' . $discount->name . '/delete');
-
-    $this->assertResponse(200, 'Store admin user is allowed to delete a discount using the admin interface');
-
-    // Check the integrity of the add form.
-    $this->pass('Test the discount delete confirmation form:');
-    $this->assertTitle(t('Are you sure you want to delete the Commerce Discount !label?', array('!label' => $discount->label)) . ' | Drupal', 'The confirmation message is displayed');
-    $this->assertText(t('This action cannot be undone'), "A warning notifying the user about the action can't be undone is displayed.");
-    $this->assertFieldById('edit-submit', t('Confirm'), 'Delete button is present');
-    $this->assertText(t('Cancel'), 'Cancel is present');
-
-    // Try to save the product and check validation messages.
-    $this->drupalPost(NULL, array(), t('Confirm'));
-
-    // Check the url after deleting and if the discount has been deleted in
-    // database.
-    $this->assertUrl('admin/commerce/discounts', array(), 'Landing page after deleting a discount is the discounts listing page');
-    $this->assertRaw(t('Deleted %type %label.', array('%type' => 'Commerce Discount', '%label' => $discount->label)), "'Discount has been deleted' message is displayed");
-    $this->assertRaw(t('No discounts found.', array('@link' => url('admin/commerce/discounts/add'))), 'Empty discount listing message is displayed');
-  }
-
-  /**
-   * Test the importing of commerce discounts.
-   */
-  public function testCommerceDiscountImport() {
-    // Login store admin.
-    $this->drupalLogin($this->store_admin);
-
-    // Access to the admin discount creation page.
-    $this->drupalGet('admin/commerce/discounts/import');
-    $this->assertResponse(200, 'Store admin is allowed in the discounts import page');
-
-    $exported_discount = '{
-  "name" : "pf",
-  "label" : "PF",
-  "type" : "product_discount",
-  "status" : "1",
-  "component_title" : "pf",
-  "sort_order" : "10",
-  "commerce_discount_offer" : {
-    "type" : "fixed_amount",
-    "commerce_fixed_amount" : { "und" : [
-        {
-          "amount" : "1200",
-          "currency_code" : "USD",
-          "data" : { "components" : [] }
-        }
-      ]
-    }
-  },
-  "commerce_compatibility_strategy" : { "und" : [ { "value" : "any" } ] },
-  "commerce_compatibility_selection" : [],
-  "commerce_discount_date" : [],
-  "inline_conditions" : [],
-  "discount_usage_per_person" : [],
-  "discount_usage_limit" : []
-}';
-
-    // Import the discount.
-    $import = entity_import('commerce_discount', $exported_discount);
-    $this->assertNotNull($import, 'Entity export JSON imported successfully.');
-    entity_save('commerce_discount', $import);
-
-    // Export the discount to make sure it's identical to the import string.
-    $discount = entity_load_single('commerce_discount', $import->discount_id);
-    $export = entity_export('commerce_discount', $discount);
-    $this->assertTrue($exported_discount == $export, 'Exported discount is identical to its origin.');
-  }
-
-  /**
-   * Test order wrapper cache from order refresh.
-   */
-  public function testCommerceDiscountOrderRefreshWrapper() {
-    // Create a 'free bonus products' product discount.
-    $discount = $this->createDiscount('order_discount', 'free_products', array($this->product->product_id));
-    // 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);
-    $line_items = $order_wrapper->value()->commerce_line_items[LANGUAGE_NONE];
-    $this->assertEqual($order_wrapper->commerce_line_items->count(), count($line_items), 'Number of line items matched');
-
-    // Disable the discount.
-    $discount->status = FALSE;
-    entity_save('commerce_discount', $discount);
-
-    $order_wrapper = commerce_cart_order_refresh($order);
-    $line_items = $order_wrapper->value()->commerce_line_items[LANGUAGE_NONE];
-    $this->assertEqual($order_wrapper->commerce_line_items->count(), count($line_items), 'Number of line items matched');
-  }
-
-  /**
-   * Test fixed order discounts.
-   */
-  public function testCommerceDiscountFixedOrderDiscount() {
-    // Testing fixed discount.
-    // Create a fixed order discount of $3.
-    $discount = $this->createDiscount('order_discount', 'fixed_amount', 300);
-
-    // 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 applied on the order total price.
-    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 700, 'Fixed order discount is deducted correctly.');
-
-    // Disable the discount.
-    $discount->status = FALSE;
-    entity_save('commerce_discount', $discount);
-
-    // Re-save the order.
-    // Check if the discount was applied on the order total price.
-    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
-    $order_wrapper->save();
-
-    // Recalculate discounts.
-    $order_wrapper = commerce_cart_order_refresh($order);
-    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 1000, "Fixed order discount is removed when it's not applicable.");
-  }
-
-  /**
-   * Test percentage order discounts.
-   */
-  public function testCommerceDiscountPercentageOrderDiscount() {
-    // Testing percentage discount.
-    // Create a percentage order discount of 5%.
-    $discount = $this->createDiscount('order_discount', 'percentage', 5);
-    // 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.');
-
-    // Disable the discount.
-    $discount->status = FALSE;
-    entity_save('commerce_discount', $discount);
-
-    // Re-save the order.
-    // Check if the discount was applied on the order total price.
-    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
-    $order_wrapper->save();
-
-    // Recalculate discounts.
-    $order_wrapper = commerce_cart_order_refresh($order);
-    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 1000, "Percentage order discount is removed when it's not applicable.");
-  }
-
-  /**
-   * Test a 100% off product percentage discount.
-   *
-   * A 100% off product-level discount differs from the "Free product" discount
-   * offer type since those are normally used as an "add-on" that is added
-   * without the user's interaction (maybe as part of a package, or bonus);
-   * whereas a 100% off discount should be used for any product purposely added
-   * to a cart order.
-   */
-  public function testCommerceDiscountOneHundredPercentOff() {
-    // Login as the store admin.
-    $this->drupalLogin($this->store_admin);
-
-    // Create a 100% off discount and create a test product.
-    $this->createDiscount('product_discount', 'percentage', 100, 'freebie');
-
-    $product = $this->createDummyProduct('TEST-PRODUCT', 'Test Product', 999);
-
-    // Create the order and apply the freebie discount.
-    $order = $this->createDummyOrder($this->store_admin->uid, array($product->product_id => 1));
-    $order_wrapper = commerce_cart_order_refresh($order);
-
-    $properly_applied = $this->discountAppliedToOrder('freebie', $order);
-    $this->assertTrue($properly_applied, t('100% off discount applied to a product.'));
-
-    // Invoke line item price re-calculation.
-    $line_item = $order_wrapper->commerce_line_items->get(0)->value();
-    rules_invoke_event('commerce_product_calculate_sell_price', $line_item);
-
-    $order_wrapper = commerce_cart_order_refresh($order);
-
-    // Verify that the product is now free.
-    $line_item_wrapper = $order_wrapper->commerce_line_items->get(0);
-    $unit_price = $line_item_wrapper->commerce_unit_price->value();
-
-    $this->assertEqual($unit_price['amount'], 0, 'Product line item unit price amount is properly set to 0.');
-    $this->assertEqual($unit_price['data']['components'][1]['price']['amount'], -999, 'Product line item unit price discount component properly set to 100% of the product price.');
-  }
-
-  /**
-   * Test free bonus products order discounts.
-   */
-  public function testCommerceDiscountFreeProductsOrderDiscount() {
-    // Create 'free bonus products' product discount.
-    $discount = $this->createDiscount('order_discount', 'free_products', array($this->product->product_id));
-    // 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->assertEqual($order_wrapper->commerce_order_total->amount->value(), 1000, 'Free Bonus Products order discount has the price of only one product.');
-    $this->assertEqual($order_wrapper->commerce_line_items->count(), 2, 'Free Bonus Products order discount is added as a line item.');
-
-    // Disable the discount.
-    $discount->status = FALSE;
-    entity_save('commerce_discount', $discount);
-
-    // Re-save the order.
-    // Check if the discount was applied on the order total price.
-    $order_wrapper = commerce_cart_order_refresh($order);
-    $this->assertEqual($order_wrapper->commerce_order_total->amount->value(), 1000, "Free Bonus Products order discount is removed when it's not applicable and price is the same.");
-    $this->assertEqual($order_wrapper->commerce_line_items->count(), 1, "Free Bonus Products order discount is removed when it's not applicable and line item count is only 1");
-  }
-
-  /**
-   * Test fixed product discounts.
-   */
-  public function testCommerceDiscountFixedProductDiscount() {
-    $this->createDiscount('product_discount', 'fixed_amount', 300);
-
-    // Create an order.
-    $order = $this->createDummyOrder($this->store_customer->uid, array($this->product->product_id => 1), 'completed');
-    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
-
-    // Invoke line item price re-calculation.
-    $line_item = $order_wrapper->commerce_line_items->get(0)->value();
-    rules_invoke_event('commerce_product_calculate_sell_price', $line_item);
-
-    // Check if the discount was added as a component to the line item.
-    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
-    $price_data = $line_item_wrapper->commerce_unit_price->data->value();
-
-    $this->assertTrue($price_data['components'][1]['price']['amount'] == -300, 'Fixed product discount is added as a price component to the line item.');
-  }
-
-  /**
-   * Test percentage product discounts.
-   */
-  public function testCommerceDiscountPercentageProductDiscount() {
-    $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 = entity_metadata_wrapper('commerce_order', $order);
-
-    // Invoke line item price re-calculation.
-    $line_item = $order_wrapper->commerce_line_items->get(0)->value();
-    rules_invoke_event('commerce_product_calculate_sell_price', $line_item);
-
-    // Check if the discount was added as a component to the line item.
-    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
-    $price_data = $line_item_wrapper->commerce_unit_price->data->value();
-
-    $this->assertTrue($price_data['components'][1]['price']['amount'] == -50, 'Percentage product discount is added as a price component to the line item.');
-  }
-
-  /**
-   * Test discounted product price display.
-   */
-  public function testCommerceDiscountDiscountedProductPriceDisplay() {
-    // Create a product discount.
-    $this->createDiscount('product_discount', 'fixed_amount', 300);
-    $formatted_discounted_price = '$7.00';
-
-    // Log as a normal user.
-    $this->drupalLogin($this->store_customer);
-
-    $nid = $this->product_node->nid;
-    // View a product node.
-    $this->drupalGet("node/$nid");
-    $product_price = $this->xpath('//div[contains(@class, "field-name-commerce-price")]/div[contains(@class, "field-item")]');
-    $this->assertTrue(trim((string) $product_price[0]->div) == $formatted_discounted_price, 'Discounted product price is shown on product page.');
-
-    // Add a product to the cart.
-    $this->drupalPost('node/' . $this->product_node->nid, array(), t('Add to cart'));
-
-    // View the cart.
-    $this->drupalGet('cart');
-    $product_price = $this->xpath('//td[contains(@class, "views-field-commerce-unit-price")]');
-    $this->assertTrue(trim((string) $product_price[0]->{0}) == $formatted_discounted_price, 'Discounted product price is shown on the cart.');
-  }
-
-  /**
-   * Test multiple fixed order discounts.
-   */
-  public function testCommerceDiscountMultipleFixedOrderDiscounts() {
-    // Create two discounts.
-    $this->createDiscount('order_discount', 'fixed_amount', 300, 'of1');
-    $this->createDiscount('order_discount', 'fixed_amount', 200, 'of2');
-
-    // 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);
-
-    $this->assertTrue($order_wrapper->commerce_discounts->count() == 2, '2 discounts are listed as applied on the order.');
-    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 500, 'Two fixed order discounts are applied on the total price.');
-    $this->assertTrue($order_wrapper->commerce_line_items->count() == 3, 'An order with one product and two fixed order discounts has three line items.');
-    $order_wrapper->save();
-    $this->assertTrue($order_wrapper->commerce_line_items->count() == 3, 'After updating the order it still has three line items.');
-  }
-
-  /**
-   * Test rounding in percentage based product discounts.
-   *
-   * To test the rounding used when adding discount price components to product
-   * line items, we use a 30% discount on a product that costs $10.25. When
-   * rounding was not working correctly, the unit price amount would be set to
-   * $7.18 even though the sum of the unit price's price components would in
-   * fact be $7.17. In reality, since the actual discount amount SHOULD be
-   * rounded up to $3.08 from $3.075, the unit price amount SHOULD be $7.17.
-   * This test ensures that is the case in conjunction with a patch from the
-   * linked issue below.
-   *
-   * @link https://www.drupal.org/node/2468943#comment-10476486
-   */
-  public function testCommerceProductPercentageDiscountRounding() {
-    // Create the 30% discount and $10.25 product.
-    $this->createDiscount('product_discount', 'percentage', 30, 'discount_30_off');
-    $product = $this->createDummyProduct('TEST-PRODUCT', 'Test Product', 1025);
-
-    // Create the order and apply discount.
-    $order = $this->createDummyOrder($this->store_customer->uid, array($product->product_id => 1), 'completed');
-    $order_wrapper = commerce_cart_order_refresh($order);
-
-    // Verify rounding came out properly.
-    $line_item_wrapper = $order_wrapper->commerce_line_items->get(0);
-    $unit_price = $line_item_wrapper->commerce_unit_price->value();
-
-    $this->assertEqual($unit_price['amount'], 717, 'Product line item unit price amount rounded properly for a 30% discount.');
-    $this->assertEqual($unit_price['data']['components'][1]['price']['amount'], -308, 'Product line item unit price discount component properly rounded for a 30% discount.');
-  }
-
-  /**
-   * Test discount compatibility strategies.
-   *
-   * Currently implemented strategies include:
-   * - any: discount is compatible with any other discount.
-   * - except: discount is compatible with any discount except selected ones.
-   * - only: discount is only compatible with selected ones.
-   * - none: discount is not compatible with any other discount.
-   *
-   * Compatibility is checked first to ensure that discounts already on an order
-   * are not incompatible with the discount being added. It is then checked to
-   * ensure the discount being added is not incompatible with any discount that
-   * has already been added to the order.
-   */
-  public function testCommerceDiscountCompatibilityStrategies() {
-    // Create two discounts set to execute one after the other.
-    $discount_one = $this->createDiscount('order_discount', 'fixed_amount', 100, 'of1', 1);
-    $discount_one_wrapper = entity_metadata_wrapper('commerce_discount', $discount_one);
-    $discount_two = $this->createDiscount('order_discount', 'fixed_amount', 200, 'of2', 2);
-    $discount_two_wrapper = entity_metadata_wrapper('commerce_discount', $discount_two);
-
-    // Create an order and recalculate discounts.
-    $order = $this->createDummyOrder($this->store_customer->uid, array($this->product->product_id => 1), 'completed');
-
-    // Test compatibility with both discounts using the "any" strategy. Both
-    // discounts should be applied.
-    commerce_cart_order_refresh($order);
-
-    $properly_applied = $this->discountAppliedToOrder('of1', $order) && $this->discountAppliedToOrder('of2', $order);
-    $this->assertTrue($properly_applied, t('Discount one and two applied when both are compatible with any discount.'));
-
-    // Test compatibility with only discount one using the "none" strategy. Only
-    // discount one should be applied.
-    $discount_one_wrapper->commerce_compatibility_strategy = 'none';
-    $discount_one_wrapper->save();
-    commerce_cart_order_refresh($order);
-
-    $properly_applied = $this->discountAppliedToOrder('of1', $order) && !$this->discountAppliedToOrder('of2', $order);
-    $this->assertTrue($properly_applied, t('Only discount one applied when it is not compatible with any other discount.'));
-
-    // Test compatibility with only discount two using the "none" strategy. Only
-    // discount one should be applied.
-    $discount_one_wrapper->commerce_compatibility_strategy = 'any';
-    $discount_one_wrapper->save();
-    $discount_two_wrapper->commerce_compatibility_strategy = 'none';
-    $discount_two_wrapper->save();
-    commerce_cart_order_refresh($order);
-
-    $properly_applied = $this->discountAppliedToOrder('of1', $order) && !$this->discountAppliedToOrder('of2', $order);
-    $this->assertTrue($properly_applied, t('Only discount one applied when discount two is not compatible with any other discount.'));
-
-    // Test compatibility with discount one compatible with any discount
-    // except discount two. Only discount one should be applied.
-    $discount_one_wrapper->commerce_compatibility_strategy = 'except';
-    $discount_one_wrapper->commerce_compatibility_selection = array($discount_two->discount_id);
-    $discount_one_wrapper->save();
-    $discount_two_wrapper->commerce_compatibility_strategy = 'any';
-    $discount_two_wrapper->save();
-    commerce_cart_order_refresh($order);
-
-    $properly_applied = $this->discountAppliedToOrder('of1', $order) && !$this->discountAppliedToOrder('of2', $order);
-    $this->assertTrue($properly_applied, t('Only discount one applied when it is compatible with any discount except discount two.'));
-
-    // Test compatibility with discount two compatible with any discount
-    // except discount one. Only discount one should be applied.
-    $discount_one_wrapper->commerce_compatibility_strategy = 'any';
-    $discount_one_wrapper->save();
-    $discount_two_wrapper->commerce_compatibility_strategy = 'except';
-    $discount_two_wrapper->commerce_compatibility_selection = array($discount_one->discount_id);
-    $discount_two_wrapper->save();
-    commerce_cart_order_refresh($order);
-
-    $properly_applied = $this->discountAppliedToOrder('of1', $order) && !$this->discountAppliedToOrder('of2', $order);
-    $this->assertTrue($properly_applied, t('Only discount one applied when it is compatible with any discount and discount two is compatible with any discount except discount one.'));
-
-    // Test compatibility with discount two compatible with only discount
-    // one. Both discounts should be applied.
-    $discount_two_wrapper->commerce_compatibility_strategy = 'only';
-    $discount_two_wrapper->save();
-    commerce_cart_order_refresh($order);
-
-    $properly_applied = $this->discountAppliedToOrder('of1', $order) && $this->discountAppliedToOrder('of2', $order);
-    $this->assertTrue($properly_applied, t('Both discounts applied when discount one is compatible with any discount and discount two is compatible only with discount one.'));
-
-    // Test compatibility with discount two compatible with only discount
-    // one. Both discounts should be applied.
-    $discount_one_wrapper->commerce_compatibility_strategy = 'only';
-    $discount_one_wrapper->save();
-    $discount_two_wrapper->commerce_compatibility_strategy = 'any';
-    $discount_two_wrapper->save();
-    commerce_cart_order_refresh($order);
-
-    $properly_applied = $this->discountAppliedToOrder('of1', $order) && $this->discountAppliedToOrder('of2', $order);
-    $this->assertTrue($properly_applied, t('Both discounts applied when discount one is only compatible with discount two and discount two is compatible with any discount.'));
-  }
-
-  /**
-   * Test that delete discounts do not cause fatal errors on cart refresh
-   *
-   * @link https://www.drupal.org/node/2538812
-   */
-  public function testCartWithDiscountsDeleted() {
-    // Testing fixed discount.
-    // Create a fixed order discount of $3.
-    /** @var CommerceDiscount $discount */
-    $discount = $this->createDiscount('order_discount', 'fixed_amount', 300);
-
-    // 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 applied on the order total price.
-    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 700, 'Fixed order discount is deducted correctly.');
-
-    // Delete the discount.
-    $discount->delete();
-
-    // Recalculate discounts.
-    $order_wrapper = commerce_cart_order_refresh($order);
-    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 1000, "Fixed order discount is removed when it's not applicable.");
-  }
-}
-
-/**
- * Testing commerce discount usage module UI and functionality.
- */
-class CommerceDiscountUsageTest extends CommerceDiscountTestBase {
-
-  private $store_customer2;
-
-  /**
-   * {@inheritdoc}
-   */
-  public static function getInfo() {
-    return array(
-      'name' => 'Discounts usage',
-      'description' => 'Test discounts usage UI and functionality',
-      'group' => 'Commerce Discount',
-    );
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function setUp() {
-    parent::setUp();
-    $this->store_customer2 = $this->createStoreCustomer();
-  }
-
-  /**
-   * Test usage specific elements in the add discount UI.
-   */
-  public function testCommerceDiscountUsageUIAddDiscount() {
-    // Login with store admin.
-    $this->drupalLogin($this->store_admin);
-
-    // Access to the admin discount creation page.
-    $this->drupalGet('admin/commerce/discounts/add');
-
-    // Check the integrity of the add form.
-    $this->assertFieldByName('commerce_discount_fields[discount_usage_per_person][und][0][value]', NULL, 'Maximum usage per customer field is present');
-    $this->assertFieldByName('commerce_discount_fields[discount_usage_limit][und][0][value]', NULL, 'Maximum overall usage field is present');
-
-    // Create a discount.
-    $values = array(
-      'label' => 'Order discount - fixed',
-      'name' => 'order_discount_fixed',
-      'component_title' => 'Order discount',
-      'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => 12.77,
-      'commerce_discount_fields[discount_usage_limit][und][0][value]' => 5,
-    );
-    $this->drupalPost(NULL, $values, t('Save discount'));
-
-    // Load the discount and wrap it.
-    $discount = entity_load_single('commerce_discount', 1);
-    $discount_wrapper = entity_metadata_wrapper('commerce_discount', $discount);
-
-    // Check the usage fields of the stored discount.
-    $this->assertTrue($discount_wrapper->discount_usage_per_person->value() == 0, 'Discount uses field is empty.');
-    $this->assertTrue($discount_wrapper->discount_usage_limit->value() == 5, 'Discount max uses stored correctly.');
-
-    // Check the discounts listing.
-    $this->assertText(t('@amount available', array('@amount' => 5)), 'Analytics - Max usage is shown.');
-    $this->assertText(t('Used @amount times', array('@amount' => 0)), 'Analytics - Usage is shown.');
-  }
-
-  /**
-   * Test usage specific elements in the edit discount UI.
-   */
-  public function testCommerceDiscountUsageUIEditDiscount() {
-    // Testing fixed discount.
-    // Create a fixed order discount of $3 limited to one use.
-    $discount = $this->createUsageDiscount('order_discount', 'fixed_amount', 300, 1);
-
-    // Login with store admin.
-    $this->drupalLogin($this->store_admin);
-
-    // Access to the admin discount edit page.
-    $this->drupalGet('admin/commerce/discounts/manage/' . $discount->name);
-
-    // Check the integrity of the add form.
-    $this->assertFieldByName('commerce_discount_fields[discount_usage_per_person][und][0][value]', NULL, 'Maximum usage per customer field is present');
-    $this->assertFieldByName('commerce_discount_fields[discount_usage_limit][und][0][value]', NULL, 'Maximum overall usage field is present');
-
-    // Change the discount values.
-    $values = array(
-      'label' => 'Order discount - fixed',
-      'name' => 'order_discount_fixed',
-      'component_title' => 'Order discount',
-      'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => 12.77,
-      'commerce_discount_fields[discount_usage_limit][und][0][value]' => 5,
-    );
-    $this->drupalPost(NULL, $values, t('Save discount'));
-
-    // Load the discount from the database and wrap it.
-    $discounts = entity_load('commerce_discount', array($discount->discount_id), $conditions = array(), $reset = TRUE);
-    $discount_wrapper = entity_metadata_wrapper('commerce_discount', reset($discounts));
-
-    // Check the usage fields of the stored discount.
-    $this->assertEqual($discount_wrapper->discount_usage_per_person->value(), 0, 'Discount uses field is empty.');
-    $this->assertEqual($discount_wrapper->discount_usage_limit->value(), 5, 'Discount max uses stored correctly.');
-
-    // Check the discounts listing.
-    $this->assertText(t('@amount available', array('@amount' => 5)), 'Analytics - Max usage is shown.');
-    $this->assertText(t('Used @amount times', array('@amount' => 0)), 'Analytics - Usage is shown.');
-  }
-
-  /**
-   * Test fixed order discounts.
-   */
-  public function testCommerceDiscountUsageFixedOrderDiscount() {
-    // Testing fixed discount.
-    // Create a fixed order discount of $3 limited to one use.
-    $this->createUsageDiscount('order_discount', 'fixed_amount', 300, 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 applied on the order total price.
-    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 700, 'Fixed order discount is deducted correctly on the first use.');
-
-    // 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, 'Fixed order discount is ignored after maximal usage.');
-  }
-
-  /**
-   * Test percentage order discounts.
-   */
-  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.');
-  }
-
-  /**
-   * Test fixed product discounts.
-   */
-  public function testCommerceDiscountUsageFixedProductDiscount() {
-    $this->createUsageDiscount('product_discount', 'fixed_amount', 300, 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->assertTrue($price['data']['components'][1]['price']['amount'] == -300, 'Fixed 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, 'Fixed product discount is ignored after maximal usage.');
-  }
-
-  /**
-   * Test percentage product discounts.
-   */
-  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.');
-  }
-
-  /**
-   * Create a discount.
-   *
-   * @param string $discount_type
-   *   The discount type; Either 'order_discount' or 'product_discount'.
-   * @param string $offer_type
-   *   The discount offer type; Either 'fixed_amount' or 'percentage'.
-   * @param int $amount
-   *   The discount offer amount.
-   * @param int $max_usage
-   *   Maximal uses for the discount.
-   *
-   * @return object
-   *   The newly created commerce_discount entity.
-   */
-  protected function createUsageDiscount($discount_type, $offer_type, $amount, $max_usage) {
-    // Use the base class to create a discount.
-    $discount = parent::createDiscount($discount_type, $offer_type, $amount);
-
-    // Populate the max usage field.
-    $wrapper = entity_metadata_wrapper('commerce_discount', $discount);
-    $wrapper->discount_usage_limit = $max_usage;
-    $wrapper->save();
-
-    return $wrapper->value();
-  }
-
-}
-
-/**
- * Testing commerce discount usage module UI and functionality.
- */
-class CommerceDiscountDateTest extends CommerceDiscountTestBase {
-
-  /**
-   * The date format used by the date fields.
-   *
-   * @var string
-   */
-  protected $dateFormat = 'm/d/Y';
-
-  /**
-   * The number of seconds in a day (60 * 60 * 24).
-   *
-   * @var int
-   */
-  protected $dayInSeconds = 86400;
-
-  /**
-   * {@inheritdoc}
-   */
-  public static function getInfo() {
-    return array(
-      'name' => 'Discounts date',
-      'description' => 'Test discounts date UI and functionality',
-      'group' => 'Commerce Discount',
-    );
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function setUp() {
-    parent::setUp();
-  }
-
-  /**
-   * Test date specific elements in the add discount UI.
-   */
-  public function testDiscountDateUIAddDiscount() {
-    // Login with store admin.
-    $this->drupalLogin($this->store_admin);
-
-    // Access to the admin discount creation page.
-    $this->drupalGet('admin/commerce/discounts/add');
-
-    // Check the integrity of the add form.
-    $this->assertFieldByName('commerce_discount_fields[commerce_discount_date][und][0][value][date]', NULL, 'Start date field is present');
-    $this->assertFieldByName('commerce_discount_fields[commerce_discount_date][und][0][value2][date]', NULL, 'End date field is present');
-
-    // Create a discount valid from yesterday until tomorrow.
-    $start_time = time() - $this->dayInSeconds;
-    $start_date = date($this->dateFormat, $start_time);
-    $end_time = time() + $this->dayInSeconds;
-    $end_date = date($this->dateFormat, $end_time);
-
-    $values = array(
-      'label' => 'Order discount - fixed',
-      'name' => 'order_discount_fixed',
-      'component_title' => 'Order discount',
-      'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => 12.77,
-      'commerce_discount_fields[commerce_discount_date][und][0][value][date]' => $start_date,
-      'commerce_discount_fields[commerce_discount_date][und][0][value2][date]' => $end_date,
-    );
-    $this->drupalPost(NULL, $values, t('Save discount'));
-
-    // Load the discount and wrap it.
-    $discount = entity_load_single('commerce_discount', 1);
-    $wrapper = entity_metadata_wrapper('commerce_discount', $discount);
-
-    // Check the usage fields of the stored discount.
-    $result_start_date = date($this->dateFormat, $wrapper->commerce_discount_date->value->value());
-    $result_end_date = date($this->dateFormat, $wrapper->commerce_discount_date->value2->value());
-    $this->assertEqual($result_start_date, $start_date, 'Start date is stored correctly.');
-    $this->assertEqual($result_end_date, $end_date, 'End date is stored correctly.');
-
-    // Check the discounts listing.
-    $this->assertText($start_date, 'Start date is shown');
-    $this->assertText($end_date, 'End date is shown');
-  }
-
-  /**
-   * Test the Edit discount UI.
-   */
-  public function testDiscountDateUIEditDiscount() {
-    // Create a discount valid from yesterday until tomorrow.
-    $start_time = time() - $this->dayInSeconds;
-    $end_time = time() + $this->dayInSeconds;
-    $discount = $this->createDateDiscount('order_discount', 'fixed_amount', 300, $start_time, $end_time);
-
-    // Login with store admin.
-    $this->drupalLogin($this->store_admin);
-
-    // Access to the admin discount edit page.
-    $this->drupalGet('admin/commerce/discounts/manage/' . $discount->name);
-
-    // Check the integrity of the add form.
-    $this->assertFieldByName('commerce_discount_fields[commerce_discount_date][und][0][value][date]', NULL, 'Start date field is present');
-    $this->assertFieldByName('commerce_discount_fields[commerce_discount_date][und][0][value2][date]', NULL, 'End date field is present');
-
-    // Change the discount date, to be valid from tomorrow.
-    $start_time = time() + $this->dayInSeconds;
-    $end_time = time() + (2 * $this->dayInSeconds);
-    $start_date = date($this->dateFormat, $start_time);
-    $end_date = date($this->dateFormat, $end_time);
-
-    $values = array(
-      'label' => 'Order discount - fixed',
-      'name' => 'order_discount_fixed',
-      'component_title' => 'Order discount',
-      'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => 12.77,
-      'commerce_discount_fields[commerce_discount_date][und][0][value][date]' => $start_date,
-      'commerce_discount_fields[commerce_discount_date][und][0][value2][date]' => $end_date,
-    );
-
-    $this->drupalPost(NULL, $values, t('Save discount'));
-
-    // Load the discount from the database and wrap it.
-    $discounts = entity_load('commerce_discount', array($discount->discount_id), $conditions = array(), $reset = TRUE);
-    $wrapper = entity_metadata_wrapper('commerce_discount', reset($discounts));
-
-    // Check the usage fields of the stored discount.
-    $result_start_date = date($this->dateFormat, $wrapper->commerce_discount_date->value->value());
-    $result_end_date = date($this->dateFormat, $wrapper->commerce_discount_date->value2->value());
-    $this->assertEqual($result_start_date, $start_date, 'Start date is stored correctly.');
-    $this->assertEqual($result_end_date, $end_date, 'End date is stored correctly.');
-
-    // Check the discounts listing.
-    $this->assertText($start_date, 'Start date is shown');
-    $this->assertText($end_date, 'End date is shown');
-  }
-
-  /**
-   * Test order discount in timespan.
-   */
-  public function testDiscountDateOrderDiscountInTime() {
-    // Create a discount valid from yesterday until tomorrow.
-    $start_time = time() - $this->dayInSeconds;
-    $end_time = time() + $this->dayInSeconds;
-
-    // Testing fixed discount.
-    $this->createDateDiscount('order_discount', 'fixed_amount', 300, $start_time, $end_time);
-
-    // 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 applied on the order total price.
-    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 700, 'Order discount is deducted when in time frame.');
-  }
-
-  /**
-   * Test order discount out of timespan.
-   */
-  public function testDiscountDateOrderDiscountOutOfTime() {
-    // Create a discount valid from tomorrow.
-    $start_time = time() + $this->dayInSeconds;
-    $end_time = time() + 2 * $this->dayInSeconds;
-
-    // Testing fixed discount.
-    // Create a fixed order discount of $3 limited to one use.
-    $this->createDateDiscount('order_discount', 'fixed_amount', 300, $start_time, $end_time);
-
-    // Create an order.
-    $order = $this->createDummyOrder($this->store_customer->uid, array($this->product->product_id => 1), 'completed');
-    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
-    // Check if the discount was applied on the order total price.
-    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 1000, 'Order discount is ignored when out of time frame.');
-  }
-
-  /**
-   * Test product discount in timespan.
-   */
-  public function testDiscountDateProductDiscountInTime() {
-    // Create a discount valid from yesterday until tomorrow.
-    $start_time = time() - $this->dayInSeconds;
-    $end_time = time() + $this->dayInSeconds;
-
-    $this->createDateDiscount('product_discount', 'fixed_amount', 300, $start_time, $end_time);
-
-    // Create an order.
-    $order = $this->createDummyOrder($this->store_customer->uid, array($this->product->product_id => 1), 'completed');
-    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
-    // Invoke line item price re-calculation.
-    $line_item = $order_wrapper->commerce_line_items->get(0)->value();
-    rules_invoke_event('commerce_product_calculate_sell_price', $line_item);
-    // Check if the discount was added as a component to the line item.
-    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
-    $price_data = $line_item_wrapper->commerce_unit_price->data->value();
-    $this->assertEqual($price_data['components'][1]['price']['amount'], -300, 'Product discount is applied when discount is in time frame.');
-  }
-
-  /**
-   * Test product discount out of timespan.
-   */
-  public function testDiscountDateProductDiscountOutOfTime() {
-    // Create a discount valid from tomorrow.
-    $start_time = time() + $this->dayInSeconds;
-    $end_time = time() + (2 * $this->dayInSeconds);
-
-    $this->createDateDiscount('product_discount', 'fixed_amount', 300, $start_time, $end_time);
-
-    // Create an order.
-    $order = $this->createDummyOrder($this->store_customer->uid, array($this->product->product_id => 1), 'completed');
-    $wrapper = entity_metadata_wrapper('commerce_order', $order);
-    // Invoke line item price re-calculation.
-    $line_item = $wrapper->commerce_line_items->get(0)->value();
-    rules_invoke_event('commerce_product_calculate_sell_price', $line_item);
-    // Check if the discount was added as a component to the line item.
-    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
-    $price_data = $line_item_wrapper->commerce_unit_price->data->value();
-    $this->assertTrue(count($price_data['components']) == 1, 'Product discount is ignored when discount is out of time frame.');
-  }
-
-  /**
-   * Create a date discount.
-   *
-   * @param string $discount_type
-   *   The discount type; Either 'order_discount' or 'product_discount'.
-   * @param string $offer_type
-   *   The discount offer type; Either 'fixed_amount' or 'percentage'.
-   * @param int $amount
-   *   The discount offer amount.
-   * @param int $start_time
-   *   Discount valid from.
-   * @param int $end_time
-   *   Discount valid until.
-   *
-   * @return object
-   *   The newly created commerce_discount entity.
-   */
-  protected function createDateDiscount($discount_type, $offer_type, $amount, $start_time, $end_time) {
-    // Use the base class to create a discount.
-    $discount = parent::createDiscount($discount_type, $offer_type, $amount);
-
-    // Populate the date fields.
-    $discount_wrapper = entity_metadata_wrapper('commerce_discount', $discount);
-    $discount_wrapper->commerce_discount_date = array(
-      'value' => $start_time,
-      'value2' => $end_time,
-      'date_type' => 'datestamp',
-    );
-    $discount_wrapper->save();
-
-    return $discount_wrapper->value();
-  }
-
-}
-
-/**
- * Test inline conditions.
- */
-class CommerceDiscountConditionsTest extends CommerceDiscountTestBase {
-  public $products;
-
-  /**
-   * Implementation of getInfo().
-   */
-  public static function getInfo() {
-    return array(
-      'name' => 'Discounts inline conditions',
-      'description' => 'Test discounts inline conditions',
-      'group' => 'Commerce Discount',
-    );
-  }
-
-  /**
-   * Set up our tests by adding some additional products.
-   */
-  public function setUp() {
-    parent::setUp();
-
-    // We need a bunch of products.
-    $this->products['b'] = $this->createDummyProduct('PROD-B', 'Product B', 1000);
-    $this->products['c'] = $this->createDummyProduct('PROD-C', 'Product C', 1000);
-    $this->products['d'] = $this->createDummyProduct('PROD-D', 'Product D', 1000);
-    $this->products['e'] = $this->createDummyProduct('PROD-E', 'Product E', 1000);
-    $this->products['f'] = $this->createDummyProduct('PROD-F', 'Product F', 1000);
-  }
-
-  /**
-   * Tests the 'commerce_order_contains_products' rule.
-   */
-  public function testOrderContainsProductsCondition() {
-    // Build a test matrix.
-    // @see https://www.drupal.org/node/2398113
-    $test_matrix = array(
-      // All of the products, including other products.
-      'all inclusive' => array(
-        'products_in_order' => array('b', 'c', 'd', 'e', 'f'),
-        'results' => array('any' => TRUE, 'all' => TRUE, 'exactly' => FALSE, 'only' => FALSE),
-      ),
-      // All of the products, exclusive of other products.
-      'all exclusive' => array(
-        'products_in_order' => array('c', 'e', 'f'),
-        'results' => array('any' => TRUE, 'all' => TRUE, 'exactly' => TRUE, 'only' => TRUE),
-      ),
-      // Some of the products, including one other product.
-      'some inclusive' => array(
-        'products_in_order' => array('b', 'c'),
-        'results' => array('any' => TRUE, 'all' => FALSE, 'exactly' => FALSE, 'only' => FALSE),
-      ),
-      // Some of the products, exclusively.
-      'some exclusive' => array(
-        'products_in_order' => array('e', 'f'),
-        'results' => array('any' => TRUE, 'all' => FALSE, 'exactly' => FALSE, 'only' => TRUE),
-      ),
-      // None of the products.
-      'none' => array(
-        'products_in_order' => array('b', 'd'),
-        'results' => array('any' => FALSE, 'all' => FALSE, 'exactly' => FALSE, 'only' => FALSE),
-      ),
-    );
-
-    // Set up all of the discount rules.
-    foreach ($test_matrix['none']['results'] as $operator => $result) {
-      $discount = $this->createDiscount('order_discount', 'fixed_amount', 100, 'ic_' . $operator, 1);
-      $discount->inline_conditions[LANGUAGE_NONE][0] = array(
-        'condition_name' => 'commerce_order_contains_products',
-        'condition_settings' => array(
-          'operator' => $operator,
-          'products' => array(
-            array('product_id' => $this->products['c']->product_id),
-            array('product_id' => $this->products['e']->product_id),
-            array('product_id' => $this->products['f']->product_id),
-          ),
-        ),
-      );
-      entity_save('commerce_discount', $discount);
-    }
-
-    // Loop through each element of the test matrix and run the tests.
-    foreach ($test_matrix as $set => $test_details) {
-      $order_products = array();
-
-      // Only add products we want for our test.
-      foreach ($test_details['products_in_order'] as $product_letter) {
-        $order_products[$this->products[$product_letter]->product_id] = 1;
-      }
-
-      // Create a discount with our dummy products.
-      $order = $this->createDummyOrder($this->store_customer->uid, $order_products);
-
-      // Refresh the order to apply the discounts.
-      commerce_cart_order_refresh($order);
-
-      // Check if the discount was applied on the order total price.
-      foreach ($test_details['results'] as $operator => $result) {
-        $this->assertTrue(($this->discountAppliedToOrder('ic_' . $operator, $order) === $result), 'Order discount properly applies with "' . $operator . '" operator to product set: ' . $set . '.', 'Discount');
-      }
-
-      // Delete the order.
-      commerce_order_delete($order->order_id);
-    }
-  }
-
-}
diff --git a/tests/commerce_discount.test b/tests/commerce_discount.test
new file mode 100644
index 0000000..5159429
--- /dev/null
+++ b/tests/commerce_discount.test
@@ -0,0 +1,452 @@
+<?php
+
+/**
+ * @file
+ * Commerce Discounts tests.
+ */
+
+/**
+ * Testing commerce discounts functionality.
+ */
+class CommerceDiscountTest extends CommerceDiscountTestBase {
+  /**
+   * Implementation of getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Discounts',
+      'description' => 'Test discounts functionality',
+      'group' => 'Commerce Discount',
+    );
+  }
+
+  /**
+   * Test the importing of commerce discounts.
+   */
+  public function testCommerceDiscountImport() {
+    $exported_discount = '{
+  "name" : "pf",
+  "label" : "PF",
+  "type" : "product_discount",
+  "status" : "1",
+  "component_title" : "pf",
+  "sort_order" : "10",
+  "commerce_discount_offer" : {
+    "type" : "fixed_amount",
+    "commerce_fixed_amount" : { "und" : [
+        {
+          "amount" : "1200",
+          "currency_code" : "USD",
+          "data" : { "components" : [] }
+        }
+      ]
+    }
+  },
+  "commerce_compatibility_strategy" : { "und" : [ { "value" : "any" } ] },
+  "commerce_compatibility_selection" : [],
+  "commerce_discount_date" : [],
+  "inline_conditions" : [],
+  "discount_usage_per_person" : [],
+  "discount_usage_limit" : []
+}';
+
+    // Import the discount.
+    $import = entity_import('commerce_discount', $exported_discount);
+    $this->assertNotNull($import, 'Entity export JSON imported successfully.');
+    entity_save('commerce_discount', $import);
+
+    // Export the discount to make sure it's identical to the import string.
+    $discount = entity_load_single('commerce_discount', $import->discount_id);
+    $export = entity_export('commerce_discount', $discount);
+    $this->assertTrue($exported_discount == $export, 'Exported discount is identical to its origin.');
+  }
+
+  /**
+   * Test order wrapper cache from order refresh.
+   */
+  public function testCommerceDiscountOrderRefreshWrapper() {
+    // Create a 'free bonus products' product discount.
+    $discount = $this->createDiscount('order_discount', 'free_products', array($this->product->product_id));
+    // 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);
+    $line_items = $order_wrapper->value()->commerce_line_items[LANGUAGE_NONE];
+    $this->assertEqual($order_wrapper->commerce_line_items->count(), count($line_items), 'Number of line items matched');
+
+    // Disable the discount.
+    $discount->status = FALSE;
+    entity_save('commerce_discount', $discount);
+
+    $order_wrapper = commerce_cart_order_refresh($order);
+    $line_items = $order_wrapper->value()->commerce_line_items[LANGUAGE_NONE];
+    $this->assertEqual($order_wrapper->commerce_line_items->count(), count($line_items), 'Number of line items matched');
+  }
+
+  /**
+   * Test fixed order discounts.
+   */
+  public function testCommerceDiscountFixedOrderDiscount() {
+    // Testing fixed discount.
+    // Create a fixed order discount of $3.
+    $discount = $this->createDiscount('order_discount', 'fixed_amount', 300);
+
+    // 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 applied on the order total price.
+    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 700, 'Fixed order discount is deducted correctly.');
+
+    // Disable the discount.
+    $discount->status = FALSE;
+    entity_save('commerce_discount', $discount);
+
+    // Re-save the order.
+    // Check if the discount was applied on the order total price.
+    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
+    $order_wrapper->save();
+
+    // Recalculate discounts.
+    $order_wrapper = commerce_cart_order_refresh($order);
+    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 1000, "Fixed order discount is removed when it's not applicable.");
+  }
+
+  /**
+   * Test percentage order discounts.
+   */
+  public function testCommerceDiscountPercentageOrderDiscount() {
+    // Testing percentage discount.
+    // Create a percentage order discount of 5%.
+    $discount = $this->createDiscount('order_discount', 'percentage', 5);
+    // 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.');
+
+    // Disable the discount.
+    $discount->status = FALSE;
+    entity_save('commerce_discount', $discount);
+
+    // Re-save the order.
+    // Check if the discount was applied on the order total price.
+    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
+    $order_wrapper->save();
+
+    // Recalculate discounts.
+    $order_wrapper = commerce_cart_order_refresh($order);
+    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 1000, "Percentage order discount is removed when it's not applicable.");
+  }
+
+  /**
+   * Test a 100% off product percentage discount.
+   *
+   * A 100% off product-level discount differs from the "Free product" discount
+   * offer type since those are normally used as an "add-on" that is added
+   * without the user's interaction (maybe as part of a package, or bonus);
+   * whereas a 100% off discount should be used for any product purposely added
+   * to a cart order.
+   */
+  public function testCommerceDiscountOneHundredPercentOff() {
+    // Login as the store admin.
+    $this->drupalLogin($this->store_admin);
+
+    // Create a 100% off discount and create a test product.
+    $this->createDiscount('product_discount', 'percentage', 100, 'freebie');
+
+    $product = $this->createDummyProduct('TEST-PRODUCT', 'Test Product', 999);
+
+    // Create the order and apply the freebie discount.
+    $order = $this->createDummyOrder($this->store_admin->uid, array($product->product_id => 1));
+    $order_wrapper = commerce_cart_order_refresh($order);
+
+    $properly_applied = $this->discountAppliedToOrder('freebie', $order);
+    $this->assertTrue($properly_applied, t('100% off discount applied to a product.'));
+
+    // Invoke line item price re-calculation.
+    $line_item = $order_wrapper->commerce_line_items->get(0)->value();
+    rules_invoke_event('commerce_product_calculate_sell_price', $line_item);
+
+    $order_wrapper = commerce_cart_order_refresh($order);
+
+    // Verify that the product is now free.
+    $line_item_wrapper = $order_wrapper->commerce_line_items->get(0);
+    $unit_price = $line_item_wrapper->commerce_unit_price->value();
+
+    $this->assertEqual($unit_price['amount'], 0, 'Product line item unit price amount is properly set to 0.');
+    $this->assertEqual($unit_price['data']['components'][1]['price']['amount'], -999, 'Product line item unit price discount component properly set to 100% of the product price.');
+  }
+
+  /**
+   * Test free bonus products order discounts.
+   */
+  public function testCommerceDiscountFreeProductsOrderDiscount() {
+    // Create 'free bonus products' product discount.
+    $discount = $this->createDiscount('order_discount', 'free_products', array($this->product->product_id));
+    // 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->assertEqual($order_wrapper->commerce_order_total->amount->value(), 1000, 'Free Bonus Products order discount has the price of only one product.');
+    $this->assertEqual($order_wrapper->commerce_line_items->count(), 2, 'Free Bonus Products order discount is added as a line item.');
+
+    // Disable the discount.
+    $discount->status = FALSE;
+    entity_save('commerce_discount', $discount);
+
+    // Re-save the order.
+    // Check if the discount was applied on the order total price.
+    $order_wrapper = commerce_cart_order_refresh($order);
+    $this->assertEqual($order_wrapper->commerce_order_total->amount->value(), 1000, "Free Bonus Products order discount is removed when it's not applicable and price is the same.");
+    $this->assertEqual($order_wrapper->commerce_line_items->count(), 1, "Free Bonus Products order discount is removed when it's not applicable and line item count is only 1");
+  }
+
+  /**
+   * Test fixed product discounts.
+   */
+  public function testCommerceDiscountFixedProductDiscount() {
+    $this->createDiscount('product_discount', 'fixed_amount', 300);
+
+    // Create an order.
+    $order = $this->createDummyOrder($this->store_customer->uid, array($this->product->product_id => 1), 'completed');
+    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
+
+    // Invoke line item price re-calculation.
+    $line_item = $order_wrapper->commerce_line_items->get(0)->value();
+    rules_invoke_event('commerce_product_calculate_sell_price', $line_item);
+
+    // Check if the discount was added as a component to the line item.
+    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
+    $price_data = $line_item_wrapper->commerce_unit_price->data->value();
+
+    $this->assertTrue($price_data['components'][1]['price']['amount'] == -300, 'Fixed product discount is added as a price component to the line item.');
+  }
+
+  /**
+   * Test percentage product discounts.
+   */
+  public function testCommerceDiscountPercentageProductDiscount() {
+    $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 = entity_metadata_wrapper('commerce_order', $order);
+
+    // Invoke line item price re-calculation.
+    $line_item = $order_wrapper->commerce_line_items->get(0)->value();
+    rules_invoke_event('commerce_product_calculate_sell_price', $line_item);
+
+    // Check if the discount was added as a component to the line item.
+    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
+    $price_data = $line_item_wrapper->commerce_unit_price->data->value();
+
+    $this->assertTrue($price_data['components'][1]['price']['amount'] == -50, 'Percentage product discount is added as a price component to the line item.');
+  }
+
+  /**
+   * Test discounted product price display.
+   */
+  public function testCommerceDiscountDiscountedProductPriceDisplay() {
+    // Create a product discount.
+    $this->createDiscount('product_discount', 'fixed_amount', 300);
+    $formatted_discounted_price = '$7.00';
+
+    // Log as a normal user.
+    $this->drupalLogin($this->store_customer);
+
+    $nid = $this->product_node->nid;
+    // View a product node.
+    $this->drupalGet("node/$nid");
+    $product_price = $this->xpath('//div[contains(@class, "field-name-commerce-price")]/div[contains(@class, "field-item")]');
+    $this->assertTrue(trim((string) $product_price[0]->div) == $formatted_discounted_price, 'Discounted product price is shown on product page.');
+
+    // Add a product to the cart.
+    $this->drupalPost('node/' . $this->product_node->nid, array(), t('Add to cart'));
+
+    // View the cart.
+    $this->drupalGet('cart');
+    $product_price = $this->xpath('//td[contains(@class, "views-field-commerce-unit-price")]');
+    $this->assertTrue(trim((string) $product_price[0]->{0}) == $formatted_discounted_price, 'Discounted product price is shown on the cart.');
+  }
+
+  /**
+   * Test multiple fixed order discounts.
+   */
+  public function testCommerceDiscountMultipleFixedOrderDiscounts() {
+    // Create two discounts.
+    $this->createDiscount('order_discount', 'fixed_amount', 300, 'of1');
+    $this->createDiscount('order_discount', 'fixed_amount', 200, 'of2');
+
+    // 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);
+
+    $this->assertTrue($order_wrapper->commerce_discounts->count() == 2, '2 discounts are listed as applied on the order.');
+    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 500, 'Two fixed order discounts are applied on the total price.');
+    $this->assertTrue($order_wrapper->commerce_line_items->count() == 3, 'An order with one product and two fixed order discounts has three line items.');
+    $order_wrapper->save();
+    $this->assertTrue($order_wrapper->commerce_line_items->count() == 3, 'After updating the order it still has three line items.');
+  }
+
+  /**
+   * Test rounding in percentage based product discounts.
+   *
+   * To test the rounding used when adding discount price components to product
+   * line items, we use a 30% discount on a product that costs $10.25. When
+   * rounding was not working correctly, the unit price amount would be set to
+   * $7.18 even though the sum of the unit price's price components would in
+   * fact be $7.17. In reality, since the actual discount amount SHOULD be
+   * rounded up to $3.08 from $3.075, the unit price amount SHOULD be $7.17.
+   * This test ensures that is the case in conjunction with a patch from the
+   * linked issue below.
+   *
+   * @link https://www.drupal.org/node/2468943#comment-10476486
+   */
+  public function testCommerceProductPercentageDiscountRounding() {
+    // Create the 30% discount and $10.25 product.
+    $this->createDiscount('product_discount', 'percentage', 30, 'discount_30_off');
+    $product = $this->createDummyProduct('TEST-PRODUCT', 'Test Product', 1025);
+
+    // Create the order and apply discount.
+    $order = $this->createDummyOrder($this->store_customer->uid, array($product->product_id => 1), 'completed');
+    $order_wrapper = commerce_cart_order_refresh($order);
+
+    // Verify rounding came out properly.
+    $line_item_wrapper = $order_wrapper->commerce_line_items->get(0);
+    $unit_price = $line_item_wrapper->commerce_unit_price->value();
+
+    $this->assertEqual($unit_price['amount'], 717, 'Product line item unit price amount rounded properly for a 30% discount.');
+    $this->assertEqual($unit_price['data']['components'][1]['price']['amount'], -308, 'Product line item unit price discount component properly rounded for a 30% discount.');
+  }
+
+  /**
+   * Test discount compatibility strategies.
+   *
+   * Currently implemented strategies include:
+   * - any: discount is compatible with any other discount.
+   * - except: discount is compatible with any discount except selected ones.
+   * - only: discount is only compatible with selected ones.
+   * - none: discount is not compatible with any other discount.
+   *
+   * Compatibility is checked first to ensure that discounts already on an order
+   * are not incompatible with the discount being added. It is then checked to
+   * ensure the discount being added is not incompatible with any discount that
+   * has already been added to the order.
+   */
+  public function testCommerceDiscountCompatibilityStrategies() {
+    // Create two discounts set to execute one after the other.
+    $discount_one = $this->createDiscount('order_discount', 'fixed_amount', 100, 'of1', 1);
+    $discount_one_wrapper = entity_metadata_wrapper('commerce_discount', $discount_one);
+    $discount_two = $this->createDiscount('order_discount', 'fixed_amount', 200, 'of2', 2);
+    $discount_two_wrapper = entity_metadata_wrapper('commerce_discount', $discount_two);
+
+    // Create an order and recalculate discounts.
+    $order = $this->createDummyOrder($this->store_customer->uid, array($this->product->product_id => 1), 'completed');
+
+    // Test compatibility with both discounts using the "any" strategy. Both
+    // discounts should be applied.
+    commerce_cart_order_refresh($order);
+
+    $properly_applied = $this->discountAppliedToOrder('of1', $order) && $this->discountAppliedToOrder('of2', $order);
+    $this->assertTrue($properly_applied, t('Discount one and two applied when both are compatible with any discount.'));
+
+    // Test compatibility with only discount one using the "none" strategy. Only
+    // discount one should be applied.
+    $discount_one_wrapper->commerce_compatibility_strategy = 'none';
+    $discount_one_wrapper->save();
+    commerce_cart_order_refresh($order);
+
+    $properly_applied = $this->discountAppliedToOrder('of1', $order) && !$this->discountAppliedToOrder('of2', $order);
+    $this->assertTrue($properly_applied, t('Only discount one applied when it is not compatible with any other discount.'));
+
+    // Test compatibility with only discount two using the "none" strategy. Only
+    // discount one should be applied.
+    $discount_one_wrapper->commerce_compatibility_strategy = 'any';
+    $discount_one_wrapper->save();
+    $discount_two_wrapper->commerce_compatibility_strategy = 'none';
+    $discount_two_wrapper->save();
+    commerce_cart_order_refresh($order);
+
+    $properly_applied = $this->discountAppliedToOrder('of1', $order) && !$this->discountAppliedToOrder('of2', $order);
+    $this->assertTrue($properly_applied, t('Only discount one applied when discount two is not compatible with any other discount.'));
+
+    // Test compatibility with discount one compatible with any discount
+    // except discount two. Only discount one should be applied.
+    $discount_one_wrapper->commerce_compatibility_strategy = 'except';
+    $discount_one_wrapper->commerce_compatibility_selection = array($discount_two->discount_id);
+    $discount_one_wrapper->save();
+    $discount_two_wrapper->commerce_compatibility_strategy = 'any';
+    $discount_two_wrapper->save();
+    commerce_cart_order_refresh($order);
+
+    $properly_applied = $this->discountAppliedToOrder('of1', $order) && !$this->discountAppliedToOrder('of2', $order);
+    $this->assertTrue($properly_applied, t('Only discount one applied when it is compatible with any discount except discount two.'));
+
+    // Test compatibility with discount two compatible with any discount
+    // except discount one. Only discount one should be applied.
+    $discount_one_wrapper->commerce_compatibility_strategy = 'any';
+    $discount_one_wrapper->save();
+    $discount_two_wrapper->commerce_compatibility_strategy = 'except';
+    $discount_two_wrapper->commerce_compatibility_selection = array($discount_one->discount_id);
+    $discount_two_wrapper->save();
+    commerce_cart_order_refresh($order);
+
+    $properly_applied = $this->discountAppliedToOrder('of1', $order) && !$this->discountAppliedToOrder('of2', $order);
+    $this->assertTrue($properly_applied, t('Only discount one applied when it is compatible with any discount and discount two is compatible with any discount except discount one.'));
+
+    // Test compatibility with discount two compatible with only discount
+    // one. Both discounts should be applied.
+    $discount_two_wrapper->commerce_compatibility_strategy = 'only';
+    $discount_two_wrapper->save();
+    commerce_cart_order_refresh($order);
+
+    $properly_applied = $this->discountAppliedToOrder('of1', $order) && $this->discountAppliedToOrder('of2', $order);
+    $this->assertTrue($properly_applied, t('Both discounts applied when discount one is compatible with any discount and discount two is compatible only with discount one.'));
+
+    // Test compatibility with discount two compatible with only discount
+    // one. Both discounts should be applied.
+    $discount_one_wrapper->commerce_compatibility_strategy = 'only';
+    $discount_one_wrapper->save();
+    $discount_two_wrapper->commerce_compatibility_strategy = 'any';
+    $discount_two_wrapper->save();
+    commerce_cart_order_refresh($order);
+
+    $properly_applied = $this->discountAppliedToOrder('of1', $order) && $this->discountAppliedToOrder('of2', $order);
+    $this->assertTrue($properly_applied, t('Both discounts applied when discount one is only compatible with discount two and discount two is compatible with any discount.'));
+  }
+
+  /**
+   * Test that delete discounts do not cause fatal errors on cart refresh
+   *
+   * @link https://www.drupal.org/node/2538812
+   */
+  public function testCartWithDiscountsDeleted() {
+    // Testing fixed discount.
+    // Create a fixed order discount of $3.
+    /** @var CommerceDiscount $discount */
+    $discount = $this->createDiscount('order_discount', 'fixed_amount', 300);
+
+    // 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 applied on the order total price.
+    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 700, 'Fixed order discount is deducted correctly.');
+
+    // Delete the discount.
+    $discount->delete();
+
+    // Recalculate discounts.
+    $order_wrapper = commerce_cart_order_refresh($order);
+    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 1000, "Fixed order discount is removed when it's not applicable.");
+  }
+
+}
diff --git a/tests/commerce_discount_base.test b/tests/commerce_discount_base.test
new file mode 100644
index 0000000..4a62a06
--- /dev/null
+++ b/tests/commerce_discount_base.test
@@ -0,0 +1,226 @@
+<?php
+
+/**
+ * @file
+ * Commerce Discounts test base.
+ */
+
+/**
+ * Base class for commerce discount tests.
+ */
+class CommerceDiscountTestBase extends CommerceBaseTestCase {
+
+  /**
+   * Don't need most of default core modules.
+   */
+  protected $profile = 'minimal';
+
+  /**
+   * Dummy commerce_product and related product node.
+   */
+  protected $product;
+  protected $product_node;
+
+  /**
+   * User accounts for testing.
+   */
+  protected $store_admin;
+  protected $store_customer;
+
+  /**
+   * Allows submodules to define themselves for setup.
+   *
+   * @var string
+   */
+  protected $sub_module;
+
+  /**
+   * Overrides CommerceBaseTestCase::permissionBuilder().
+   */
+  protected function permissionBuilder($set) {
+    $permissions = parent::permissionBuilder($set);
+
+    switch ($set) {
+      case 'store admin':
+      case 'site admin':
+        $permissions[] = 'administer commerce discounts';
+        break;
+    }
+
+    return $permissions;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    // Enable all commerce modules + commerce_discount.
+    $modules = parent::setUpHelper('all');
+
+    $modules[] = 'commerce_discount';
+    if ($this->sub_module) {
+      $modules[] = $this->sub_module;
+    }
+    parent::setUp($modules);
+
+    // User creation for different operations.
+    $this->store_admin = $this->createStoreAdmin();
+    $this->store_customer = $this->createStoreCustomer();
+
+    // Create a dummy product.
+    $this->product = $this->createDummyProduct('PROD-01', 'Product One', 1000);
+
+    // Create a dummy product display content type.
+    $this->createDummyProductDisplayContentType();
+
+    // Create a product display node.
+    $this->product_node = $this->createDummyProductNode(array($this->product->product_id), 'Product One node');
+
+    // Set the default country to US.
+    variable_set('site_default_country', 'US');
+  }
+
+  /**
+   * Create a discount.
+   *
+   * @param string $discount_type
+   *   The discount type; Either 'order_discount' or 'product_discount'.
+   * @param string $offer_type
+   *   The discount offer type; Either 'fixed_amount' or 'percentage'.
+   * @param int|array $amount
+   *   The discount offer amount, percentage or product ids array.
+   * @param string $name
+   *   Discount name - Optional. If given, CANNOT start with a number.
+   * @param string $component_title
+   *   Component title - Optional.
+   *
+   * @return object
+   *   The newly created commerce_discount entity.
+   */
+  protected function createDiscount($discount_type, $offer_type, $amount, $name = '', $component_title = '', $sort_order = 10) {
+    // Create the discount offer.
+    $commerce_discount_offer = entity_create('commerce_discount_offer', array('type' => $offer_type));
+    $offer_wrapper = entity_metadata_wrapper('commerce_discount_offer', $commerce_discount_offer);
+    switch ($offer_type) {
+      case 'fixed_amount':
+        $offer_wrapper->commerce_fixed_amount->amount = $amount;
+        $offer_wrapper->commerce_fixed_amount->currency_code = 'USD';
+        break;
+
+      case 'percentage':
+        $offer_wrapper->commerce_percentage = $amount;
+        break;
+
+      case 'free_products':
+        // Product ids array should be provided for $amount.
+        $offer_wrapper->commerce_free_products = $amount;
+        break;
+    }
+
+    $offer_wrapper->save();
+
+    // Provide default name.
+    $name = $name ? $name : $discount_type . '_' . $offer_type;
+    $component_title = $component_title ? $component_title : $name;
+
+    // Create the discount.
+    $values = array(
+      'name' => $name,
+      'label' => $name,
+      'type' => $discount_type,
+      'sort_order' => $sort_order,
+      'component_title' => $component_title,
+      'status' => TRUE,
+      'export_status' => TRUE,
+    );
+    $commerce_discount = entity_create('commerce_discount', $values);
+    $discount_wrapper = entity_metadata_wrapper('commerce_discount', $commerce_discount);
+    $discount_wrapper->commerce_discount_offer = $commerce_discount_offer;
+    $discount_wrapper->save();
+
+    return $discount_wrapper->value();
+  }
+
+  /**
+   * Determines whether or not a discount has been applied to an order.
+   *
+   * @param $discount_name
+   *   The machine-name of the discount to look for.
+   * @param $order
+   *   The order object to inspect for the discount.
+   *
+   * @return bool
+   *   Boolean indicating whether or not the discount is applied to the order.
+   */
+  public function discountAppliedToOrder($discount_name, $order) {
+    // Fetch the list of discounts applied to the order based on the price
+    // components in its order total array.
+    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
+    $order_total = $order_wrapper->commerce_order_total->value();
+    $applied_discounts = commerce_discount_get_discounts_applied_to_price($order_total);
+
+    // Look for the given discount in the list of applied discounts.
+    return in_array($discount_name, $applied_discounts);
+  }
+
+  /**
+   * Create a discount.
+   *
+   * @param string $discount_type
+   *   The discount type; Either 'order_discount' or 'product_discount'.
+   * @param string $offer_type
+   *   The discount offer type; Either 'fixed_amount' or 'percentage'.
+   * @param int $amount
+   *   The discount offer amount.
+   * @param int $max_usage
+   *   Maximal uses for the discount.
+   *
+   * @return object
+   *   The newly created commerce_discount entity.
+   */
+  protected function createUsageDiscount($discount_type, $offer_type, $amount, $max_usage) {
+    // Use the base class to create a discount.
+    $discount = $this->createDiscount($discount_type, $offer_type, $amount);
+
+    // Populate the max usage field.
+    $wrapper = entity_metadata_wrapper('commerce_discount', $discount);
+    $wrapper->discount_usage_limit = $max_usage;
+    $wrapper->save();
+
+    return $wrapper->value();
+  }
+
+  /**
+   * Create a date discount.
+   *
+   * @param string $discount_type
+   *   The discount type; Either 'order_discount' or 'product_discount'.
+   * @param string $offer_type
+   *   The discount offer type; Either 'fixed_amount' or 'percentage'.
+   * @param int $amount
+   *   The discount offer amount.
+   * @param int $start_time
+   *   Discount valid from.
+   * @param int $end_time
+   *   Discount valid until.
+   *
+   * @return object
+   *   The newly created commerce_discount entity.
+   */
+  protected function createDateDiscount($discount_type, $offer_type, $amount, $start_time, $end_time) {
+    // Use the base class to create a discount.
+    $discount = $this->createDiscount($discount_type, $offer_type, $amount);
+
+    // Populate the date fields.
+    $discount_wrapper = entity_metadata_wrapper('commerce_discount', $discount);
+    $discount_wrapper->commerce_discount_date = array(
+      'value' => $start_time,
+      'value2' => $end_time,
+      'date_type' => 'datestamp',
+    );
+    $discount_wrapper->save();
+
+    return $discount_wrapper->value();
+  }
+
+}
diff --git a/tests/commerce_discount_conditions.test b/tests/commerce_discount_conditions.test
new file mode 100644
index 0000000..6b785a5
--- /dev/null
+++ b/tests/commerce_discount_conditions.test
@@ -0,0 +1,116 @@
+<?php
+
+/**
+ * @file
+ * Commerce Discounts inline conditions tests.
+ */
+
+/**
+ * Test inline conditions.
+ */
+class CommerceDiscountConditionsTest extends CommerceDiscountTestBase {
+
+  public $products;
+
+  /**
+   * Implementation of getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Discounts inline conditions',
+      'description' => 'Test discounts inline conditions',
+      'group' => 'Commerce Discount',
+    );
+  }
+
+  /**
+   * Set up our tests by adding some additional products.
+   */
+  public function setUp() {
+    parent::setUp();
+
+    // We need a bunch of products.
+    $this->products['b'] = $this->createDummyProduct('PROD-B', 'Product B', 1000);
+    $this->products['c'] = $this->createDummyProduct('PROD-C', 'Product C', 1000);
+    $this->products['d'] = $this->createDummyProduct('PROD-D', 'Product D', 1000);
+    $this->products['e'] = $this->createDummyProduct('PROD-E', 'Product E', 1000);
+    $this->products['f'] = $this->createDummyProduct('PROD-F', 'Product F', 1000);
+  }
+
+  /**
+   * Tests the 'commerce_order_contains_products' rule.
+   */
+  public function testOrderContainsProductsCondition() {
+    // Build a test matrix.
+    // @see https://www.drupal.org/node/2398113
+    $test_matrix = array(
+      // All of the products, including other products.
+      'all inclusive' => array(
+        'products_in_order' => array('b', 'c', 'd', 'e', 'f'),
+        'results' => array('any' => TRUE, 'all' => TRUE, 'exactly' => FALSE, 'only' => FALSE),
+      ),
+      // All of the products, exclusive of other products.
+      'all exclusive' => array(
+        'products_in_order' => array('c', 'e', 'f'),
+        'results' => array('any' => TRUE, 'all' => TRUE, 'exactly' => TRUE, 'only' => TRUE),
+      ),
+      // Some of the products, including one other product.
+      'some inclusive' => array(
+        'products_in_order' => array('b', 'c'),
+        'results' => array('any' => TRUE, 'all' => FALSE, 'exactly' => FALSE, 'only' => FALSE),
+      ),
+      // Some of the products, exclusively.
+      'some exclusive' => array(
+        'products_in_order' => array('e', 'f'),
+        'results' => array('any' => TRUE, 'all' => FALSE, 'exactly' => FALSE, 'only' => TRUE),
+      ),
+      // None of the products.
+      'none' => array(
+        'products_in_order' => array('b', 'd'),
+        'results' => array('any' => FALSE, 'all' => FALSE, 'exactly' => FALSE, 'only' => FALSE),
+      ),
+    );
+
+    // Set up all of the discount rules.
+    foreach ($test_matrix['none']['results'] as $operator => $result) {
+      $discount = $this->createDiscount('order_discount', 'fixed_amount', 100, 'ic_' . $operator, 1);
+      $discount->inline_conditions[LANGUAGE_NONE][0] = array(
+        'condition_name' => 'commerce_order_contains_products',
+        'condition_settings' => array(
+          'operator' => $operator,
+          'products' => array(
+            array('product_id' => $this->products['c']->product_id),
+            array('product_id' => $this->products['e']->product_id),
+            array('product_id' => $this->products['f']->product_id),
+          ),
+        ),
+      );
+      entity_save('commerce_discount', $discount);
+    }
+
+    // Loop through each element of the test matrix and run the tests.
+    foreach ($test_matrix as $set => $test_details) {
+      $order_products = array();
+
+      // Only add products we want for our test.
+      foreach ($test_details['products_in_order'] as $product_letter) {
+        $order_products[$this->products[$product_letter]->product_id] = 1;
+      }
+
+      // Create a discount with our dummy products.
+      $order = $this->createDummyOrder($this->store_customer->uid, $order_products);
+
+      // Refresh the order to apply the discounts.
+      commerce_cart_order_refresh($order);
+
+      // Check if the discount was applied on the order total price.
+      foreach ($test_details['results'] as $operator => $result) {
+        $this->assertTrue(($this->discountAppliedToOrder('ic_' . $operator, $order) === $result), 'Order discount properly applies with "' . $operator . '" operator to product set: ' . $set . '.', 'Discount');
+      }
+
+      // Delete the order.
+      commerce_order_delete($order->order_id);
+    }
+  }
+
+}
diff --git a/tests/commerce_discount_date.test b/tests/commerce_discount_date.test
new file mode 100644
index 0000000..d364b4d
--- /dev/null
+++ b/tests/commerce_discount_date.test
@@ -0,0 +1,120 @@
+<?php
+
+/**
+ * @file
+ * Commerce Discounts date tests.
+ */
+
+/**
+ * Testing commerce discount date functionality.
+ */
+class CommerceDiscountDateTest extends CommerceDiscountTestBase {
+
+  /**
+   * The number of seconds in a day (60 * 60 * 24).
+   *
+   * @var int
+   */
+  protected $dayInSeconds = 86400;
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Discounts date',
+      'description' => 'Test discounts date functionality',
+      'group' => 'Commerce Discount',
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    parent::setUp();
+  }
+
+  /**
+   * Test order discount in timespan.
+   */
+  public function testDiscountDateOrderDiscountInTime() {
+    // Create a discount valid from yesterday until tomorrow.
+    $start_time = time() - $this->dayInSeconds;
+    $end_time = time() + $this->dayInSeconds;
+
+    // Testing fixed discount.
+    $this->createDateDiscount('order_discount', 'fixed_amount', 300, $start_time, $end_time);
+
+    // 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 applied on the order total price.
+    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 700, 'Order discount is deducted when in time frame.');
+  }
+
+  /**
+   * Test order discount out of timespan.
+   */
+  public function testDiscountDateOrderDiscountOutOfTime() {
+    // Create a discount valid from tomorrow.
+    $start_time = time() + $this->dayInSeconds;
+    $end_time = time() + 2 * $this->dayInSeconds;
+
+    // Testing fixed discount.
+    // Create a fixed order discount of $3 limited to one use.
+    $this->createDateDiscount('order_discount', 'fixed_amount', 300, $start_time, $end_time);
+
+    // Create an order.
+    $order = $this->createDummyOrder($this->store_customer->uid, array($this->product->product_id => 1), 'completed');
+    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
+    // Check if the discount was applied on the order total price.
+    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 1000, 'Order discount is ignored when out of time frame.');
+  }
+
+  /**
+   * Test product discount in timespan.
+   */
+  public function testDiscountDateProductDiscountInTime() {
+    // Create a discount valid from yesterday until tomorrow.
+    $start_time = time() - $this->dayInSeconds;
+    $end_time = time() + $this->dayInSeconds;
+
+    $this->createDateDiscount('product_discount', 'fixed_amount', 300, $start_time, $end_time);
+
+    // Create an order.
+    $order = $this->createDummyOrder($this->store_customer->uid, array($this->product->product_id => 1), 'completed');
+    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
+    // Invoke line item price re-calculation.
+    $line_item = $order_wrapper->commerce_line_items->get(0)->value();
+    rules_invoke_event('commerce_product_calculate_sell_price', $line_item);
+    // Check if the discount was added as a component to the line item.
+    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
+    $price_data = $line_item_wrapper->commerce_unit_price->data->value();
+    $this->assertEqual($price_data['components'][1]['price']['amount'], -300, 'Product discount is applied when discount is in time frame.');
+  }
+
+  /**
+   * Test product discount out of timespan.
+   */
+  public function testDiscountDateProductDiscountOutOfTime() {
+    // Create a discount valid from tomorrow.
+    $start_time = time() + $this->dayInSeconds;
+    $end_time = time() + (2 * $this->dayInSeconds);
+
+    $this->createDateDiscount('product_discount', 'fixed_amount', 300, $start_time, $end_time);
+
+    // Create an order.
+    $order = $this->createDummyOrder($this->store_customer->uid, array($this->product->product_id => 1), 'completed');
+    $wrapper = entity_metadata_wrapper('commerce_order', $order);
+    // Invoke line item price re-calculation.
+    $line_item = $wrapper->commerce_line_items->get(0)->value();
+    rules_invoke_event('commerce_product_calculate_sell_price', $line_item);
+    // Check if the discount was added as a component to the line item.
+    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
+    $price_data = $line_item_wrapper->commerce_unit_price->data->value();
+    $this->assertTrue(count($price_data['components']) == 1, 'Product discount is ignored when discount is out of time frame.');
+  }
+
+}
diff --git a/tests/commerce_discount_date_ui.test b/tests/commerce_discount_date_ui.test
new file mode 100644
index 0000000..a3ec38f
--- /dev/null
+++ b/tests/commerce_discount_date_ui.test
@@ -0,0 +1,141 @@
+<?php
+
+/**
+ * @file
+ * Commerce Discounts date UI tests.
+ */
+
+/**
+ * Testing commerce discount date UI.
+ */
+class CommerceDiscountDateUITest extends CommerceDiscountTestBase {
+
+  /**
+   * The date format used by the date fields.
+   *
+   * @var string
+   */
+  protected $dateFormat = 'm/d/Y';
+
+  /**
+   * The number of seconds in a day (60 * 60 * 24).
+   *
+   * @var int
+   */
+  protected $dayInSeconds = 86400;
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Discounts date UI',
+      'description' => 'Test discounts date UI',
+      'group' => 'Commerce Discount UI',
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    parent::setUp();
+  }
+
+  /**
+   * Test date specific elements in the add discount UI.
+   */
+  public function testDiscountDateUIAddDiscount() {
+    // Login with store admin.
+    $this->drupalLogin($this->store_admin);
+
+    // Access to the admin discount creation page.
+    $this->drupalGet('admin/commerce/discounts/add');
+
+    // Check the integrity of the add form.
+    $this->assertFieldByName('commerce_discount_fields[commerce_discount_date][und][0][value][date]', NULL, 'Start date field is present');
+    $this->assertFieldByName('commerce_discount_fields[commerce_discount_date][und][0][value2][date]', NULL, 'End date field is present');
+
+    // Create a discount valid from yesterday until tomorrow.
+    $start_time = time() - $this->dayInSeconds;
+    $start_date = date($this->dateFormat, $start_time);
+    $end_time = time() + $this->dayInSeconds;
+    $end_date = date($this->dateFormat, $end_time);
+
+    $values = array(
+      'label' => 'Order discount - fixed',
+      'name' => 'order_discount_fixed',
+      'component_title' => 'Order discount',
+      'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => 12.77,
+      'commerce_discount_fields[commerce_discount_date][und][0][value][date]' => $start_date,
+      'commerce_discount_fields[commerce_discount_date][und][0][value2][date]' => $end_date,
+    );
+    $this->drupalPost(NULL, $values, t('Save discount'));
+
+    // Load the discount and wrap it.
+    $discount = entity_load_single('commerce_discount', 1);
+    $wrapper = entity_metadata_wrapper('commerce_discount', $discount);
+
+    // Check the usage fields of the stored discount.
+    $result_start_date = date($this->dateFormat, $wrapper->commerce_discount_date->value->value());
+    $result_end_date = date($this->dateFormat, $wrapper->commerce_discount_date->value2->value());
+    $this->assertEqual($result_start_date, $start_date, 'Start date is stored correctly.');
+    $this->assertEqual($result_end_date, $end_date, 'End date is stored correctly.');
+
+    // Check the discounts listing.
+    $this->assertText($start_date, 'Start date is shown');
+    $this->assertText($end_date, 'End date is shown');
+  }
+
+  /**
+   * Test the Edit discount UI.
+   */
+  public function testDiscountDateUIEditDiscount() {
+    // Create a discount valid from yesterday until tomorrow.
+    $start_time = time() - $this->dayInSeconds;
+    $end_time = time() + $this->dayInSeconds;
+    $discount = $this->createDateDiscount('order_discount', 'fixed_amount', 300, $start_time, $end_time);
+
+    // Login with store admin.
+    $this->drupalLogin($this->store_admin);
+
+    // Access to the admin discount edit page.
+    $this->drupalGet('admin/commerce/discounts/manage/' . $discount->name);
+
+    // Check the integrity of the add form.
+    $this->assertFieldByName('commerce_discount_fields[commerce_discount_date][und][0][value][date]', NULL, 'Start date field is present');
+    $this->assertFieldByName('commerce_discount_fields[commerce_discount_date][und][0][value2][date]', NULL, 'End date field is present');
+
+    // Change the discount date, to be valid from tomorrow.
+    $start_time = time() + $this->dayInSeconds;
+    $end_time = time() + (2 * $this->dayInSeconds);
+    $start_date = date($this->dateFormat, $start_time);
+    $end_date = date($this->dateFormat, $end_time);
+
+    $values = array(
+      'label' => 'Order discount - fixed',
+      'name' => 'order_discount_fixed',
+      'component_title' => 'Order discount',
+      'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => 12.77,
+      'commerce_discount_fields[commerce_discount_date][und][0][value][date]' => $start_date,
+      'commerce_discount_fields[commerce_discount_date][und][0][value2][date]' => $end_date,
+    );
+
+    $this->drupalPost(NULL, $values, t('Save discount'));
+
+    // Load the discount from the database and wrap it.
+    $discounts = entity_load('commerce_discount', array($discount->discount_id), $conditions = array(), $reset = TRUE);
+    $wrapper = entity_metadata_wrapper('commerce_discount', reset($discounts));
+
+    // Check the usage fields of the stored discount.
+    $result_start_date = date($this->dateFormat, $wrapper->commerce_discount_date->value->value());
+    $result_end_date = date($this->dateFormat, $wrapper->commerce_discount_date->value2->value());
+    $this->assertEqual($result_start_date, $start_date, 'Start date is stored correctly.');
+    $this->assertEqual($result_end_date, $end_date, 'End date is stored correctly.');
+
+    // Check the discounts listing.
+    $this->assertText($start_date, 'Start date is shown');
+    $this->assertText($end_date, 'End date is shown');
+  }
+
+}
diff --git a/tests/commerce_discount_ui.test b/tests/commerce_discount_ui.test
new file mode 100644
index 0000000..69eab36
--- /dev/null
+++ b/tests/commerce_discount_ui.test
@@ -0,0 +1,240 @@
+<?php
+
+/**
+ * @file
+ * Commerce Discounts UI tests.
+ */
+
+/**
+ * Testing commerce discounts UI.
+ */
+class CommerceDiscountUITest extends CommerceDiscountTestBase {
+
+  /**
+   * Implementation of getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Discounts',
+      'description' => 'Test discounts UI and functionality',
+      'group' => 'Commerce Discount UI',
+    );
+  }
+
+  /**
+   * Test the importing of commerce discounts.
+   */
+  public function testCommerceDiscountImportUI() {
+    // Login store admin.
+    $this->drupalLogin($this->store_admin);
+
+    // Access to the admin discount creation page.
+    $this->drupalGet('admin/commerce/discounts/import');
+    $this->assertResponse(200, 'Store admin is allowed in the discounts import page');
+  }
+
+  /**
+   * Access to commerce discounts admin.
+   */
+  public function testCommerceDiscountUIAccessDiscountsListing() {
+    // Login with customer.
+    $this->drupalLogin($this->store_customer);
+    // Check the access to the profiles listing.
+    $this->drupalGet('admin/commerce/discounts');
+    $this->assertResponse(403, 'The store customer has no access to discounts administration.');
+
+    // Login with store admin.
+    $this->drupalLogin($this->store_admin);
+    // Check the access to the profiles listing.
+    $this->drupalGet('admin/commerce/discounts');
+    $this->assertResponse(200, 'The store admin has access to discounts administration.');
+
+    // Check the message of no discounts available.
+    $this->assertText(t('No discounts found.'), "'No discounts found.' message is displayed");
+    // Check the add customer profile link.
+    $this->assertRaw(l(t('Add discount'), 'admin/commerce/discounts/add'), "'Add discount' link is present in the page");
+  }
+
+  /**
+   * Test the add discount UI.
+   */
+  public function testCommerceDiscountUIAddDiscount() {
+    // Login with normal user.
+    $this->drupalLogin($this->store_customer);
+
+    // Access to the admin discount creation page.
+    $this->drupalGet('admin/commerce/discounts/add');
+
+    $this->assertResponse(403, 'Normal user is not able to add a discount using the admin interface');
+
+    // Login with store admin.
+    $this->drupalLogin($this->store_admin);
+
+    // Access to the admin discount creation page.
+    $this->drupalGet('admin/commerce/discounts/add');
+
+    $this->assertResponse(200, 'Store admin user is allowed to add a discount using the admin interface');
+
+    // Check the integrity of the add form.
+    $this->assertFieldByName('commerce_discount_type', NULL, 'Discount type field is present');
+    $this->assertFieldByName('label', NULL, 'Label field is present');
+    $this->assertFieldByName('component_title', NULL, 'Name field is present');
+    $this->assertFieldByName('commerce_discount_fields[commerce_discount_offer][und][form][type]', NULL, 'Offer type field is present');
+    $this->assertFieldByName('commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]', NULL, 'Amount field is present');
+    $this->assertFieldByName('status', NULL, 'Status field is present');
+    $this->assertFieldById('edit-submit', t('Save discount'), 'Save discount button is present');
+
+    // Try to save the product and check validation messages.
+    $this->drupalPost(NULL, array(), t('Save discount'));
+
+    $this->assertText(t('Admin title field is required.'), 'Validation message for missing label.');
+    $this->assertText(t('Machine-readable name field is required.'), 'Validation message for missing machine-name.');
+    $this->assertText(t('Fixed amount field is required.'), 'Validation message for missing amount.');
+
+    // Load a clean discount add form.
+    $this->drupalGet('admin/commerce/discounts/add');
+    // Create a discount.
+    $values = array(
+      'label' => 'Order discount - fixed',
+      'name' => 'order_discount_fixed',
+      'component_title' => 'Order discount',
+      'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => 12.77,
+    );
+    $this->drupalPost(NULL, $values, t('Save discount'));
+
+    // Load the discount and wrap it.
+    $discount = entity_load_single('commerce_discount', 1);
+    $discount_wrapper = entity_metadata_wrapper('commerce_discount', $discount);
+
+    // Check the stored discount.
+    $this->assertEqual($discount->label, $values['label'], 'Label stored correctly.');
+    $this->assertEqual($discount->name, 'discount_' . $values['name'], 'Name stored correctly.');
+    $this->assertEqual($discount->export_status, 1, 'Active stored correctly.');
+    $this->assertEqual($discount->component_title, $values['component_title'], 'Name for customer stored correctly.');
+    $this->assertEqual($discount->status, 1, 'Enabled stored correctly.');
+
+    $this->assertEqual($discount_wrapper->commerce_discount_offer->getBundle(), 'fixed_amount', 'Offer type stored correctly.');
+    $this->assertEqual($discount_wrapper->commerce_discount_offer->commerce_fixed_amount->amount->value(), 1277, 'Amount stored correctly.');
+
+    // Check the discounts listing.
+    $this->assertUrl('admin/commerce/discounts', array(), 'Landing page after save is the discounts list.');
+    $this->assertText($values['label'], 'Label of the discount is present.');
+    $this->assertText($values['component_title'], 'Name of the discount is present.');
+  }
+
+  /**
+   * Test the Edit discount UI.
+   */
+  public function testCommerceDiscountUIEditDiscount() {
+    // Create a discount.
+    $discount = $this->createDiscount('order_discount', 'fixed_amount', 300);
+
+    // Login with normal user.
+    $this->drupalLogin($this->store_customer);
+
+    // Access to the admin discount edit page.
+    $this->drupalGet('admin/commerce/discounts/manage/' . $discount->name);
+    $this->assertResponse(403, 'Normal user is not able to edit a discount using the admin interface');
+
+    // Login with store admin.
+    $this->drupalLogin($this->store_admin);
+
+    // Access to the admin discount edit page.
+    $this->drupalGet('admin/commerce/discounts/manage/' . $discount->name);
+    $this->assertResponse(200, 'Store admin user is allowed to edit a discount using the admin interface');
+
+    // Check the integrity of the add form.
+    $this->assertFieldByName('commerce_discount_type', NULL, 'Discount type field is present');
+    $this->assertFieldByName('label', NULL, 'Label field is present');
+    $this->assertFieldByName('component_title', NULL, 'Name field is present');
+    $this->assertFieldByName('commerce_discount_fields[commerce_discount_offer][und][form][type]', NULL, 'Offer type field is present');
+    $this->assertFieldByName('commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]', NULL, 'Amount field is present');
+    $this->assertFieldByName('status', NULL, 'Status field is present');
+    $this->assertFieldById('edit-submit', t('Save discount'), 'Save discount button is present');
+    $this->assertFieldById('edit-delete', t('Delete discount'), 'Delete discount button is present');
+
+    // Empty values for validation assertions.
+    $values = array(
+      'label' => '',
+      'name' => '',
+      'component_title' => '',
+      'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => '',
+    );
+
+    // Try to save the product and check validation messages.
+    $this->drupalPost(NULL, $values, t('Save discount'));
+
+    $this->assertText(t('Admin title field is required.'), 'Validation message for missing label.');
+    $this->assertText(t('Machine-readable name field is required.'), 'Validation message for missing machine-name.');
+    $this->assertText(t('Fixed amount field is required.'), 'Validation message for missing amount.');
+
+    // Discount new values.
+    $values = array(
+      'label' => 'Order discount - fixed',
+      'name' => 'order_discount_fixed',
+      'component_title' => 'Order discount',
+      'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => 12.77,
+    );
+    $this->drupalPost(NULL, $values, t('Save discount'));
+
+    // Load the discount and wrap it.
+    $discounts = entity_load('commerce_discount', array($discount->discount_id), $conditions = array(), $reset = TRUE);
+    $discount = reset($discounts);
+    $discount_wrapper = entity_metadata_wrapper('commerce_discount', $discount);
+
+    // Check the stored discount.
+    $this->assertEqual($discount->label, $values['label'], 'Label stored correctly.');
+    $this->assertEqual($discount->name, 'discount_' . $values['name'], 'Name stored correctly.');
+    $this->assertEqual($discount->component_title, $values['component_title'], 'Name for customer stored correctly.');
+    $this->assertEqual($discount->status, 1, 'Enabled stored correctly.');
+
+    $this->assertEqual($discount_wrapper->commerce_discount_offer->getBundle(), 'fixed_amount', 'Offer type stored correctly.');
+    $this->assertEqual($discount_wrapper->commerce_discount_offer->commerce_fixed_amount->amount->value(), 1277, 'Amount stored correctly.');
+
+    // Check the discounts listing.
+    $this->assertUrl('admin/commerce/discounts', array(), 'Landing page after save is the discounts list.');
+    $this->assertText($values['label'], 'Label of the discount is present.');
+    $this->assertText($values['component_title'], 'Name of the discount is present.');
+  }
+
+  /**
+   * Test the delete discount UI.
+   */
+  public function testCommerceDiscountUIDeleteDiscount() {
+    // Create a discount.
+    $discount = $this->createDiscount('order_discount', 'fixed_amount', 300);
+
+    // Login with normal user.
+    $this->drupalLogin($this->store_customer);
+
+    // Access to the admin discount edit page.
+    $this->drupalGet('admin/commerce/discounts/manage/' . $discount->name . '/delete');
+
+    $this->assertResponse(403, 'Normal user is not able to delete a discount using the admin interface');
+
+    // Login with store admin.
+    $this->drupalLogin($this->store_admin);
+
+    // Access to the admin discount edit page.
+    $this->drupalGet('admin/commerce/discounts/manage/' . $discount->name . '/delete');
+
+    $this->assertResponse(200, 'Store admin user is allowed to delete a discount using the admin interface');
+
+    // Check the integrity of the add form.
+    $this->pass('Test the discount delete confirmation form:');
+    $this->assertTitle(t('Are you sure you want to delete the Commerce Discount !label?', array('!label' => $discount->label)) . ' | Drupal', 'The confirmation message is displayed');
+    $this->assertText(t('This action cannot be undone'), "A warning notifying the user about the action can't be undone is displayed.");
+    $this->assertFieldById('edit-submit', t('Confirm'), 'Delete button is present');
+    $this->assertText(t('Cancel'), 'Cancel is present');
+
+    // Try to save the product and check validation messages.
+    $this->drupalPost(NULL, array(), t('Confirm'));
+
+    // Check the url after deleting and if the discount has been deleted in
+    // database.
+    $this->assertUrl('admin/commerce/discounts', array(), 'Landing page after deleting a discount is the discounts listing page');
+    $this->assertRaw(t('Deleted %type %label.', array('%type' => 'Commerce Discount', '%label' => $discount->label)), "'Discount has been deleted' message is displayed");
+    $this->assertRaw(t('No discounts found.', array('@link' => url('admin/commerce/discounts/add'))), 'Empty discount listing message is displayed');
+  }
+
+}
diff --git a/tests/commerce_discount_usage.test b/tests/commerce_discount_usage.test
new file mode 100644
index 0000000..77ea6a0
--- /dev/null
+++ b/tests/commerce_discount_usage.test
@@ -0,0 +1,128 @@
+<?php
+
+/**
+ * @file
+ * Commerce Discounts usage tests.
+ */
+
+/**
+ * Testing commerce discount usage module functionality.
+ */
+class CommerceDiscountUsageTest extends CommerceDiscountTestBase {
+
+  private $store_customer2;
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Discounts usage',
+      'description' => 'Test discounts usage functionality',
+      'group' => 'Commerce Discount',
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    parent::setUp();
+    $this->store_customer2 = $this->createStoreCustomer();
+  }
+
+  /**
+   * Test fixed order discounts.
+   */
+  public function testCommerceDiscountUsageFixedOrderDiscount() {
+    // Testing fixed discount.
+    // Create a fixed order discount of $3 limited to one use.
+    $this->createUsageDiscount('order_discount', 'fixed_amount', 300, 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 applied on the order total price.
+    $this->assertTrue($order_wrapper->commerce_order_total->amount->value() == 700, 'Fixed order discount is deducted correctly on the first use.');
+
+    // 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, 'Fixed order discount is ignored after maximal usage.');
+  }
+
+  /**
+   * Test percentage order discounts.
+   */
+  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.');
+  }
+
+  /**
+   * Test fixed product discounts.
+   */
+  public function testCommerceDiscountUsageFixedProductDiscount() {
+    $this->createUsageDiscount('product_discount', 'fixed_amount', 300, 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->assertTrue($price['data']['components'][1]['price']['amount'] == -300, 'Fixed 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, 'Fixed product discount is ignored after maximal usage.');
+  }
+
+  /**
+   * Test percentage product discounts.
+   */
+  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.');
+  }
+
+}
diff --git a/tests/commerce_discount_usage_ui.test b/tests/commerce_discount_usage_ui.test
new file mode 100644
index 0000000..f89db85
--- /dev/null
+++ b/tests/commerce_discount_usage_ui.test
@@ -0,0 +1,109 @@
+<?php
+
+/**
+ * @file
+ * Commerce Discounts usage UI tests.
+ */
+
+/**
+ * Testing commerce discount usage module UI.
+ */
+class CommerceDiscountUsageUITest extends CommerceDiscountTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Discounts usage',
+      'description' => 'Test discounts usage UI',
+      'group' => 'Commerce Discount UI',
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    parent::setUp();
+  }
+
+  /**
+   * Test usage specific elements in the add discount UI.
+   */
+  public function testCommerceDiscountUsageUIAddDiscount() {
+    // Login with store admin.
+    $this->drupalLogin($this->store_admin);
+
+    // Access to the admin discount creation page.
+    $this->drupalGet('admin/commerce/discounts/add');
+
+    // Check the integrity of the add form.
+    $this->assertFieldByName('commerce_discount_fields[discount_usage_per_person][und][0][value]', NULL, 'Maximum usage per customer field is present');
+    $this->assertFieldByName('commerce_discount_fields[discount_usage_limit][und][0][value]', NULL, 'Maximum overall usage field is present');
+
+    // Create a discount.
+    $values = array(
+      'label' => 'Order discount - fixed',
+      'name' => 'order_discount_fixed',
+      'component_title' => 'Order discount',
+      'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => 12.77,
+      'commerce_discount_fields[discount_usage_limit][und][0][value]' => 5,
+    );
+    $this->drupalPost(NULL, $values, t('Save discount'));
+
+    // Load the discount and wrap it.
+    $discount = entity_load_single('commerce_discount', 1);
+    $discount_wrapper = entity_metadata_wrapper('commerce_discount', $discount);
+
+    // Check the usage fields of the stored discount.
+    $this->assertTrue($discount_wrapper->discount_usage_per_person->value() == 0, 'Discount uses field is empty.');
+    $this->assertTrue($discount_wrapper->discount_usage_limit->value() == 5, 'Discount max uses stored correctly.');
+
+    // Check the discounts listing.
+    $this->assertText(t('@amount available', array('@amount' => 5)), 'Analytics - Max usage is shown.');
+    $this->assertText(t('Used @amount times', array('@amount' => 0)), 'Analytics - Usage is shown.');
+  }
+
+  /**
+   * Test usage specific elements in the edit discount UI.
+   */
+  public function testCommerceDiscountUsageUIEditDiscount() {
+    // Testing fixed discount.
+    // Create a fixed order discount of $3 limited to one use.
+    $discount = $this->createUsageDiscount('order_discount', 'fixed_amount', 300, 1);
+
+    // Login with store admin.
+    $this->drupalLogin($this->store_admin);
+
+    // Access to the admin discount edit page.
+    $this->drupalGet('admin/commerce/discounts/manage/' . $discount->name);
+
+    // Check the integrity of the add form.
+    $this->assertFieldByName('commerce_discount_fields[discount_usage_per_person][und][0][value]', NULL, 'Maximum usage per customer field is present');
+    $this->assertFieldByName('commerce_discount_fields[discount_usage_limit][und][0][value]', NULL, 'Maximum overall usage field is present');
+
+    // Change the discount values.
+    $values = array(
+      'label' => 'Order discount - fixed',
+      'name' => 'order_discount_fixed',
+      'component_title' => 'Order discount',
+      'commerce_discount_fields[commerce_discount_offer][und][form][commerce_fixed_amount][und][0][amount]' => 12.77,
+      'commerce_discount_fields[discount_usage_limit][und][0][value]' => 5,
+    );
+    $this->drupalPost(NULL, $values, t('Save discount'));
+
+    // Load the discount from the database and wrap it.
+    $discounts = entity_load('commerce_discount', array($discount->discount_id), $conditions = array(), $reset = TRUE);
+    $discount_wrapper = entity_metadata_wrapper('commerce_discount', reset($discounts));
+
+    // Check the usage fields of the stored discount.
+    $this->assertEqual($discount_wrapper->discount_usage_per_person->value(), 0, 'Discount uses field is empty.');
+    $this->assertEqual($discount_wrapper->discount_usage_limit->value(), 5, 'Discount max uses stored correctly.');
+
+    // Check the discounts listing.
+    $this->assertText(t('@amount available', array('@amount' => 5)), 'Analytics - Max usage is shown.');
+    $this->assertText(t('Used @amount times', array('@amount' => 0)), 'Analytics - Usage is shown.');
+  }
+
+}
