You are here

public function CommerceBaseTestCase::createDummyProductDisplayContentType in Commerce Core 7

Create a dummy product display content type.

Parameters

$type: Machine name of the content type to create. Also used for human readable name to keep things simple.

$attach_product_reference_field: If TRUE, automatically add a product reference field to the new content type.

$field_name: Only used if $attach_product_reference_field is TRUE. Sets the name for the field instance to attach. Creates the field if it doesn't exist.

$cardinality_reference_field: Only used if $attach_product_reference_field is TRUE. Sets the cardinality for the field instance to attach.

Return value

An object for the content type.

See also

attachProductReferenceField()

11 calls to CommerceBaseTestCase::createDummyProductDisplayContentType()
CommerceBaseTestCase::createDummyProductNodeBatch in tests/commerce_base.test
Create a full product node without worrying about the earlier steps in the process.
CommerceBaseTesterTestCase::testTestCreateDummyProductDisplayAndRefField in tests/commerce_base.test
Test the creation of a product_display content type and add a product reference field to the content type.
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().

... See full list

File

tests/commerce_base.test, line 312
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 createDummyProductDisplayContentType($type = 'product_display', $attach_product_reference_field = TRUE, $field_name = 'field_product', $cardinality_reference_field = 1) {

  // If the specified node type already exists, return it now.
  if ($content_type = node_type_load($type)) {
    return $content_type;
  }
  $content_type = array(
    'type' => $type,
    'name' => $type,
    // Don't use a human readable name here to keep it simple.
    'base' => 'node_content',
    'description' => 'Use <em>product displays</em> to display products for sale to your customers.',
    'custom' => 1,
    'modified' => 1,
    'locked' => 0,
  );
  $content_type = node_type_set_defaults($content_type);
  node_type_save($content_type);
  node_add_body_field($content_type);
  $this
    ->pass("Created content type: {$type}");
  if ($attach_product_reference_field) {

    // Maybe $instance should be returned as well
    $instance = $this
      ->attachProductReferenceField($type, $field_name, $cardinality_reference_field);
  }
  return $content_type;
}