You are here

public function CommerceDiscountUITest::testCommerceDiscountUIDeleteDiscount in Commerce Discount 7

Test the delete discount UI.

File

tests/commerce_discount_ui.test, line 201
Commerce Discounts UI tests.

Class

CommerceDiscountUITest
Testing commerce discounts UI.

Code

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');
}