You are here

public function MerciBaseTestCase::createDummyProduct in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3

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.

9 calls to MerciBaseTestCase::createDummyProduct()
MerciBaseTestCase::createDummyLineItem in merci_core/tests/merci_base.test
Create a dummy order in a given status.
MerciBaseTestCase::createDummyProductNodeBatch in merci_core/tests/merci_base.test
Create a full product node without worrying about the earlier steps in the process.
MerciBaseTestCase::createDummyReservation in merci_core/tests/merci_base.test
Create a dummy order in a given status.
MerciBaseTesterTestCase::testTestCreateDummyLineItem in merci_core/tests/merci_base.test
Test the createDummyReservation function.
MerciBaseTesterTestCase::_testTestCreateDummyProduct in merci_core/tests/merci_base.test
Make a test product.

... See full list

File

merci_core/tests/merci_base.test, line 276
Defines abstract base test class for the Merci module tests.

Class

MerciBaseTestCase
Abstract class for Merci testing. All Merci tests should extend this class.

Code

public function createDummyProduct($sku = '', $title = '', $amount = -1, $currency_code = 'USD', $uid = 1, $type_given = 'merci_resource') {
  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'] = 'USD';
    $new_product->field_quantity[LANGUAGE_NONE][0]['value'] = '1';
    commerce_product_save($new_product);
    return $new_product;
  }
  else {
    return FALSE;
  }
}