public function UbercartTaxesTestCase::testInclusiveTaxes in Ubercart 7.3
File
- uc_taxes/tests/uc_taxes.test, line 30
- Tax tests.
Class
- UbercartTaxesTestCase
- Tests the tax functionality.
Code
public function testInclusiveTaxes() {
$this
->drupalLogin($this->adminUser);
$rate = (object) array(
'name' => $this
->randomName(8),
'rate' => 0.2,
'taxed_product_types' => array(
'product',
),
'taxed_line_items' => array(),
'weight' => 0,
'shippable' => 0,
'display_include' => 1,
'inclusion_text' => $this
->randomName(6),
);
uc_taxes_rate_save($rate);
entity_flush_caches();
$product = $this
->createProduct(array(
'sell_price' => 10,
));
$attribute = (object) array(
'name' => $this
->randomName(8),
'label' => $this
->randomName(8),
'description' => $this
->randomName(8),
'required' => TRUE,
'display' => 1,
'ordering' => 0,
);
uc_attribute_save($attribute);
$option = (object) array(
'aid' => $attribute->aid,
'name' => $this
->randomName(8),
'cost' => 0,
'price' => 5,
'weight' => 0,
'ordering' => 0,
);
uc_attribute_option_save($option);
$attribute = uc_attribute_load($attribute->aid);
uc_attribute_subject_save($attribute, 'product', $product->nid, TRUE);
$kit = $this
->drupalCreateNode(array(
'type' => 'product_kit',
'products' => array(
$product->nid,
),
'ordering' => 0,
'mutable' => UC_PRODUCT_KIT_UNMUTABLE_WITH_LIST,
'default_qty' => 1,
));
$kit = node_load($kit->nid);
$kit->kit_total = 9;
node_save($kit);
$kit = node_load($kit->nid);
$this
->assertEqual($kit->products[$product->nid]->discount, -1, 'Product kit component has correct discount applied.');
$this
->drupalGet('node/' . $kit->nid);
$this
->assertText('$10.80' . $rate->inclusion_text, 'Tax inclusive price on node-view form is accurate.');
$this
->assertRaw($option->name . ', +$6.00</option>', 'Tax inclusive option price on node view form is accurate.');
$attribute_key = 'products[' . $product->nid . '][attributes][' . $attribute->aid . ']';
$this
->drupalPost('node/' . $kit->nid, array(
$attribute_key => $option->oid,
), t('Add to cart'));
$this
->drupalGet('cart');
$this
->assertText('Subtotal: $16.80', 'Order subtotal is correct on cart page.');
$this
->drupalPost('cart', array(), 'Checkout');
$this
->assertText('Subtotal: $16.80', 'Order subtotal is correct on checkout page.');
$zone_id = db_query_range('SELECT zone_id FROM {uc_zones} WHERE zone_country_id = :country ORDER BY rand()', 0, 1, array(
'country' => variable_get('uc_store_country', 840),
))
->fetchField();
$edit = array(
'panes[delivery][delivery_first_name]' => $this
->randomName(10),
'panes[delivery][delivery_last_name]' => $this
->randomName(10),
'panes[delivery][delivery_street1]' => $this
->randomName(10),
'panes[delivery][delivery_city]' => $this
->randomName(10),
'panes[delivery][delivery_zone]' => $zone_id,
'panes[delivery][delivery_postal_code]' => mt_rand(10000, 99999),
'panes[billing][billing_first_name]' => $this
->randomName(10),
'panes[billing][billing_last_name]' => $this
->randomName(10),
'panes[billing][billing_street1]' => $this
->randomName(10),
'panes[billing][billing_city]' => $this
->randomName(10),
'panes[billing][billing_zone]' => $zone_id,
'panes[billing][billing_postal_code]' => mt_rand(10000, 99999),
);
$this
->drupalPost('cart/checkout', $edit, t('Review order'));
$this
->assertRaw(t('Your order is almost complete.'));
$this
->assertText('$16.80' . $rate->inclusion_text, 'Tax inclusive price appears in cart pane on checkout review page');
$order_id = db_query("SELECT order_id FROM {uc_orders} WHERE delivery_first_name = :name", array(
':name' => $edit['panes[delivery][delivery_first_name]'],
))
->fetchField();
$this
->assertTrue($order_id, 'Order was created successfully');
$this
->drupalGet('admin/store/orders/' . $order_id);
$this
->assertText('$16.80' . $rate->inclusion_text, 'Tax inclusive price appears on the order view page.');
$this
->drupalGet('admin/store/orders/' . $order_id . '/invoice');
$this
->assertText('$16.80' . $rate->inclusion_text, 'Tax inclusive price appears on the invoice.');
$this
->drupalGet('admin/store/orders/' . $order_id . '/invoice');
$this
->assertText('$16.80' . $rate->inclusion_text, 'Tax inclusive price appears on the printable invoice.');
}