public function CommerceBaseTestCase::createDummyProductNode in Commerce Core 7
Creates a product display node with an associated product.
Parameters
$product_ids: Array of product IDs to use for the product reference field.
$title: Optional title for the product node. Will default to a random name.
$product_display_content_type: Machine name for the product display content type to use for creating the node. Defaults to 'product_display'.
$product_ref_field_name: Machine name for the product reference field on this product display content type. Defaults to 'field_product'.
Return value
The newly saved $node object.
13 calls to CommerceBaseTestCase::createDummyProductNode()
- CommerceBaseTestCase::createDummyProductNodeBatch in tests/
commerce_base.test - Create a full product node without worrying about the earlier steps in the process.
- CommerceBaseTesterTestCase::testTestCreateDummyProductNode in tests/
commerce_base.test - Test the createDummyProductNode function.
- CommerceCartTestCaseAnonymousToAuthenticated::setUp in modules/
cart/ tests/ commerce_cart.test - Implementation of setUp().
- CommerceCartTestCaseAttributes::setUp in modules/
cart/ tests/ commerce_cart.test - Implementation of setUp().
- CommerceCartTestCaseMultiProducts::setUp in modules/
cart/ tests/ commerce_cart.test - Implementation of setUp().
File
- tests/
commerce_base.test, line 473 - Defines abstract base test class for the Commerce module tests.
Class
- CommerceBaseTestCase
- Abstract class for Commerce testing. All Commerce tests should extend this class.
Code
public function createDummyProductNode($product_ids, $title = '', $product_display_content_type = 'product_display', $product_ref_field_name = 'field_product') {
if (module_exists('commerce_product')) {
if (empty($title)) {
$title = $this
->randomString(10);
}
$node = (object) array(
'type' => $product_display_content_type,
);
node_object_prepare($node);
$node->uid = 1;
$node->title = $title;
foreach ($product_ids as $product_id) {
$node->{$product_ref_field_name}[LANGUAGE_NONE][]['product_id'] = $product_id;
}
node_save($node);
return $node;
}
else {
$this
->fail(t('Cannot use use createProductNode because the product module is not enabled.'));
}
}