protected function LocalStockUpdaterTest::setUp in Commerce Stock 8
Overrides CommerceKernelTestBase::setUp
File
- modules/
local_storage/ tests/ src/ Kernel/ LocalStockUpdaterTest.php, line 81
Class
- LocalStockUpdaterTest
- Testing the local stock updater.
Namespace
Drupal\Tests\commerce_stock_local\KernelCode
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('commerce_product');
$this
->installEntitySchema('commerce_product_type');
$this
->installEntitySchema('commerce_product_variation');
$this
->installEntitySchema('commerce_product_variation_type');
$this
->installEntitySchema('commerce_stock_location_type');
$this
->installEntitySchema('commerce_stock_location');
$this
->installConfig([
'commerce_product',
]);
$this
->installConfig([
'commerce_stock',
]);
$this
->installConfig([
'commerce_stock_field',
]);
$this
->installConfig([
'commerce_stock_local',
]);
$this
->installConfig([
'commerce_stock_local_test',
]);
$this
->installSchema('commerce_stock_local', [
'commerce_stock_transaction_type',
'commerce_stock_transaction',
'commerce_stock_location_level',
]);
$defaultStockLocation = StockLocation::create([
'name' => 'Test',
'status' => 1,
'type' => "default",
]);
$defaultStockLocation
->save();
$user = $this
->createUser();
$user = $this
->reloadEntity($user);
$this->user = $user;
$config = \Drupal::configFactory()
->getEditable('commerce_stock.service_manager');
$config
->set('default_service_id', 'local_stock');
$config
->save();
$stockServiceManager = \Drupal::service('commerce_stock.service_manager');
// Turn off title generation to allow explicit values to be used.
$variation_type = ProductVariationType::load('default');
$variation_type
->setGenerateTitle(FALSE);
$variation_type
->save();
$this->variation = ProductVariation::create([
'type' => 'default',
'sku' => 'TEST_' . strtolower($this
->randomMachineName()),
'title' => $this
->randomString(),
'status' => 1,
'price' => [
'number' => '11.11',
'currency_code' => 'USD',
],
]);
$this->variation
->save();
$this->variation = $this
->reloadEntity($this->variation);
$this->checker = $stockServiceManager
->getService($this->variation)
->getStockChecker();
$this->stockService = $stockServiceManager
->getService($this->variation);
$stockServiceConfiguration = $stockServiceManager
->getService($this->variation)
->getConfiguration();
$context = new Context($user, $this->store);
$this->locations = $stockServiceConfiguration
->getAvailabilityLocations($context, $this->variation);
}