You are here

public function CommerceTaxUIAdminTest::testCommerceTaxUIApplySalesTax in Commerce Core 7

Check if a 'Salex tax' rate is correctly applied in a given order.

File

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

Class

CommerceTaxUIAdminTest
Functional tests for the commerce tax UI module.

Code

public function testCommerceTaxUIApplySalesTax() {

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

  // Create a dummy order in cart status.
  $order = $this
    ->createDummyOrder($this->normal_user->uid);

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

  // Get the checkout url and navigate to it.
  $links = commerce_line_item_summary_links();
  $this->checkout_url = $links['checkout']['href'];
  $this
    ->drupalGet($this->checkout_url);

  // Check in database if the tax is applied.
  $order = commerce_order_load_multiple(array(
    $order->order_id,
  ), array(), TRUE);
  $order_wrapper = entity_metadata_wrapper('commerce_order', reset($order));
  $order_data = $order_wrapper->commerce_order_total
    ->value();
  $components = commerce_price_component_load($order_data, $tax_rate['price_component']);
  $tax_component = reset($components);
  $this
    ->assertFalse(empty($tax_component), t('Tax is applied in the order'));

  // Tax should be applied in Checkout Review with the correct quantity.
  $this
    ->assertText($tax_rate['display_title'], t('Tax appears in the order summary'));
  $this
    ->assertText(trim(commerce_currency_format($order_data['amount'], $order_data['currency_code'])), t('Tax amount applied appears in the order summary'));
}