public function UbercartProductKitTestCase::testProductKitMutability in Ubercart 7.3
Same name and namespace in other branches
- 6.2 uc_product_kit/uc_product_kit.test \UbercartProductKitTestCase::testProductKitMutability()
Tests product kit mutability.
File
- uc_product_kit/
tests/ uc_product_kit.test, line 148 - Ubercart product kit tests.
Class
- UbercartProductKitTestCase
- Tests product kit functionality.
Code
public function testProductKitMutability() {
$this
->drupalLogin($this->adminUser);
// Create some test products and prepare a kit.
$products = array();
for ($i = 0; $i < 3; $i++) {
$products[$i] = $this
->createProduct();
}
$kit_data = array(
'type' => 'product_kit',
'title' => $this
->randomName(32),
'products' => array(
$products[0]->nid,
$products[1]->nid,
$products[2]->nid,
),
'default_qty' => 1,
'ordering' => 0,
);
// Test kits with no listing.
$kit_data['mutable'] = UC_PRODUCT_KIT_UNMUTABLE_NO_LIST;
$kit = $this
->drupalCreateNode($kit_data);
$this
->drupalGet('node/' . $kit->nid);
$this
->assertText($kit->title, 'Product kit title found.');
$this
->assertNoText($products[0]->title, 'Product 1 title not shown.');
$this
->assertNoText($products[1]->title, 'Product 2 title not shown.');
$this
->assertNoText($products[2]->title, 'Product 3 title not shown.');
$this
->drupalPost('node/' . $kit->nid, array(), 'Add to cart');
$this
->drupalGet('cart');
$this
->assertText($kit->title, 'Product kit title found.');
$this
->assertNoText($products[0]->title, 'Product 1 title not shown.');
$this
->assertNoText($products[1]->title, 'Product 2 title not shown.');
$this
->assertNoText($products[2]->title, 'Product 3 title not shown.');
$total = $products[0]->sell_price + $products[1]->sell_price + $products[2]->sell_price;
$this
->assertText('Subtotal: ' . uc_currency_format($total), 'Product kit total found.');
$qty = mt_rand(2, 10);
$this
->drupalPost(NULL, array(
'items[2][qty]' => $qty,
), 'Update cart');
$this
->assertText('Subtotal: ' . uc_currency_format($total * $qty), 'Updated product kit total found.');
$this
->drupalPost(NULL, array(), 'Remove');
$this
->assertText('There are no products in your shopping cart.');
// Test kits with listing.
$kit_data['mutable'] = UC_PRODUCT_KIT_UNMUTABLE_WITH_LIST;
$kit = $this
->drupalCreateNode($kit_data);
$this
->drupalGet('node/' . $kit->nid);
$this
->assertText($kit->title, 'Product kit title found.');
$this
->assertText($products[0]->title, 'Product 1 title shown.');
$this
->assertText($products[1]->title, 'Product 2 title shown.');
$this
->assertText($products[2]->title, 'Product 3 title shown.');
$this
->drupalPost('node/' . $kit->nid, array(), 'Add to cart');
$this
->drupalGet('cart');
$this
->assertText($kit->title, 'Product kit title found.');
$this
->assertText($products[0]->title, 'Product 1 title shown.');
$this
->assertText($products[1]->title, 'Product 2 title shown.');
$this
->assertText($products[2]->title, 'Product 3 title shown.');
$total = $products[0]->sell_price + $products[1]->sell_price + $products[2]->sell_price;
$this
->assertText('Subtotal: ' . uc_currency_format($total), 'Product kit total found.');
$qty = mt_rand(2, 10);
$this
->drupalPost(NULL, array(
'items[2][qty]' => $qty,
), 'Update cart');
$this
->assertText('Subtotal: ' . uc_currency_format($total * $qty), 'Updated product kit total found.');
$this
->drupalPost(NULL, array(), 'Remove');
$this
->assertText('There are no products in your shopping cart.');
// Test mutable kits.
$kit_data['mutable'] = UC_PRODUCT_KIT_MUTABLE;
$kit = $this
->drupalCreateNode($kit_data);
$this
->drupalGet('node/' . $kit->nid);
$this
->assertText($kit->title, 'Product kit title found.');
$this
->assertText($products[0]->title, 'Product 1 title shown.');
$this
->assertText($products[1]->title, 'Product 2 title shown.');
$this
->assertText($products[2]->title, 'Product 3 title shown.');
$this
->drupalPost('node/' . $kit->nid, array(), 'Add to cart');
$this
->drupalGet('cart');
$this
->assertNoText($kit->title, 'Product kit title not shown.');
$this
->assertText($products[0]->title, 'Product 1 title shown.');
$this
->assertText($products[1]->title, 'Product 2 title shown.');
$this
->assertText($products[2]->title, 'Product 3 title shown.');
$total = $products[0]->sell_price + $products[1]->sell_price + $products[2]->sell_price;
$this
->assertText('Subtotal: ' . uc_currency_format($total), 'Product kit total found.');
$qty = array(
mt_rand(2, 10),
mt_rand(2, 10),
mt_rand(2, 10),
);
$edit = array(
'items[0][qty]' => $qty[0],
'items[1][qty]' => $qty[1],
'items[2][qty]' => $qty[2],
);
$this
->drupalPost(NULL, $edit, 'Update cart');
$total = $products[0]->sell_price * $qty[0];
$total += $products[1]->sell_price * $qty[1];
$total += $products[2]->sell_price * $qty[2];
$this
->assertText('Subtotal: ' . uc_currency_format($total), 'Updated product kit total found.');
$this
->drupalPost(NULL, array(), 'Remove');
$this
->drupalPost(NULL, array(), 'Remove');
$this
->drupalPost(NULL, array(), 'Remove');
$this
->assertText('There are no products in your shopping cart.');
}