You are here

protected function StockLevelFieldTestBase::setup in Commerce Stock 8

Setting up the test.

1 call to StockLevelFieldTestBase::setup()
StockLevelFormatterTest::setup in modules/field/tests/src/Functional/StockLevelFormatterTest.php
Setting the field name.
1 method overrides StockLevelFieldTestBase::setup()
StockLevelFormatterTest::setup in modules/field/tests/src/Functional/StockLevelFormatterTest.php
Setting the field name.

File

modules/field/tests/src/Functional/StockLevelFieldTestBase.php, line 45

Class

StockLevelFieldTestBase
Provides a base class for stock level fields functional tests.

Namespace

Drupal\Tests\commerce_stock_field\Functional

Code

protected function setup() {
  parent::setUp();
  $entity_type = "commerce_product_variation";
  $bundle = 'default';
  $this->fieldName = 'stock_level_test';
  $config = \Drupal::configFactory()
    ->getEditable('commerce_stock.service_manager');
  $config
    ->set('default_service_id', 'local_stock');
  $config
    ->save();
  $widget_settings = [
    'step' => 1,
    'transaction_note' => FALSE,
  ];
  $this
    ->createStockLevelField($entity_type, $bundle, 'commerce_stock_level_simple_transaction', [], [], $widget_settings);

  // Varations needs a fresh load to load the new fields.
  $this->variation = $entityTypeManager = \Drupal::entityTypeManager()
    ->getStorage($entity_type)
    ->load($this->variations[2]
    ->id());
  self::assertTrue($this->variation
    ->hasField($this->fieldName));
  $stockServiceConfiguration = $this->stockServiceManager
    ->getService($this->variation)
    ->getConfiguration();
  $store = array_shift($this->stores);
  $context = new Context($this->adminUser, $store);
  $this->locations = $stockServiceConfiguration
    ->getAvailabilityLocations($context, $this->variation);
  $this->stockServiceManager
    ->createTransaction($this->variation, $this->locations[1]
    ->getId(), '', 10, 10.1, 'USD', StockTransactionsInterface::STOCK_IN, []);
  self::assertTrue($this->stockServiceManager
    ->getStockLevel($this->variation) == 10);
}