function CommerceBpcTestCase::testTwoFieldsTwoListValues in Commerce Bulk Product Creation 7
Test the correct creation of 2x3 combinations.
File
- ./
commerce_bpc.test, line 40 - Tests for Commerce bulk product creation
Class
- CommerceBpcTestCase
- @file Tests for Commerce bulk product creation
Code
function testTwoFieldsTwoListValues() {
$fields = array();
$field = $this
->attachNewListField($this->productType, 2);
$fields[$field['field_name']] = array_keys($field['settings']['allowed_values']);
$field = $this
->attachNewListField($this->productType, 3);
$fields[$field['field_name']] = array_keys($field['settings']['allowed_values']);
$price = rand(2, 500);
$sku_fragment = $this
->randomName(5);
$params = array(
'sku_fragment' => $sku_fragment,
'title_fragment' => $this
->randomName(10),
'commerce_price[' . LANGUAGE_NONE . '][0][amount]' => $price,
'static_values[status]' => 1,
);
foreach ($fields as $name => $vals) {
foreach ($vals as $val) {
$params['combinations[' . $name . '][' . LANGUAGE_NONE . '][' . $val . ']'] = TRUE;
}
}
$bulk_url = 'admin/commerce/products/add-bulk/';
$bulk_url .= $this->productType['type'];
$this
->drupalPost($bulk_url, $params, t('Create products'));
$this
->assertCorrectPermutationsExist($fields, "All permutations of two fields have been created exactly once.");
$n = $this
->getNumberOfProductsWithFieldValues();
$this
->assertEqual($n, 6, 'No other product was created.');
$attributes = array(
'commerce_price' => array(
'field' => 'commerce_price',
// The price is stored in nondecimal form, hence we need to multiply.
'value' => $price * 100,
'column' => 'amount',
),
);
$n = $this
->getNumberOfProductsWithFieldValues($attributes);
$this
->assertEqual($n, 6, "All created products have the correct price.");
$active_products = commerce_product_load_multiple(FALSE, array(
'status' => 1,
));
$this
->assertEqual(count($active_products), 6, "All created products have are active.");
}