public function CommercePricelistTestCaseSimpleProduct::testCommercePricelistItemAdd in Commerce Pricelist 7
Test if the price of a product changes when a price list item is added.
File
- tests/
commerce_pricelist.test, line 186 - Functional tests for the commerce price list module.
Class
- CommercePricelistTestCaseSimpleProduct
- Test price list features for a product display that only has one product attached.
Code
public function testCommercePricelistItemAdd() {
// Log in as a normal user to test price list process.
$this
->drupalLogin($this->store_customer);
// Add pricelist item.
$item_a = $this
->createDummyPricelistItem();
$item_b = $this
->createDummyPricelistItem(array(
'price_amount' => 75,
'quantity' => 2,
));
// Go to product display page
$this
->drupalGet('node/' . $this->product_node->nid);
$this
->assertRaw(t('Add to cart'), t('Product was correctly enabled.'));
$this
->assertText('$1.00', t('Product price was correctly set from price list.'));
// Add to product to cart.
$this
->drupalPost('node/' . $this->product_node->nid, array(), t('Add to cart'));
// Go to cart.
$this
->drupalGet($this
->getCommerceUrl('cart'));
// Change quantity in the cart view form.
// We search for the first quantity field in the html and change the
// amount there.
$qty = $this
->xpath("//input[starts-with(@name, 'edit_quantity')]");
$this
->drupalPost($this
->getCommerceUrl('cart'), array(
(string) $qty[0]['name'] => 2,
), t('Update cart'));
// Check if the amount has been really changed.
$this
->assertText('$0.75', t('Product price was correctly set from price list for different quantities.'));
// Clean up.
commerce_pricelist_item_delete($item_a->item_id);
commerce_pricelist_item_delete($item_b->item_id);
}