You are here

public function ShipmentTypeTest::testDeleteShipmentType in Commerce Shipping 8.2

Tests deleting a shipment type.

File

tests/src/Functional/ShipmentTypeTest.php, line 146

Class

ShipmentTypeTest
Tests the shipment type UI.

Namespace

Drupal\Tests\commerce_shipping\Functional

Code

public function testDeleteShipmentType() {
  $type = $this
    ->createEntity('commerce_shipment_type', [
    'id' => 'foo',
    'label' => 'Foo label',
  ]);

  // Create a shipment.
  $shipment = $this
    ->createEntity('commerce_shipment', [
    'type' => 'foo',
    'order_id' => 10,
    'items' => [
      new ShipmentItem([
        'order_item_id' => 10,
        'title' => 'Test',
        'quantity' => 1,
        'weight' => new Weight(0, 'g'),
        'declared_value' => new Price('1', 'USD'),
      ]),
    ],
  ]);

  // Try to delete the shipment type.
  $this
    ->drupalGet('admin/commerce/config/shipment-types/foo/delete');
  $this
    ->assertSession()
    ->pageTextContains(t('@type is used by 1 shipment on your site. You can not remove this shipment type until you have removed all of the @type shipments.', [
    '@type' => $type
      ->label(),
  ]));
  $this
    ->assertSession()
    ->pageTextNotContains('This action cannot be undone.');
  $this
    ->assertSession()
    ->pageTextNotContains('The shipment type deletion confirmation form is not available');

  // Deleting the shipment type when its not being referenced by a shipment.
  $shipment
    ->delete();
  $this
    ->drupalGet('admin/commerce/config/shipment-types/foo/delete');
  $this
    ->assertSession()
    ->pageTextContains(t('Are you sure you want to delete the shipment type @type?', [
    '@type' => $type
      ->label(),
  ]));
  $this
    ->saveHtmlOutput();
  $this
    ->assertSession()
    ->pageTextContains('This action cannot be undone.');
  $this
    ->submitForm([], 'Delete');
  $type_exists = (bool) ShipmentType::load($type
    ->id());
  $this
    ->assertEmpty($type_exists);
}