You are here

public function CommerceBaseTestCase::createDummyProduct in Commerce Core 7

Creates a dummy product for use with other tests.

Parameters

$type_given: Optional. The product type to base this product on. Defaults to 'product'.

Return value

A product type with most of it's basic fields set random values. FALSE if the appropiate modules were not available.

24 calls to CommerceBaseTestCase::createDummyProduct()
CommerceBaseTestCase::createDummyOrder in tests/commerce_base.test
Create a dummy order in a given status.
CommerceBaseTestCase::createDummyProductNodeBatch in tests/commerce_base.test
Create a full product node without worrying about the earlier steps in the process.
CommerceBaseTesterTestCase::testTestCreateDummyOrder in tests/commerce_base.test
Test the createDummyOrder function.
CommerceBaseTesterTestCase::testTestCreateDummyProduct in tests/commerce_base.test
Make a test product.
CommerceBaseTesterTestCase::testTestCreateDummyProductNode in tests/commerce_base.test
Test the createDummyProductNode function.

... See full list

File

tests/commerce_base.test, line 274
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 createDummyProduct($sku = '', $title = '', $amount = -1, $currency_code = 'USD', $uid = 1, $type_given = 'product') {
  if (module_exists('commerce_product')) {
    $new_product = commerce_product_new($type_given);
    $new_product->sku = empty($sku) ? $this
      ->randomName(10) : $sku;
    $new_product->title = empty($title) ? $this
      ->randomName(10) : $title;
    $new_product->uid = $uid;
    $new_product->commerce_price[LANGUAGE_NONE][0]['amount'] = $amount < 0 ? rand(2, 500) : $amount;
    $new_product->commerce_price[LANGUAGE_NONE][0]['currency_code'] = $currency_code;
    commerce_product_save($new_product);
    return $new_product;
  }
  else {
    return FALSE;
  }
}