You are here

protected function UbercartTestBase::createProduct in Ubercart 8.4

Creates a new product.

Parameters

array $product: (optional) An associative array of product fields to change from the defaults, keys are product field names. For example, 'price' => '12.34'.

Return value

\Drupal\node\NodeInterface Product node object.

4 calls to UbercartTestBase::createProduct()
CartLinksTest::createCartLinksProduct in uc_cart_links/src/Tests/CartLinksTest.php
Creates a product with all attribute types and options.
QuoteTest::testNoQuote in shipping/uc_quote/src/Tests/QuoteTest.php
Verifies shipping pane is hidden when there are no shippable items.
QuoteTest::testQuote in shipping/uc_quote/src/Tests/QuoteTest.php
Tests basic flatrate shipping quote functionality.
UbercartTestBase::setUp in uc_store/src/Tests/UbercartTestBase.php
Sets up a Drupal site for running functional and integration tests.

File

uc_store/src/Tests/UbercartTestBase.php, line 116

Class

UbercartTestBase
Base class for Ubercart Simpletest tests.

Namespace

Drupal\uc_store\Tests

Code

protected function createProduct(array $product = []) {

  // Set the default required fields.
  $weight_units = [
    'lb',
    'kg',
    'oz',
    'g',
  ];
  $length_units = [
    'in',
    'ft',
    'cm',
    'mm',
  ];
  $product += [
    'type' => 'product',
    'model' => $this
      ->randomMachineName(8),
    'cost' => mt_rand(1, 9999),
    'price' => mt_rand(1, 9999),
    'weight' => [
      0 => [
        'value' => mt_rand(1, 9999),
        'units' => array_rand(array_flip($weight_units)),
      ],
    ],
    'dimensions' => [
      0 => [
        'length' => mt_rand(1, 9999),
        'width' => mt_rand(1, 9999),
        'height' => mt_rand(1, 9999),
        'units' => array_rand(array_flip($length_units)),
      ],
    ],
    'pkg_qty' => mt_rand(1, 99),
    'default_qty' => 1,
    'shippable' => 1,
  ];
  $product['model'] = [
    [
      'value' => $product['model'],
    ],
  ];
  $product['price'] = [
    [
      'value' => $product['price'],
    ],
  ];
  return $this
    ->drupalCreateNode($product);
}