public function StockTest::testProductStock in Ubercart 8.4
Tests stock settings on product edit page.
File
- uc_stock/
tests/ src/ Functional/ StockTest.php, line 44
Class
- StockTest
- Tests the stock control functionality.
Namespace
Drupal\Tests\uc_stock\FunctionalCode
public function testProductStock() {
/** @var \Drupal\Tests\WebAssert $assert */
$assert = $this
->assertSession();
$sku = $this->product->model->value;
$prefix = 'stock[' . $sku . ']';
$this
->drupalGet('node/' . $this->product
->id() . '/edit/stock');
$assert
->pageTextContains($this->product
->label());
// Check for SKU on product edit page.
$assert
->pageTextContains($this->product->model->value);
// Ensure stock tracking is not active.
$assert
->checkboxNotChecked('edit-stock-' . strtolower($sku) . '-active');
// Verify that default stock level found.
$assert
->fieldValueEquals($prefix . '[stock]', '0');
// Verify that default stock threshold found.
$assert
->fieldValueEquals($prefix . '[threshold]', '0');
$stock = rand(1, 1000);
$edit = [
$prefix . '[active]' => 1,
$prefix . '[stock]' => $stock,
$prefix . '[threshold]' => rand(1, 100),
];
$this
->submitForm($edit, 'Save changes');
$assert
->pageTextContains('Stock settings saved.');
$this
->assertTrue(uc_stock_is_active($sku));
$this
->assertEquals($stock, uc_stock_level($sku));
$stock = rand(1, 1000);
uc_stock_set($sku, $stock);
$this
->drupalGet('node/' . $this->product
->id() . '/edit/stock');
// Verify that set stock level found.
$assert
->fieldValueEquals($prefix . '[stock]', (string) $stock);
}