ProductBehaviorSettingsFormTest.php in Rabbit Hole 2.x
File
modules/rh_commerce/tests/src/Functional/ProductBehaviorSettingsFormTest.php
View source
<?php
namespace Drupal\Tests\rh_commerce\Functional;
use Drupal\commerce_product\Entity\Product;
use Drupal\commerce_store\StoreCreationTrait;
use Drupal\Core\Url;
use Drupal\Tests\rabbit_hole\Functional\RabbitHoleBehaviorSettingsFormTestBase;
class ProductBehaviorSettingsFormTest extends RabbitHoleBehaviorSettingsFormTestBase {
use StoreCreationTrait;
protected $bundle;
protected $store;
protected $entityType = 'commerce_product';
protected $bundleEntityTypeName = 'commerce_product_type';
public static $modules = [
'rh_commerce',
];
protected function setUp() {
parent::setUp();
$this->store = $this
->createStore();
}
protected function createEntityBundle() {
$storage = \Drupal::entityTypeManager()
->getStorage('commerce_product_type');
$product_type = $storage
->create([
'id' => mb_strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
]);
$storage
->save($product_type);
$this->bundle = $product_type;
return $product_type
->id();
}
protected function createEntityBundleFormSubmit($action, $override) {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/commerce/config/product-types/add');
$this
->assertSession()
->statusCodeEquals(200);
$edit = [
'id' => mb_strtolower($this
->randomMachineName()),
'label' => $this
->randomMachineName(),
'rh_action' => $action,
'rh_override' => $override,
];
$this
->submitForm($edit, 'Save');
$this->bundle = $this
->loadBundle($edit['id']);
return $edit['id'];
}
protected function createEntity($action = NULL) {
$values = [];
if (isset($action)) {
$values['rh_action'] = $action;
}
$product = Product::create($values + [
'title' => $this
->randomString(),
'type' => $this->bundle
->id(),
'stores' => [
$this->store,
],
]);
$product
->save();
return $product
->id();
}
protected function getCreateEntityUrl() {
return Url::fromRoute('entity.commerce_product.add_form', [
'commerce_product_type' => $this->bundle
->id(),
]);
}
protected function getEditEntityUrl($id) {
return Url::fromRoute('entity.commerce_product.edit_form', [
'commerce_product' => $id,
]);
}
protected function getEditBundleUrl($bundle) {
return Url::fromRoute('entity.commerce_product_type.edit_form', [
'commerce_product_type' => $bundle,
]);
}
protected function getAdminPermissions() {
return [
'administer commerce_store',
'administer commerce_product',
'administer commerce_product_type',
];
}
protected function getEntityFormSubmit() {
return 'Save';
}
}