protected function UbercartCartLinksTestCase::createCartLinksProduct in Ubercart 7.3
Same name and namespace in other branches
- 6.2 uc_cart_links/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.
6 calls to UbercartCartLinksTestCase::createCartLinksProduct()
- UbercartCartLinksTestCase::testCartLinksAllowEmptying in uc_cart_links/
tests/ uc_cart_links.test - Tests Cart Links cart empty action.
- UbercartCartLinksTestCase::testCartLinksBasicFunctionality in uc_cart_links/
tests/ uc_cart_links.test - Tests Cart Links on a page under a variety of conditions.
- UbercartCartLinksTestCase::testCartLinksMessages in uc_cart_links/
tests/ uc_cart_links.test - Tests Cart Links messages.
- UbercartCartLinksTestCase::testCartLinksProductActionMessage in uc_cart_links/
tests/ uc_cart_links.test - Tests Cart Links product action messages.
- UbercartCartLinksTestCase::testCartLinksRestrictions in uc_cart_links/
tests/ uc_cart_links.test - Tests Cart Links restrictions.
File
- uc_cart_links/
tests/ uc_cart_links.test, line 701 - Ubercart Cart Links Tests.
Class
- UbercartCartLinksTestCase
- SimpleTests for Ubercart Cart Links.
Code
protected 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);
// 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->nid, TRUE);
}
return $product;
}