You are here

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

Tests entity type deletion if fields are present.

@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 324

Class

NavigationalStructureTest
Test Entity Construction Kit's navigational structure.

Namespace

Drupal\Tests\eck\Functional

Code

public function entityTypeDeleteWithField() {

  // Delete the original bundle.
  \Drupal::entityTypeManager()
    ->getStorage($this->entityTypeMachineName . '_type')
    ->load($this->entityBundleMachineName)
    ->delete();

  // Create a bundle with matching name.
  $this->entityBundleMachineName = $this->entityTypeMachineName;
  $this->entityBundleLabel = $this->entityTypeLabel;
  $this
    ->createEntityBundle($this->entityTypeMachineName, $this->entityBundleLabel);
  FieldStorageConfig::create([
    'entity_type' => $this->entityTypeMachineName,
    'field_name' => 'field_decimal',
    'type' => 'decimal',
  ])
    ->save();
  FieldConfig::create([
    'entity_type' => $this->entityTypeMachineName,
    'field_name' => 'field_decimal',
    'bundle' => $this->entityBundleMachineName,
  ])
    ->save();
  $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.");
  $this
    ->assertSession()
    ->pageTextContains("Configuration deletions The listed configuration will be deleted.{$this->entityTypeLabel} type{$this->entityTypeLabel}Fieldfield_decimal");

  // Delete the entity.
  $this
    ->submitForm([], 'Delete entity type');
  $this
    ->assertSession()
    ->responseContains('The eck entity type <em class="placeholder">' . $this->entityTypeLabel . '</em> has been deleted.');

  // Try to load the deleted entity type definition.
  $entity_type = \Drupal::entityTypeManager()
    ->clearCachedDefinitions();
  \Drupal::entityTypeManager()
    ->getDefinition($this->entityTypeMachineName, FALSE);

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