You are here

public function UbercartProductTestCase::testProductNodeForm in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 uc_product/uc_product.test \UbercartProductTestCase::testProductNodeForm()

File

uc_product/tests/uc_product.test, line 29
Ubercart Product Tests

Class

UbercartProductTestCase
@file Ubercart Product Tests

Code

public function testProductNodeForm() {
  $this
    ->drupalGet('node/add/product');
  foreach (array(
    'model',
    'list_price',
    'cost',
    'sell_price',
    'shippable',
    'weight',
    'weight_units',
    'dim_length',
    'dim_width',
    'dim_height',
    'length_units',
    'pkg_qty',
    'ordering',
  ) as $field) {
    $this
      ->assertFieldByName($field, NULL);
  }
  $body_key = 'body[und][0][value]';

  // Make a node with those fields.
  $edit = array(
    'title' => $this
      ->randomName(32),
    $body_key => $this
      ->randomName(64),
    'model' => $this
      ->randomName(8),
    'list_price' => mt_rand(1, 200),
    'cost' => mt_rand(0, 100),
    'sell_price' => mt_rand(1, 150),
    'shippable' => mt_rand(0, 1),
    'weight' => mt_rand(1, 50),
    'weight_units' => array_rand(array(
      'lb' => t('Pounds'),
      'kg' => t('Kilograms'),
      'oz' => t('Ounces'),
      'g' => t('Grams'),
    )),
    'dim_length' => mt_rand(1, 50),
    'dim_width' => mt_rand(1, 50),
    'dim_height' => mt_rand(1, 50),
    'length_units' => array_rand(array(
      'in' => t('Inches'),
      'ft' => t('Feet'),
      'cm' => t('Centimeters'),
      'mm' => t('Millimeters'),
    )),
  );
  $this
    ->drupalPost('node/add/product', $edit, t('Save'));
  $this
    ->assertText(t('Product @title has been created.', array(
    '@title' => $edit['title'],
  )), t('Product created.'));
  $this
    ->assertText($edit[$body_key], t('Product body found.'));
  $this
    ->assertText(t('SKU: @model', array(
    '@model' => $edit['model'],
  )), t('Product model found.'));
  $this
    ->assertText(t('Price: @price', array(
    '@price' => uc_currency_format($edit['sell_price']),
  )), t('Product sell price found.'));
  $this
    ->assertNoUniqueText(uc_currency_format($edit['sell_price']), t('Price appears more than once.'));
  $elements = $this
    ->xpath('//body[contains(@class, "uc-product-node")]');
  $this
    ->assertEqual(count($elements), 1, t('Product page contains body CSS class.'));
}