public function StockLevelWidgetsTest::testDeprecatedWidget in Commerce Stock 8
Test the deprecated simple widget.
File
- modules/
field/ tests/ src/ Functional/ StockLevelWidgetsTest.php, line 470
Class
- StockLevelWidgetsTest
- Provides tests for the stock level widget.
Namespace
Drupal\Tests\commerce_stock_field\FunctionalCode
public function testDeprecatedWidget() {
$entity_type = "commerce_product_variation";
$bundle = 'default';
$widget_id = "commerce_stock_level_simple";
$widget_settings = [
'entry_system' => 'basic',
'transaction_note' => FALSE,
'context_fallback' => FALSE,
];
$this
->configureFormDisplay($widget_id, $widget_settings, $entity_type, $bundle);
$this
->drupalGet($this->variation
->toUrl('edit-form'));
// Ensure the stock part of the form is healty.
$this
->assertSession()
->fieldExists('commerce_stock_always_in_stock[value]');
$this
->assertSession()
->checkboxNotChecked('commerce_stock_always_in_stock[value]');
$this
->assertSession()
->fieldExists($this->fieldName . '[0][adjustment]');
$adjustment = 5;
$new_price_amount = '1.11';
$variations_edit = [
'price[0][number]' => $new_price_amount,
$this->fieldName . '[0][adjustment]' => $adjustment,
];
$this
->submitForm($variations_edit, 'Save');
$transaction = $this
->getLastEntityTransaction($this->variation
->id());
$this
->assertEquals($adjustment, $transaction->qty);
$this
->assertEquals($this->adminUser
->id(), $transaction->related_uid);
$widget_settings = [
'entry_system' => 'simple',
'transaction_note' => FALSE,
'context_fallback' => FALSE,
];
$this
->configureFormDisplay($widget_id, $widget_settings, $entity_type, $bundle);
$this
->drupalGet($this->variation
->toUrl('edit-form'));
$this
->assertSession()
->fieldExists($this->fieldName . '[0][stock_level]');
$stock_level = 20;
$edit = [
$this->fieldName . '[0][stock_level]' => $stock_level,
];
$this
->submitForm($edit, 'Save');
$transaction = $this
->getLastEntityTransaction($this->variation
->id());
// We setup our variation with an initial stock of 15. So setting the
// absolute level to 20 should result in a transaction with 5.
$this
->assertEquals(5, $transaction->qty);
$this
->assertEquals($this->adminUser
->id(), $transaction->related_uid);
$widget_settings = [
'entry_system' => 'transactions',
'transaction_note' => FALSE,
'context_fallback' => FALSE,
];
$this
->configureFormDisplay($widget_id, $widget_settings, $entity_type, $bundle);
$this
->drupalGet($this->variation
->toUrl('edit-form'));
$this
->assertSession()
->linkExists('New transaction');
}