View source
<?php
namespace Drupal\Tests\commerce_order\Functional;
use Drupal\commerce_order\Entity\OrderType;
class OrderTypeTest extends OrderBrowserTestBase {
public function testDefault() {
$order_type = OrderType::load('default');
$this
->assertNotEmpty($order_type);
$this
->drupalGet('admin/commerce/config/order-types');
$rows = $this
->getSession()
->getPage()
->findAll('css', 'table tbody tr');
$this
->assertCount(1, $rows);
}
public function testAdd() {
OrderType::load('default')
->delete();
$this
->drupalGet('admin/commerce/config/order-types/add');
$edit = [
'id' => 'foo',
'label' => 'Foo',
'refresh_mode' => 'always',
'refresh_frequency' => 60,
];
$this
->submitForm($edit, t('Save'));
$this
->assertSession()
->pageTextContains('Saved the Foo order type.');
$order_type = OrderType::load('foo');
$this
->assertNotEmpty($order_type);
$this
->assertEmpty($order_type
->getNumberPatternId());
$this
->assertEquals($edit['refresh_mode'], $order_type
->getRefreshMode());
$this
->assertEquals($edit['refresh_frequency'], $order_type
->getRefreshFrequency());
}
public function testEdit() {
$this
->drupalGet('admin/commerce/config/order-types/default/edit');
$edit = [
'label' => 'Default!',
'generate_number' => FALSE,
'refresh_mode' => 'always',
'refresh_frequency' => 60,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('Saved the Default! order type.');
$order_type = OrderType::load('default');
$this
->assertNotEmpty($order_type);
$this
->assertEquals($edit['label'], $order_type
->label());
$this
->assertEmpty($order_type
->getNumberPatternId());
$this
->assertEquals($edit['refresh_mode'], $order_type
->getRefreshMode());
$this
->assertEquals($edit['refresh_frequency'], $order_type
->getRefreshFrequency());
}
public function testDuplicate() {
$this
->drupalGet('admin/commerce/config/order-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 type.');
$order_type = OrderType::load('default');
$this
->assertNotEmpty($order_type);
$this
->assertEquals('Default', $order_type
->label());
$this
->assertEquals('order_default', $order_type
->getNumberPatternId());
$order_type = OrderType::load('default2');
$this
->assertNotEmpty($order_type);
$this
->assertEquals('Default2', $order_type
->label());
$this
->assertEquals('order_default', $order_type
->getNumberPatternId());
}
public function testDelete() {
$order_type = $this
->createEntity('commerce_order_type', [
'id' => 'foo',
'label' => 'Label for foo',
'workflow' => 'order_default',
]);
$order = $this
->createEntity('commerce_order', [
'type' => $order_type
->id(),
'mail' => $this->loggedInUser
->getEmail(),
'store_id' => $this->store,
]);
$this
->drupalGet($order_type
->toUrl('delete-form'));
$this
->assertSession()
->pageTextContains(t('@type is used by 1 order on your site. You cannot remove this order type until you have removed all of the @type orders.', [
'@type' => $order_type
->label(),
]));
$this
->assertSession()
->pageTextNotContains(t('This action cannot be undone.'));
$order_type
->lock();
$order_type
->save();
$this
->drupalGet($order_type
->toUrl('delete-form'));
$this
->assertSession()
->statusCodeEquals('403');
$order
->delete();
$order_type
->unlock();
$order_type
->save();
$this
->drupalGet($order_type
->toUrl('delete-form'));
$this
->assertSession()
->pageTextContains(t('Are you sure you want to delete the order type @label?', [
'@label' => $order_type
->label(),
]));
$this
->assertSession()
->pageTextContains(t('This action cannot be undone.'));
$this
->submitForm([], t('Delete'));
$order_type_exists = (bool) OrderType::load($order_type
->id());
$this
->assertEmpty($order_type_exists);
}
public function testOrderTypeDependencies() {
$this
->drupalGet('admin/commerce/config/order-types/default/edit');
$this
->submitForm([
'workflow' => 'test_workflow',
], t('Save'));
$order_type = OrderType::load('default');
$this
->assertEquals('test_workflow', $order_type
->getWorkflowId());
$dependencies = $order_type
->getDependencies();
$this
->assertArrayHasKey('module', $dependencies);
$this
->assertContains('commerce_order_test', $dependencies['module']);
}
}