public function CommerceTaxUIAdminTest::testCommerceTaxUICreateTaxType in Commerce Core 7
Test the creation of a tax type.
File
- modules/
tax/ tests/ commerce_tax_ui.test, line 354 - Functional tests for the commerce tax UI module.
Class
- CommerceTaxUIAdminTest
- Functional tests for the commerce tax UI module.
Code
public function testCommerceTaxUICreateTaxType() {
// Login with normal user.
$this
->drupalLogin($this->normal_user);
// Access the tax rate types create page.
$this
->drupalGet('admin/commerce/config/taxes/types/add');
// It should return a 403.
$this
->assertResponse(403, t('Normal user is not able to access the tax type creation'));
// Login with store admin user.
$this
->drupalLogin($this->store_admin);
// Access the tax rate types create page.
$this
->drupalGet('admin/commerce/config/taxes/types/add');
// It should return a 200.
$this
->assertResponse(200, t('Store admin user can access the tax type creation'));
// Check the integrity of the creation form.
$this
->pass(t('Test the integrity of the tax type add form:'));
$this
->assertFieldByXPath('//input[@id="edit-tax-type-title" and contains(@class, "required")]', NULL, t('Tax type title field is present and is required'));
$this
->assertFieldById('edit-tax-type-display-title', NULL, t('Tax type display title is present'));
$this
->assertFieldById('edit-tax-type-description', NULL, t('Tax type description is present'));
$this
->assertFieldById('edit-tax-type-display-inclusive', NULL, t('Tax type checkbox for configure inclusive taxes is present'));
$this
->assertFieldById('edit-submit', t('Save tax type'), t('\'Save tax type\' button is present'));
$this
->assertRaw(l(t('Cancel'), 'admin/commerce/config/taxes/types'), t('Cancel link is present'));
// Save the tax type.
$edit = array(
'tax_type[title]' => 'Additional tax type',
'tax_type[name]' => 'additional_tax_rate',
'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 saving and if the tax type loads in the form.
$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 rates listing'));
$this
->assertText($edit['tax_type[name]'], t('Machine name of the tax type is present in the tax rates listing'));
$this
->assertText($edit['tax_type[description]'], t('Description of the tax type is present in the tax rates listing'));
// Check in database if the tax rate has been created.
commerce_tax_types_reset();
$tax_type = commerce_tax_type_load($edit['tax_type[name]']);
$this
->assertFalse(empty($tax_type), t('Tax type is stored in database'));
// Create a tax rate and check that the new tax type is there.
$this
->drupalGet('admin/commerce/config/taxes/rates/add');
$tax_select_types = $this
->xpath('//select[@id="edit-tax-rate-type"]//option');
$this
->assertTrue(in_array($this->tax_type['display_title'], $tax_select_types), t('Tax type is available in the tax rate creation form'));
}