You are here

public function OrderEventsTransactionsTest::testWorkflowCancelEventNotModifyStockOnDraftOrders in Commerce Stock 8

Whether transactions are not triggered for the orders in draft state.

File

modules/local_storage/tests/src/Kernel/OrderEventsTransactionsTest.php, line 297

Class

OrderEventsTransactionsTest
Ensure the stock transactions are performed on order events.

Namespace

Drupal\Tests\commerce_stock_local\Kernel

Code

public function testWorkflowCancelEventNotModifyStockOnDraftOrders() {
  $this
    ->assertEquals(10, $this->checker
    ->getTotalStockLevel($this->variation, $this->locations));
  $transition = $this->order
    ->getState()
    ->getTransitions();
  $this->order
    ->getState()
    ->applyTransition($transition['cancel']);
  $this->order
    ->save();
  $this
    ->assertEquals($this->order
    ->getState()
    ->getLabel(), 'Canceled');
  $query = \Drupal::database()
    ->select('commerce_stock_transaction', 'txn')
    ->fields('txn')
    ->condition('entity_id', $this->variation
    ->id())
    ->condition('transaction_type_id', StockTransactionsInterface::STOCK_RETURN);
  $result = $query
    ->execute()
    ->fetchAll();
  $this
    ->assertCount(0, $result);
  $this
    ->assertEquals(10, $this->checker
    ->getTotalStockLevel($this->variation, $this->locations));
}