You are here

public function UbercartTaxesTestCase::testTaxProductClassUpdate in Ubercart 7.3

File

uc_taxes/tests/uc_taxes.test, line 284
Tax tests.

Class

UbercartTaxesTestCase
Tests the tax functionality.

Code

public function testTaxProductClassUpdate() {
  $this
    ->drupalLogin($this->adminUser);

  // Create a new product class.
  $type = strtolower($this
    ->randomName(12));
  $edit = array(
    'pcid' => $type,
    'name' => $type,
    'description' => $this
      ->randomName(32),
  );
  $this
    ->drupalPost('admin/store/products/classes', $edit, t('Save'));
  node_types_rebuild();

  // Create a tax rate.
  $tax = $this
    ->randomName(8);
  $rate = (object) array(
    'id' => 0,
    // TODO: should not have to set this
    'name' => $tax,
    'rate' => rand(1, 20) / 10,
    'taxed_product_types' => array(
      $type,
    ),
    'taxed_line_items' => array(),
    'weight' => 0,
    'shippable' => 0,
  );
  uc_taxes_rate_save($rate);

  // Check that the tax rate shows up at checkout.
  $product = $this
    ->createProduct(array(
    'type' => $type,
  ));
  $this
    ->drupalPost('node/' . $product->nid, array(), t('Add to cart'));
  $this
    ->drupalGet('cart/checkout');
  $this
    ->assertText($tax, 'Tax line item displayed.');

  // Change the machine name of the product class.
  $new_type = strtolower($this
    ->randomName(12));
  $edit = array(
    'name' => $new_type,
    'type' => $new_type,
  );
  $this
    ->drupalPost('admin/structure/types/manage/' . $type, $edit, t('Save content type'));

  // Check that the tax rate still shows up at checkout.
  $this
    ->drupalPost('cart', array(), t('Remove'));
  $this
    ->drupalPost('node/' . $product->nid, array(), t('Add to cart'));
  $this
    ->drupalGet('cart/checkout');
  $this
    ->assertText($tax, 'Tax line item displayed after changing product class node type.');
}