protected function CommerceBpcTestCase::attachNewListField in Commerce Bulk Product Creation 7
Attach a new list field with the given number of options to a product type.
Parameters
string $product_type: An array representing the product type to which the field should be attached.
Return value
array An array containing the field specification of the new field.
1 call to CommerceBpcTestCase::attachNewListField()
- CommerceBpcTestCase::testTwoFieldsTwoListValues in ./
commerce_bpc.test - Test the correct creation of 2x3 combinations.
File
- ./
commerce_bpc.test, line 101 - Tests for Commerce bulk product creation
Class
- CommerceBpcTestCase
- @file Tests for Commerce bulk product creation
Code
protected function attachNewListField($product_type, $no_options = 2) {
$field_name = drupal_strtolower($this
->randomName() . '_field_name');
$values = array();
for ($i = 0; $i < $no_options; $i++) {
$values[$this
->randomName(6) . 'val' . $i] = $this
->randomString(10);
}
$field = array(
'field_name' => $field_name,
'type' => 'list_text',
'cardinality' => 1,
'settings' => array(
'allowed_values' => $values,
),
);
$field = field_create_field($field);
$field_id = $field['id'];
$instance = array(
'field_name' => $field_name,
'entity_type' => 'commerce_product',
'bundle' => $product_type['type'],
'label' => $this
->randomName() . '_label',
'description' => $this
->randomName() . '_description',
'weight' => mt_rand(0, 127),
'settings' => array(),
'widget' => array(
'type' => 'options_buttons',
'label' => 'Test Field',
'settings' => array(
'test_widget_setting' => $this
->randomName(),
),
),
);
$instance = field_create_instance($instance);
return $field;
}