public function OrderEventsTransactionsTest::testOrderPlaceTransition in Commerce Stock 8
Whether transactions are created on 'place' transition.
File
- modules/
local_storage/ tests/ src/ Kernel/ OrderEventsTransactionsTest.php, line 260
Class
- OrderEventsTransactionsTest
- Ensure the stock transactions are performed on order events.
Namespace
Drupal\Tests\commerce_stock_local\KernelCode
public function testOrderPlaceTransition() {
// Tests initial stock level transactions did work.
$query = \Drupal::database()
->select('commerce_stock_transaction', 'txn')
->fields('txn')
->condition('transaction_type_id', StockTransactionsInterface::STOCK_IN);
$result = $query
->execute()
->fetchAll();
$this
->assertEquals('1', $result[0]->id);
$this
->assertEquals($this->variation
->id(), $result[0]->entity_id);
$this
->assertEquals('2', $result[1]->id);
$this
->assertEquals($this->variation2
->id(), $result[1]->entity_id);
$this
->assertEquals(10, $this->checker
->getTotalStockLevel($this->variation, $this->locations));
$this
->assertEquals(11, $this->checker2
->getTotalStockLevel($this->variation2, $this->locations2));
// Tests the commerce_order.place.post_transition workflow event.
$transition = $this->order
->getState()
->getTransitions();
$this->order
->setOrderNumber('2017/01');
$this->order
->getState()
->applyTransition($transition['place']);
$this->order
->save();
$this
->assertEquals($this->order
->getState()
->getLabel(), 'Validation');
$this
->assertEquals(9, $this->checker
->getTotalStockLevel($this->variation, $this->locations));
$query = \Drupal::database()
->select('commerce_stock_transaction', 'txn')
->fields('txn')
->condition('entity_id', $this->variation
->id())
->condition('transaction_type_id', StockTransactionsInterface::STOCK_SALE);
$result = $query
->execute()
->fetchAll();
$this
->assertCount(1, $result);
$this
->assertEquals('3', $result[0]->id);
$this
->assertEquals($this->variation
->id(), $result[0]->entity_id);
$this
->assertEquals($this->order
->id(), $result[0]->related_oid);
$this
->assertEquals($this->order
->getCustomerId(), $result[0]->related_uid);
$this
->assertEquals('-1.00', $result[0]->qty);
$this
->assertEquals('Order placed.', unserialize($result[0]->data)['message']);
}