You are here

public function UbercartCartLinksTestCase::createCartLinksProduct in Ubercart 6.2

Same name and namespace in other branches
  1. 7.3 uc_cart_links/tests/uc_cart_links.test \UbercartCartLinksTestCase::createCartLinksProduct()

Creates a product with all attribute types and options.

Parameters

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

7 calls to UbercartCartLinksTestCase::createCartLinksProduct()
UbercartCartLinksTestCase::testCartLinksAllowEmptying in uc_cart_links/uc_cart_links.test
Tests cart links on a page under a variety of conditions.
UbercartCartLinksTestCase::testCartLinksBasicFunctionality in uc_cart_links/uc_cart_links.test
Tests cart links on a page under a variety of conditions.
UbercartCartLinksTestCase::testCartLinksMessages in uc_cart_links/uc_cart_links.test
Tests cart links messages.
UbercartCartLinksTestCase::testCartLinksProductActionMessage in uc_cart_links/uc_cart_links.test
Tests cart links on a page under a variety of conditions.
UbercartCartLinksTestCase::testCartLinksRedirect in uc_cart_links/uc_cart_links.test
Tests page redirection for invalid cart links.

... See full list

File

uc_cart_links/uc_cart_links.test, line 723
Ubercart Cart Links Tests.

Class

UbercartCartLinksTestCase
SimpleTests for Ubercart Cart Links.

Code

public function createCartLinksProduct($product_class = FALSE) {

  // Create a product
  if ($product_class) {
    $product = $this
      ->createProductClass();
  }
  else {
    $product = $this
      ->createProduct();
  }

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

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

  // array('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 = drupal_map_assoc(array_rand($attributes, 3));

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

  // add attributes of all 4 types
  // 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->nid, TRUE);
  }
  return $product;
}