You are here

public function StoreTypeTest::testDelete in Commerce Core 8.2

Tests deleting a product type.

File

modules/store/tests/src/Functional/StoreTypeTest.php, line 86

Class

StoreTypeTest
Tests the store type UI.

Namespace

Drupal\Tests\commerce_store\Functional

Code

public function testDelete() {

  /** @var \Drupal\commerce_store\Entity\StoreTypeInterface $store_type */
  $store_type = $this
    ->createEntity('commerce_store_type', [
    'id' => 'foo',
    'label' => 'Label for foo',
  ]);
  $store = $this
    ->createStore(NULL, NULL, $store_type
    ->id());

  // Confirm that the type can't be deleted while there's a store.
  $this
    ->drupalGet($store_type
    ->toUrl('delete-form'));
  $this
    ->assertSession()
    ->pageTextContains(t('@type is used by 1 store on your site. You cannot remove this store type until you have removed all of the @type stores.', [
    '@type' => $store_type
      ->label(),
  ]));
  $this
    ->assertSession()
    ->pageTextNotContains('This action cannot be undone.');
  $this
    ->assertSession()
    ->pageTextNotContains('The store type deletion confirmation form is not available');

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

  // Delete the store, unlock the type, confirm that deletion works.
  $store
    ->delete();
  $store_type
    ->unlock();
  $store_type
    ->save();
  $this
    ->drupalGet($store_type
    ->toUrl('delete-form'));
  $this
    ->assertSession()
    ->pageTextContains(t('Are you sure you want to delete the store type @type?', [
    '@type' => $store_type
      ->label(),
  ]));
  $this
    ->saveHtmlOutput();
  $this
    ->assertSession()
    ->pageTextContains('This action cannot be undone.');
  $this
    ->submitForm([], 'Delete');
  $store_type_exists = (bool) StoreType::load($store_type
    ->id());
  $this
    ->assertEmpty($store_type_exists);
}