You are here

public function OrderTypeTest::testDelete in Commerce Core 8.2

Tests deleting an order type.

File

modules/order/tests/src/Functional/OrderTypeTest.php, line 102

Class

OrderTypeTest
Tests the order type UI.

Namespace

Drupal\Tests\commerce_order\Functional

Code

public function testDelete() {

  /** @var \Drupal\commerce_order\Entity\OrderTypeInterface $order_type */
  $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,
  ]);

  // Confirm that the type can't be deleted while there's an order.
  $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.'));

  // Confirm that the delete page is not available when the type is locked.
  $order_type
    ->lock();
  $order_type
    ->save();
  $this
    ->drupalGet($order_type
    ->toUrl('delete-form'));
  $this
    ->assertSession()
    ->statusCodeEquals('403');

  // Delete the order, unlock the type, confirm that deletion works.
  $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);
}