public function CommerceTaxUIAdminTest::testCommerceTaxUIEditTaxRate in Commerce Core 7
Test editing a tax rate.
File
- modules/
tax/ tests/ commerce_tax_ui.test, line 171 - Functional tests for the commerce tax UI module.
Class
- CommerceTaxUIAdminTest
- Functional tests for the commerce tax UI module.
Code
public function testCommerceTaxUIEditTaxRate() {
// Create a tax rate.
$tax_rate = $this
->createDummyTaxRate();
// Login with normal user.
$this
->drupalLogin($this->normal_user);
// Access the edit page for tax rates.
$this
->drupalGet('admin/commerce/config/taxes/rates/' . strtr($tax_rate['name'], '_', '-') . '/edit');
// It should return a 403.
$this
->assertResponse(403, t('Normal user is not able to access the tax rate edit page'));
// Login with store admin user.
$this
->drupalLogin($this->store_admin);
// Access the edit page for tax rates.
$this
->drupalGet('admin/commerce/config/taxes/rates/' . strtr($tax_rate['name'], '_', '-') . '/edit');
// It should return a 200.
$this
->assertResponse(200, t('Store admin user can access the tax rate edit page'));
// Check if the data loaded in the edit form matches with the tax rate.
$this
->pass(t('Test if the rate is correctly loaded in the edit form:'));
$this
->assertFieldById('edit-tax-rate-title', $tax_rate['title'], t('Title field corresponds with tax rate'));
$this
->assertText($tax_rate['name'], t('Machine name field corresponds with tax rate'));
$this
->assertFieldById('edit-tax-rate-display-title', $tax_rate['display_title'], t('Display title field corresponds with tax rate'));
$this
->assertFieldById('edit-tax-rate-rate', $tax_rate['rate'], t('Rate field corresponds with tax rate'));
$this
->assertOptionSelected('edit-tax-rate-type', $tax_rate['type'], t('Type select value corresponds with tax rate'));
$this
->assertFieldById('edit-submit', t('Save tax rate'), t('\'Save tax rate\' button is present'));
$this
->assertFieldById('edit-delete', t('Delete tax rate'), t('Delete button is present'));
$this
->assertRaw(l(t('Cancel'), 'admin/commerce/config/taxes'), t('Cancel link is present'));
// Modify tax rate information and save the form.
$edit = array(
'tax_rate[title]' => 'Altered tax rate',
'tax_rate[display_title]' => 'Altered tax rate',
'tax_rate[description]' => 'Altered tax rate for testing',
'tax_rate[rate]' => $tax_rate['rate'] + rand(1, 100) / 1000,
'tax_rate[type]' => 'vat',
);
$this
->drupalPost(NULL, $edit, t('Save tax rate'));
// Check the url after edit and if the values have been loaded.
$this
->assertTrue($this->url == url('admin/commerce/config/taxes', array(
'absolute' => TRUE,
)), t('After saving a tax rate we are in the list of tax rates'));
$this
->assertText($edit['tax_rate[title]'], t('Title of the tax rate is present in the tax rates listing'));
$this
->assertText($edit['tax_rate[description]'], t('Description of the tax rate is present in the tax rates listing'));
$this
->assertText(trim($edit['tax_rate[rate]']), t('Rate value of the tax rate is present in the tax rates listing'));
$this
->assertText(t('Tax rate saved.'), t('\'Tax rate saved\' message is displayed'));
// Check in database if the tax rate has been correctly modified.
commerce_tax_rates_reset();
$tax_rate = commerce_tax_rate_load($tax_rate['name']);
$this
->assertFalse(empty($tax_rate), t('Tax is present in database'));
$this
->assertTrue($tax_rate['title'] = $edit['tax_rate[title]'], t('Tax title is correctly saved in database'));
$this
->assertTrue($tax_rate['display_title'] = $edit['tax_rate[display_title]'], t('Tax display title is correctly saved in database'));
$this
->assertTrue($tax_rate['description'] = $edit['tax_rate[description]'], t('Tax description is correctly saved in database'));
$this
->assertTrue($tax_rate['rate'] = $edit['tax_rate[rate]'], t('Tax rate is correctly saved in database'));
$this
->assertTrue($tax_rate['type'] = $edit['tax_rate[type]'], t('Tax type is correctly saved in database'));
}