You are here

protected function CartLinksTest::createCartLinksProduct in Ubercart 8.4

Creates a product with all attribute types and options.

Parameters

bool $product_class: Defaults to FALSE to create a normal product, set to TRUE to create a product class instead.

6 calls to CartLinksTest::createCartLinksProduct()
CartLinksTest::testCartLinksAllowEmptying in uc_cart_links/src/Tests/CartLinksTest.php
Tests Cart Links cart empty action.
CartLinksTest::testCartLinksBasicFunctionality in uc_cart_links/src/Tests/CartLinksTest.php
Tests Cart Links on a page under a variety of conditions.
CartLinksTest::testCartLinksMessages in uc_cart_links/src/Tests/CartLinksTest.php
Tests Cart Links custom messages.
CartLinksTest::testCartLinksProductActionMessage in uc_cart_links/src/Tests/CartLinksTest.php
Tests Cart Links product action messages.
CartLinksTest::testCartLinksRestrictions in uc_cart_links/src/Tests/CartLinksTest.php
Tests Cart Links restrictions.

... See full list

File

uc_cart_links/src/Tests/CartLinksTest.php, line 731

Class

CartLinksTest
Tests the Cart Links functionality.

Namespace

Drupal\uc_cart_links\Tests

Code

protected function createCartLinksProduct($product_class = FALSE) {

  // Create a product.
  if ($product_class) {
    $product = $this
      ->createProductClass([
      'promote' => 0,
    ]);
  }
  else {
    $product = $this
      ->createProduct([
      'promote' => 0,
    ]);
  }

  // Create some attributes.
  for ($i = 0; $i < 5; $i++) {
    $attribute = $this
      ->createAttribute();
    $attributes[$attribute->aid] = $attribute;
  }

  // Add some options, organizing them by aid and oid.
  $attribute_aids = array_keys($attributes);
  $all_options = [];
  foreach ($attribute_aids as $aid) {
    for ($i = 0; $i < 3; $i++) {
      $option = $this
        ->createAttributeOption([
        'aid' => $aid,
      ]);
      $all_options[$option->aid][$option->oid] = $option;
    }
  }

  // ['required' => TRUE]
  // Get the options.
  $attribute = uc_attribute_load($attribute->aid);

  // Load every attribute we got.
  $attributes_with_options = uc_attribute_load_multiple();

  // Pick 5 keys to check at random.
  $aids = array_rand($attributes, 3);

  // Load the attributes back.
  $loaded_attributes = uc_attribute_load_multiple($aids);

  // @todo Add attributes of all 4 types.
  // @todo Create both required and not required attributes.
  // Add the selected attributes to the product.
  foreach ($loaded_attributes as $loaded_attribute) {
    uc_attribute_subject_save($loaded_attribute, 'product', $product
      ->id(), TRUE);
  }
  return $product;
}