You are here

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

1 call to UbercartTestBase::createAttributeOption()
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 190

Class

UbercartTestBase
Base class for Ubercart Simpletest tests.

Namespace

Drupal\uc_store\Tests

Code

protected function createAttributeOption(array $data = [], $save = TRUE) {
  $max_aid = db_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;
}