protected function StockBrowserTestBase::setUp in Commerce Stock 8
Overrides CommerceBrowserTestBase::setUp
3 calls to StockBrowserTestBase::setUp()
- EnforcementBrowserTest::setUp in modules/
enforcement/ tests/ src/ Functional/ EnforcementBrowserTest.php - OutOfStockTest::setUp in modules/
enforcement/ tests/ src/ Functional/ OutOfStockTest.php - StockLevelFieldTestBase::setup in modules/
field/ tests/ src/ Functional/ StockLevelFieldTestBase.php - Setting up the test.
2 methods override StockBrowserTestBase::setUp()
- EnforcementBrowserTest::setUp in modules/
enforcement/ tests/ src/ Functional/ EnforcementBrowserTest.php - OutOfStockTest::setUp in modules/
enforcement/ tests/ src/ Functional/ OutOfStockTest.php
File
- tests/
src/ Functional/ StockBrowserTestBase.php, line 99
Class
- StockBrowserTestBase
- Defines base class for commerce stock test cases.
Namespace
Drupal\Tests\commerce_stock\FunctionalCode
protected function setUp() {
parent::setUp();
$this->stockServiceManager = $this->container
->get('commerce_stock.service_manager');
$this->store = $this
->createStore();
$this
->placeBlock('local_tasks_block');
$this
->placeBlock('local_actions_block');
$this
->placeBlock('page_title_block');
$this->adminUser = $this
->drupalCreateUser($this
->getAdministratorPermissions());
$this
->drupalLogin($this->adminUser);
$location = StockLocation::create([
'type' => 'default',
'name' => 'TESTLOCATION',
]);
$location
->save();
$this->stores = [];
for ($i = 0; $i < 3; $i++) {
$this->stores[] = $this
->createStore();
}
// Turn off title generation to allow explicit values to be used.
$variation_type = ProductVariationType::load('default');
$variation_type
->setGenerateTitle(FALSE);
$variation_type
->save();
$variations = [];
for ($i = 1; $i <= 3; $i++) {
$variation = ProductVariation::create([
'type' => 'default',
'sku' => strtolower($this
->randomMachineName()),
'status' => $i % 2,
'title' => $this
->randomString(),
]);
$variation
->save();
$variations[] = $this
->reloadEntity($variation);
}
$this->variations = array_reverse($variations);
$product = Product::create([
'type' => 'default',
'variations' => $variations,
'stores' => $this->stores,
]);
$product
->save();
$this->product = $product;
}