You are here

public function NavigationalStructureTest::entityTypeDeleteWithMatchingBundle in Entity Construction Kit (ECK) 8

Tests entity type deletion with matching bundle.

@test

Throws

\Behat\Mink\Exception\ExpectationException

\Behat\Mink\Exception\ResponseTextException

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

File

tests/src/Functional/NavigationalStructureTest.php, line 274

Class

NavigationalStructureTest
Test Entity Construction Kit's navigational structure.

Namespace

Drupal\Tests\eck\Functional

Code

public function entityTypeDeleteWithMatchingBundle() {
  $this
    ->createEntityBundle($this->entityTypeMachineName, $this->entityTypeLabel);
  $this->entityBundleMachineName = $this->entityTypeMachineName;
  $this->entityBundleLabel = $this->entityTypeLabel;
  \Drupal::entityTypeManager()
    ->getStorage($this->entityTypeMachineName . '_type')
    ->load($this->entityBundleMachineName)
    ->delete();
  $route = 'entity.eck_entity_type.delete_form';
  $routeArguments = [
    'eck_entity_type' => $this->entityTypeMachineName,
  ];
  $expectedUrl = "admin/structure/eck/{$this->entityTypeMachineName}/delete";
  $expectedTitle = "Are you sure you want to delete entity type {$this->entityTypeLabel}?";
  $crumbs = [
    'Structure',
    'ECK Entity Types',
    "Edit entity type",
  ];
  $this
    ->assertCorrectPageOnRoute($route, $routeArguments, $expectedUrl, $expectedTitle, $crumbs);
  $this
    ->assertSession()
    ->pageTextContains("This action cannot be undone.");

  // Delete the entity.
  $this
    ->submitForm([], 'Delete entity type');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Try to load the deleted entity.
  $entity_type = \Drupal::entityTypeManager()
    ->getStorage($this->entityTypeMachineName)
    ->load($this->entityTypeMachineName);

  // Make sure the entity is deleted.
  $this
    ->assertNull($entity_type);
  $this
    ->entityTypeList();
}