You are here

protected function UbercartTestBase::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.

1 call to UbercartTestBase::createAttribute()
CartLinksTest::createCartLinksProduct in uc_cart_links/src/Tests/CartLinksTest.php
Creates a product with all attribute types and options.

File

uc_store/src/Tests/UbercartTestBase.php, line 161

Class

UbercartTestBase
Base class for Ubercart Simpletest tests.

Namespace

Drupal\uc_store\Tests

Code

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;
}