public function StockLevelTest::testTransactionData in Commerce Stock 8
Whether all data are correctly saved with the transaction.
File
- modules/
field/ tests/ src/ Kernel/ StockLevelTest.php, line 199
Class
- StockLevelTest
- Ensure the stock level field works.
Namespace
Drupal\Tests\commerce_stock_field\KernelCode
public function testTransactionData() {
$test_note = $this
->randomString();
$zone = 'TestZone';
$mock_widget_values = [
'adjustment' => '3.33',
'stock_transaction_note' => $test_note,
'user_id' => 7,
'unit_cost' => [
'amount' => 33,
'currency_code' => 'USD',
],
'zone' => $zone,
];
$this->variation
->set('test_stock_level', $mock_widget_values);
$this->variation
->save();
$transaction = $this
->getLastEntityTransaction($this->variation
->id());
$data = unserialize($transaction->data);
$this
->assertEquals($mock_widget_values['zone'], $transaction->location_zone);
$this
->assertEquals($mock_widget_values['adjustment'], $transaction->qty);
$this
->assertEquals($mock_widget_values['user_id'], $transaction->related_uid);
$this
->assertEquals($mock_widget_values['unit_cost']['amount'], $transaction->unit_cost);
$this
->assertEquals($mock_widget_values['unit_cost']['currency_code'], $transaction->currency_code);
$this
->assertEquals($mock_widget_values['stock_transaction_note'], $data['message']);
}