ProductBundleBrowserTestBase.php in Commerce Product Bundle 8
File
tests/src/Functional/ProductBundleBrowserTestBase.php
View source
<?php
namespace Drupal\Tests\commerce_product_bundle\Functional;
use Drupal\commerce_product\Entity\Product;
use Drupal\commerce_product\Entity\ProductVariation;
use Drupal\commerce_store\StoreCreationTrait;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\Tests\commerce\Functional\CommerceBrowserTestBase;
abstract class ProductBundleBrowserTestBase extends CommerceBrowserTestBase {
use StoreCreationTrait;
use EntityReferenceTestTrait;
public static $modules = [
'commerce_store',
'commerce_product',
'commerce_order',
'commerce_product_bundle',
'field_ui',
'options',
'taxonomy',
];
protected $products;
protected $variations;
protected $stores;
protected $bundle;
protected function getAdministratorPermissions() {
return array_merge([
'administer commerce_product',
'administer commerce_product_bundle',
'administer commerce_product_bundle_type',
'administer commerce_product_bundle_i',
'administer commerce_product_bundle_i_type',
'administer commerce_product_type',
'administer commerce_product fields',
'administer commerce_product_variation fields',
'administer commerce_product_variation display',
'access commerce_product overview',
], parent::getAdministratorPermissions());
}
protected function setUp() {
parent::setUp();
$this->stores = [];
for ($i = 0; $i < 3; $i++) {
$this->stores[] = $this
->createStore();
}
for ($j = 1; $j <= 2; $j++) {
$variations = [];
for ($i = 1; $i <= 5; $i++) {
$variation = ProductVariation::create([
'type' => 'default',
'sku' => strtolower($this
->randomMachineName()),
'title' => $this
->randomString(),
'status' => $i % 2,
]);
$variation
->save();
$this->variations[] = $variation;
}
$variations = array_reverse($variations);
$product = Product::create([
'type' => 'default',
'variations' => $variations,
]);
$product
->save();
$this->products[] = $product;
}
}
}