public function CommerceDiscountUsageUITest::testCommerceDiscountUsageUIEditDiscount in Commerce Discount 7
Test usage specific elements in the edit discount UI.
File
- tests/
commerce_discount_usage_ui.test, line 71 - Commerce Discounts usage UI tests.
Class
- CommerceDiscountUsageUITest
- Testing commerce discount usage module UI.
Code
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.');
}