You are here

public function CommerceTaxUIAdminTest::testCommerceTaxUIDeleteTaxRate in Commerce Core 7

Test deleting a tax rate.

File

modules/tax/tests/commerce_tax_ui.test, line 235
Functional tests for the commerce tax UI module.

Class

CommerceTaxUIAdminTest
Functional tests for the commerce tax UI module.

Code

public function testCommerceTaxUIDeleteTaxRate() {

  // Create a tax rate.
  $tax_rate = $this
    ->createDummyTaxRate();

  // Login with normal user.
  $this
    ->drupalLogin($this->normal_user);

  // Access the deletion page for tax rates.
  $this
    ->drupalGet('admin/commerce/config/taxes/rates/' . strtr($tax_rate['name'], '_', '-') . '/delete');

  // It should return a 403.
  $this
    ->assertResponse(403, t('Normal user is not able to access the delete form of a tax rate'));

  // Login with store admin user.
  $this
    ->drupalLogin($this->store_admin);

  // Access the deletion page for tax rates.
  $this
    ->drupalGet('admin/commerce/config/taxes/rates/' . strtr($tax_rate['name'], '_', '-') . '/delete');

  // It should return a 200.
  $this
    ->assertResponse(200, t('Store admin user can access the delete form of a tax rate'));

  // Check the integrity of the tax rate delete confirmation form.
  $this
    ->pass('Test the tax rate delete confirmation form:');
  $this
    ->assertTitle(t('Are you sure you want to delete the !title tax rate?', array(
    '!title' => $tax_rate['title'],
  )) . ' | Drupal', t('The confirmation message is displayed'));
  $this
    ->assertText(t('This action cannot be undone'), t('A warning notifying the user about the action can\'t be undone is displayed.'));
  $this
    ->assertFieldById('edit-submit', t('Delete'), t('Delete button is present'));
  $this
    ->assertText(t('Cancel'), t('Cancel is present'));

  // Confirm delete.
  $this
    ->drupalPost(NULL, array(), t('Delete'));

  // Check the url after deleting and if the tax rate has been deleted in
  // database.
  $this
    ->assertTrue($this->url == url('admin/commerce/config/taxes', array(
    'absolute' => TRUE,
  )), t('Landing page after deleting a tax rate is the tax rates listing page'));
  $this
    ->assertRaw(t('The tax rate %title has been deleted.', array(
    '%title' => $tax_rate['title'],
  )), t('\'Tax rate has been deleted\' message is displayed'));
  $this
    ->assertRaw(t('There are no tax rates yet. <a href="@link">Add a tax rate</a>.', array(
    '@link' => url('admin/commerce/config/taxes/rates/add'),
  )), t('Empty tax rate listing message is displayed'));
  commerce_tax_rates_reset();
  $tax_rate = commerce_tax_rate_load($tax_rate['name']);
  $this
    ->assertTrue(empty($tax_rate), t('Tax is correctly deleted from database'));
}