You are here

public function CommerceTaxUIAdminTest::testCommerceTaxUIDeleteTaxType in Commerce Core 7

Test deleting a tax type.

File

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

Class

CommerceTaxUIAdminTest
Functional tests for the commerce tax UI module.

Code

public function testCommerceTaxUIDeleteTaxType() {

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

  // Access the tax rate type delete page.
  $this
    ->drupalGet('admin/commerce/config/taxes/types/' . strtr($this->tax_type['name'], '_', '-') . '/delete');

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

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

  // Access the tax rate type delete page.
  $this
    ->drupalGet('admin/commerce/config/taxes/types/' . strtr($this->tax_type['name'], '_', '-') . '/delete');

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

  // Check the integrity of the tax type delete confirmation form.
  $this
    ->pass('Test the tax type delete confirmation form:');
  $this
    ->assertTitle(t('Are you sure you want to delete the !title tax type?', array(
    '!title' => $this->tax_type['title'],
  )) . ' | Drupal', t('The confirmation message for deleting a tax type 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'));

  // Delete the tax type.
  $this
    ->drupalPost(NULL, array(), t('Delete'));

  // Check the url after deleting and if the tax type has been deleted in
  // database.
  $this
    ->assertTrue($this->url == url('admin/commerce/config/taxes/types', array(
    'absolute' => TRUE,
  )), t('Landing page after deleting a tax type is the tax types listing page'));
  $this
    ->assertRaw(t('The tax type %title has been deleted.', array(
    '%title' => $this->tax_type['title'],
  )), t('\'Tax type has been deleted\' message is displayed'));
  commerce_tax_types_reset();
  $tax_type = commerce_tax_rate_load($this->tax_type['name']);
  $this
    ->assertTrue(empty($tax_type), t('Tax type is correctly deleted from database'));
}