You are here

public function CommerceTaxUIAdminTest::testCommerceTaxUIApplyVATInclusive in Commerce Core 7

Check if a 'VAT' tax type is correctly applied in a given product.

File

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

Class

CommerceTaxUIAdminTest
Functional tests for the commerce tax UI module.

Code

public function testCommerceTaxUIApplyVATInclusive() {

  // Create a tax rate VAT Type.
  $tax_rate = $this
    ->createDummyTaxRate(array(
    'type' => 'vat',
  ));

  // Create a new product and product display.
  $this
    ->createDummyProductDisplayContentType();
  $product = $this
    ->createDummyProduct();
  $product_node = $this
    ->createDummyProductNode(array(
    $product->product_id,
  ));

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

  // Edit the product to be VAT tax inclusive.
  $this
    ->drupalGet('admin/commerce/products/' . $product->product_id . '/edit');
  $this
    ->drupalPost(NULL, array(
    'commerce_price[und][0][include_tax]' => $tax_rate['name'],
  ), t('Save product'));

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

  // Go to the product display and check if the tax is applied.
  $this
    ->drupalGet('node/' . $product_node->nid);

  // Check the tax applied in database and in the product display.
  $products = commerce_product_load_multiple(array(
    $product->product_id,
  ), array(), TRUE);
  $product = reset($products);
  $price_component = commerce_product_calculate_sell_price($product);
  $this
    ->assertText(trim(commerce_currency_format($price_component['amount'], $price_component['currency_code'])), t('Amount with taxes included corresponds with the amount displayed in the product display page'));
  $components = commerce_price_component_load($price_component, $tax_rate['price_component']);
  $tax_component = reset($components);
  $this
    ->assertFalse(empty($tax_component), t('Tax component is set in the product.'));
  $this
    ->assertTrue($tax_component['included'], t('Tax component is configured to be included in the price'));
}