protected function AttributeTestTrait::createAttribute in Ubercart 8.4
Creates an attribute.
Parameters
array $data: (optional) An associative array of attribute initialization data.
bool $save: If TRUE, save attribute in database.
Return value
array Associative array of attribute data.
18 calls to AttributeTestTrait::createAttribute()
- 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::testAttributeUiAddAttribute in uc_attribute/
tests/ src/ Functional/ AttributeTest.php - Tests the "add attribute" user interface.
- 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.
File
- uc_attribute/
tests/ src/ Traits/ AttributeTestTrait.php, line 25
Class
- AttributeTestTrait
- Utility functions to provide products for test purposes.
Namespace
Drupal\Tests\uc_attribute\TraitsCode
protected function createAttribute(array $data = [], $save = TRUE) {
$attribute = $data + [
'name' => $this
->randomMachineName(8),
'label' => $this
->randomMachineName(8),
'description' => $this
->randomMachineName(8),
'required' => mt_rand(0, 1) ? TRUE : FALSE,
'display' => mt_rand(0, 3),
'ordering' => mt_rand(-10, 10),
];
$attribute = (object) $attribute;
if ($save) {
uc_attribute_save($attribute);
}
return $attribute;
}