You are here

public function CommerceTaxUIAdminTest::testCommerceTaxUITaxNoMatchingCondition in Commerce Core 7

A tax rate with no matching condition doesn't get applied.

File

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

Class

CommerceTaxUIAdminTest
Functional tests for the commerce tax UI module.

Code

public function testCommerceTaxUITaxNoMatchingCondition() {

  // 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 store admin user.
  $this
    ->drupalLogin($this->store_admin);

  // Modify the tax rate to no match condition.
  $this
    ->drupalGet('admin/config/workflow/rules/components/manage/' . $tax_rate['rules_component']);
  $this
    ->clickLink(t('Add condition'));
  $this
    ->drupalPost(NULL, array(
    'element_name' => 'data_is',
  ), t('Continue'));
  $this
    ->drupalPost(NULL, array(
    'parameter[data][settings][data:select]' => 'commerce-line-item:commerce-total:amount',
  ), t('Continue'));
  $this
    ->drupalPost(NULL, array(
    'parameter[op][settings][op]' => '<',
    'parameter[value][settings][value]' => '0',
  ), t('Save'));

  // 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);

  // As the condition is impossible to match, tax rate shouldn't be applied.
  $this
    ->assertNoText($tax_rate['display_title'], t('Tax rate doesn\'t match the conditions and is not present in the cart review pane.'));

  // Also check it at database level.
  $orders = commerce_order_load_multiple(array(
    $order->order_id,
  ), array(), TRUE);
  $order = reset($orders);
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $components = commerce_price_component_load($order_wrapper->commerce_order_total
    ->value(), $tax_rate['price_component']);
  $tax_component = reset($components);
  $this
    ->assertTrue(empty($tax_component), t('Tax component is not set in the order.'));
}