OrderItemTypeTest.php in Commerce Core 8.2
File
modules/order/tests/src/Functional/OrderItemTypeTest.php
View source
<?php
namespace Drupal\Tests\commerce_order\Functional;
use Drupal\commerce_order\Entity\OrderItemType;
class OrderItemTypeTest extends OrderBrowserTestBase {
public static $modules = [
'commerce_cart',
];
public function testAdd() {
$this
->drupalGet('admin/commerce/config/order-item-types/add');
$edit = [
'id' => 'foo',
'label' => 'Foo',
'purchasableEntityType' => 'commerce_product_variation',
'orderType' => 'default',
];
$this
->submitForm($edit, t('Save'));
$this
->assertSession()
->pageTextContains('Saved the Foo order item type.');
$order_item_type = OrderItemType::load($edit['id']);
$this
->assertNotEmpty($order_item_type);
$this
->assertEquals($edit['label'], $order_item_type
->label());
$this
->assertEquals($edit['purchasableEntityType'], $order_item_type
->getPurchasableEntityTypeId());
$this
->assertEquals($edit['orderType'], $order_item_type
->getOrderTypeId());
}
public function testEdit() {
$this
->drupalGet('admin/commerce/config/order-item-types/default/edit');
$edit = [
'label' => 'Default!',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('Saved the Default! order item type.');
$order_item_type = OrderItemType::load('default');
$this
->assertEquals($edit['label'], $order_item_type
->label());
}
public function testDuplicate() {
$this
->drupalGet('admin/commerce/config/order-item-types/default/duplicate');
$this
->assertSession()
->fieldValueEquals('label', 'Default');
$edit = [
'label' => 'Default2',
'id' => 'default2',
];
$this
->submitForm($edit, t('Save'));
$this
->assertSession()
->pageTextContains('Saved the Default2 order item type.');
$order_item_type = OrderItemType::load('default');
$this
->assertNotEmpty($order_item_type);
$this
->assertEquals('Default', $order_item_type
->label());
$order_item_type = OrderItemType::load('default2');
$this
->assertNotEmpty($order_item_type);
$this
->assertEquals('Default2', $order_item_type
->label());
}
public function testDelete() {
$order_item_type = $this
->createEntity('commerce_order_item_type', [
'id' => strtolower($this
->randomMachineName(8)),
'label' => $this
->randomMachineName(16),
'purchasableEntityType' => 'commerce_product_variation',
'orderType' => 'default',
]);
$order_item_type
->lock();
$order_item_type
->save();
$this
->drupalGet($order_item_type
->toUrl('delete-form'));
$this
->assertSession()
->statusCodeEquals('403');
$order_item_type
->unlock();
$order_item_type
->save();
$this
->drupalGet($order_item_type
->toUrl('delete-form'));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains(t('This action cannot be undone.'));
$this
->submitForm([], t('Delete'));
$order_item_type_exists = (bool) OrderItemType::load($order_item_type
->id());
$this
->assertEmpty($order_item_type_exists);
}
}