public function StockTest::testStockDecrement in Ubercart 8.4
Tests stock decrementing.
File
- uc_stock/
tests/ src/ Functional/ StockTest.php, line 84
Class
- StockTest
- Tests the stock control functionality.
Namespace
Drupal\Tests\uc_stock\FunctionalCode
public function testStockDecrement() {
/** @var \Drupal\Tests\WebAssert $assert */
$assert = $this
->assertSession();
$prefix = 'stock[' . $this->product->model->value . ']';
$stock = rand(100, 1000);
$edit = [
$prefix . '[active]' => 1,
$prefix . '[stock]' => $stock,
];
$this
->drupalGet('node/' . $this->product
->id() . '/edit/stock');
$this
->submitForm($edit, 'Save changes');
$assert
->pageTextContains('Stock settings saved.');
// Enable product quantity field.
$edit = [
'uc_product_add_to_cart_qty' => TRUE,
];
$this
->drupalGet('admin/store/config/products');
$this
->submitForm($edit, 'Save configuration');
$qty = rand(1, 100);
$edit = [
'qty' => $qty,
];
$this
->addToCart($this->product, $edit);
$this
->checkout();
$this
->assertEquals($stock - $qty, uc_stock_level($this->product->model->value));
}