ProductBehaviorInvocationTest.php in Rabbit Hole 8
File
modules/rh_commerce/tests/src/Functional/ProductBehaviorInvocationTest.php
View source
<?php
namespace Drupal\Tests\rh_commerce\Functional;
use Drupal\commerce_product\Entity\Product;
use Drupal\commerce_store\StoreCreationTrait;
use Drupal\Tests\rabbit_hole\Functional\RabbitHoleBehaviorInvocationTestBase;
class ProductBehaviorInvocationTest extends RabbitHoleBehaviorInvocationTestBase {
use StoreCreationTrait;
protected $entityType = 'commerce_product';
public static $modules = [
'rh_commerce',
];
protected $productType;
protected function createEntityBundle($action = NULL) {
$storage = \Drupal::entityTypeManager()
->getStorage('commerce_product_type');
$product_type = $storage
->create([
'id' => mb_strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
]);
$storage
->save($product_type);
$this->productType = $product_type;
if (isset($action)) {
$this->behaviorSettingsManager
->saveBehaviorSettings([
'action' => $action,
'allow_override' => TRUE,
], 'commerce_product_type', $this->productType
->id());
}
return $this->productType
->id();
}
protected function createEntity($action = NULL) {
$values = [];
if (isset($action)) {
$values['rh_action'] = $action;
}
$product = Product::create($values + [
'title' => $this
->randomString(),
'type' => $this->productType
->id(),
'stores' => [
$this
->createStore(),
],
]);
$product
->save();
return $product;
}
}