public function UbercartProductKitTestCase::testProductKitNodeForm in Ubercart 7.3
Same name and namespace in other branches
- 6.2 uc_product_kit/uc_product_kit.test \UbercartProductKitTestCase::testProductKitNodeForm()
Tests creating product kits through the node form.
File
- uc_product_kit/
tests/ uc_product_kit.test, line 31 - Ubercart product kit tests.
Class
- UbercartProductKitTestCase
- Tests product kit functionality.
Code
public function testProductKitNodeForm() {
$this
->drupalLogin($this->adminUser);
// Allow the default quantity to be set.
variable_set('uc_product_add_to_cart_qty', TRUE);
// Create some test products.
$products = array();
for ($i = 0; $i < 3; $i++) {
$products[$i] = $this
->createProduct();
}
// Test the product kit fields.
$this
->drupalGet('node/add/product-kit');
foreach (array(
'mutable',
'products[]',
'ordering',
) as $field) {
$this
->assertFieldByName($field);
}
// Test creation of a basic kit.
$body_key = 'body[und][0][value]';
$edit = array(
'title' => $this
->randomName(32),
$body_key => $this
->randomName(64),
'products[]' => array(
$products[0]->nid,
$products[1]->nid,
$products[2]->nid,
),
'default_qty' => mt_rand(2, 100),
);
$this
->drupalPost('node/add/product-kit', $edit, 'Save');
$this
->assertText(t('Product kit @title has been created.', array(
'@title' => $edit['title'],
)));
$this
->assertText($edit[$body_key], 'Product kit body found.');
$this
->assertText('1 × ' . $products[0]->title, 'Product 1 title found.');
$this
->assertText('1 × ' . $products[1]->title, 'Product 2 title found.');
$this
->assertText('1 × ' . $products[2]->title, 'Product 3 title found.');
$total = $products[0]->sell_price + $products[1]->sell_price + $products[2]->sell_price;
$this
->assertText(uc_currency_format($total), 'Product kit total found.');
$this
->assertFieldByName('qty', $edit['default_qty']);
}