You are here

public function UbercartStockTestCase::testStockDecrement in Ubercart 6.2

Same name and namespace in other branches
  1. 7.3 uc_stock/tests/uc_stock.test \UbercartStockTestCase::testStockDecrement()

File

uc_stock/uc_stock.test, line 49
Ubercart stock related tests.

Class

UbercartStockTestCase
@file Ubercart stock related tests.

Code

public function testStockDecrement() {
  $stock = rand(100, 1000);
  $edit = array(
    'stock[0][active]' => 1,
    'stock[0][stock]' => $stock,
  );
  $this
    ->drupalPost('node/' . $this->product->nid . '/edit/stock', $edit, t('Save changes'));
  $this
    ->assertText('Stock settings saved.');

  // Enable product quantity field.
  variable_set('uc_product_add_to_cart_qty', TRUE);
  $qty = rand(1, 100);
  $edit = array(
    'qty' => $qty,
  );
  $this
    ->drupalPost('node/' . $this->product->nid, $edit, t('Add to cart'));
  $this
    ->checkout();
  $this
    ->assertEqual($stock - $qty, uc_stock_level($this->product->model));
}