You are here

public function CommerceTaxUIAdminTest::testCommerceTaxUIEditTaxType in Commerce Core 7

Test editing a tax type.

File

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

Class

CommerceTaxUIAdminTest
Functional tests for the commerce tax UI module.

Code

public function testCommerceTaxUIEditTaxType() {

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

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

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

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

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

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

  // Check if the data loaded in the edit form matches with the tax type.
  $this
    ->pass(t('Test if the type is correctly loaded in the edit form:'));
  $this
    ->assertFieldById('edit-tax-type-title', $this->tax_type['title'], t('Title field corresponds with tax type'));
  $this
    ->assertText($this->tax_type['name'], t('Machine name field corresponds with tax type'));
  $this
    ->assertFieldById('edit-tax-type-display-title', $this->tax_type['display_title'], t('Display title field corresponds with tax type'));
  $this
    ->assertFieldById('edit-submit', t('Save tax type'), t('\'Save tax rate\' button is present'));
  $this
    ->assertFieldById('edit-delete', t('Delete tax type'), t('Delete button is present'));
  $this
    ->assertRaw(l(t('Cancel'), 'admin/commerce/config/taxes/types'), t('Cancel link is present'));

  // Modify the tax type and save it.
  $edit = array(
    'tax_type[title]' => 'Additional tax type',
    'tax_type[display_title]' => 'Additional tax rate',
    'tax_type[description]' => 'Additional tax rate for testing',
    'tax_type[display_inclusive]' => 1,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save tax type'));

  // Check the url after edit and if the values have been loaded.
  $this
    ->assertTrue($this->url == url('admin/commerce/config/taxes/types', array(
    'absolute' => TRUE,
  )), t('After saving a tax type we are in the list of tax types'));
  $this
    ->assertText($edit['tax_type[title]'], t('Title of the tax type is present in the tax types listing'));
  $this
    ->assertText($edit['tax_type[description]'], t('Description of the tax type is present in the tax types listing'));
  $this
    ->assertText(t('Tax type saved.'), t('\'Tax type saved\' message is displayed'));

  // Check in database if the tax rate has been correctly modified.
  commerce_tax_types_reset();
  $tax_type = commerce_tax_type_load($this->tax_type['name']);
  $this
    ->assertTrue($tax_type['title'] == $edit['tax_type[title]'], t('Title of the tax type has been correctly modified in the database'));
  $this
    ->assertTrue($tax_type['display_title'] == $edit['tax_type[display_title]'], t('Display title of the tax type has been correctly modified in the database'));
  $this
    ->assertTrue($tax_type['description'] == $edit['tax_type[description]'], t('Description of the tax type has been correctly modified in the database'));
  $this
    ->assertTrue($tax_type['display_inclusive'] == $edit['tax_type[display_inclusive]'], t('Display inclusive option of the tax type has been correctly modified in the database'));
}