You are here

public function UbercartStockTestCase::testProductStock in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 uc_stock/uc_stock.test \UbercartStockTestCase::testProductStock()

File

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

Class

UbercartStockTestCase
@file Ubercart stock related tests.

Code

public function testProductStock() {
  $this
    ->drupalGet('node/' . $this->product->nid . '/edit/stock');
  $this
    ->assertText($this->product->title);
  $this
    ->assertText($this->product->model, 'Product SKU found.');
  $this
    ->assertNoFieldChecked('edit-stock-0-active', 'Stock tracking is not active.');
  $this
    ->assertFieldByName('stock[0][stock]', '0', 'Default stock level found.');
  $this
    ->assertFieldByName('stock[0][threshold]', '0', 'Default stock threshold found.');
  $stock = rand(1, 1000);
  $edit = array(
    'stock[0][active]' => 1,
    'stock[0][stock]' => $stock,
    'stock[0][threshold]' => rand(1, 100),
  );
  $this
    ->drupalPost(NULL, $edit, t('Save changes'));
  $this
    ->assertText('Stock settings saved.');
  $this
    ->assertTrue(uc_stock_is_active($this->product->model));
  $this
    ->assertEqual($stock, uc_stock_level($this->product->model));
  $stock = rand(1, 1000);
  uc_stock_set($this->product->model, $stock);
  $this
    ->drupalGet('node/' . $this->product->nid . '/edit/stock');
  $this
    ->assertFieldByName('stock[0][stock]', (string) $stock, 'Set stock level found.');
}