You are here

protected function UCDropdownAttributesTestCase::createAttributeOption in Dropdown Attributes 7

Creates an attribute option.

Parameters

array $data: Array of overrides.

bool $save: TRUE or FALSE.

2 calls to UCDropdownAttributesTestCase::createAttributeOption()
UCDropdownAttributesTestCase::testClassAttributeDependency in tests/uc_dropdown_attributes.test
Test for dropdown attributes in product classes.
UCDropdownAttributesTestCase::testProductAttributeDependency in tests/uc_dropdown_attributes.test
Test for dropdown attributes in products.

File

tests/uc_dropdown_attributes.test, line 223
Tests for Dropdown Attributes.

Class

UCDropdownAttributesTestCase
Provides tests for Dropdown Attributes.

Code

protected function createAttributeOption($data = array(), $save = TRUE) {
  $max_aid = db_select('uc_attributes', 'a')
    ->fields('a', array(
    'aid',
  ))
    ->orderBy('aid', 'DESC')
    ->range(0, 1)
    ->execute()
    ->fetchField();
  $option = $data + array(
    'aid' => $max_aid,
    'name' => DrupalWebTestCase::randomName(8),
    'cost' => mt_rand(-500, 500),
    'price' => mt_rand(-500, 500),
    'weight' => mt_rand(-500, 500),
    'ordering' => mt_rand(-10, 10),
  );
  $option = (object) $option;
  if ($save) {
    uc_attribute_option_save($option);
  }
  return $option;
}