protected function AttributeTestTrait::createAttributeOption in Ubercart 8.4
Creates an attribute option.
Parameters
array $data: Array containing attribute data, with keys corresponding to the columns of the {uc_attribute} table.
bool $save: If TRUE, save attribute option in database.
Return value
array Associative array of attribute option data.
12 calls to AttributeTestTrait::createAttributeOption()
- AttributeTest::testAttributeAddToCart in uc_attribute/
tests/ src/ Functional/ AttributeTest.php - Tests that product in cart has the selected attribute option.
- AttributeTest::testAttributeApi in uc_attribute/
tests/ src/ Functional/ AttributeTest.php - Tests the basic attribute API.
- AttributeTest::testAttributeUiAttributeOptions in uc_attribute/
tests/ src/ Functional/ AttributeTest.php - Tests the attribute options user interface.
- AttributeTest::testAttributeUiAttributeOptionsAdd in uc_attribute/
tests/ src/ Functional/ AttributeTest.php - Tests the "add attribute option" user interface.
- AttributeTest::testAttributeUiAttributeOptionsDelete in uc_attribute/
tests/ src/ Functional/ AttributeTest.php - Tests the "delete attribute option" user interface.
File
- uc_attribute/
tests/ src/ Traits/ AttributeTestTrait.php, line 54
Class
- AttributeTestTrait
- Utility functions to provide products for test purposes.
Namespace
Drupal\Tests\uc_attribute\TraitsCode
protected function createAttributeOption(array $data = [], $save = TRUE) {
$max_aid = \Drupal::database()
->select('uc_attributes', 'a')
->fields('a', [
'aid',
])
->orderBy('aid', 'DESC')
->range(0, 1)
->execute()
->fetchField();
$option = $data + [
'aid' => $max_aid,
'name' => $this
->randomMachineName(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;
}