protected function StockWebDriverTestBase::setUp in Commerce Stock 8
Overrides BrowserTestBase::setUp
File
- tests/
src/ FunctionalJavascript/ StockWebDriverTestBase.php, line 103
Class
- StockWebDriverTestBase
- Defines base class for commerce stock test cases.
Namespace
Drupal\Tests\commerce_stock\FunctionalJavascriptCode
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;
}