public function CommerceDiscountDateUITest::testDiscountDateUIEditDiscount in Commerce Discount 7
Test the Edit discount UI.
File
- tests/
commerce_discount_date_ui.test, line 93 - Commerce Discounts date UI tests.
Class
- CommerceDiscountDateUITest
- Testing commerce discount date UI.
Code
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');
}