function ConfigImportUITest::testEntityBundleDelete

Same name and namespace in other branches
  1. 9 core/modules/config/tests/src/Functional/ConfigImportUITest.php \Drupal\Tests\config\Functional\ConfigImportUITest::testEntityBundleDelete()
  2. 8.9.x core/modules/config/tests/src/Functional/ConfigImportUITest.php \Drupal\Tests\config\Functional\ConfigImportUITest::testEntityBundleDelete()
  3. 11.x core/modules/config/tests/src/Functional/ConfigImportUITest.php \Drupal\Tests\config\Functional\ConfigImportUITest::testEntityBundleDelete()

Tests the config importer cannot delete bundles with existing entities.

See also

\Drupal\Core\Entity\Event\BundleConfigImportValidate

File

core/modules/config/tests/src/Functional/ConfigImportUITest.php, line 463

Class

ConfigImportUITest
Tests the user interface for importing configuration.

Namespace

Drupal\Tests\config\Functional

Code

public function testEntityBundleDelete() : void {
  \Drupal::service('module_installer')->install([
    'node',
  ]);
  $this->copyConfig($this->container
    ->get('config.storage'), $this->container
    ->get('config.storage.sync'));
  $node_type = $this->drupalCreateContentType();
  $node = $this->drupalCreateNode([
    'type' => $node_type->id(),
  ]);
  $this->drupalGet('admin/config/development/configuration');
  // The node type, body field and entity displays will be scheduled for
  // removal.
  $this->assertSession()
    ->pageTextContains('node.type.' . $node_type->id());
  $this->assertSession()
    ->pageTextContains('field.field.node.' . $node_type->id() . '.body');
  $this->assertSession()
    ->pageTextContains('core.entity_view_display.node.' . $node_type->id() . '.teaser');
  $this->assertSession()
    ->pageTextContains('core.entity_view_display.node.' . $node_type->id() . '.default');
  $this->assertSession()
    ->pageTextContains('core.entity_form_display.node.' . $node_type->id() . '.default');
  // Attempt to import configuration and verify that an error message appears
  // and the node type, body field and entity displays are still scheduled for
  // removal.
  $this->submitForm([], 'Import all');
  $validation_message = "Entities exist of type {$node->getEntityType()->getLabel()} and {$node->getEntityType()->getBundleLabel()} {$node_type->label()}. These entities need to be deleted before importing.";
  $this->assertSession()
    ->pageTextContains($validation_message);
  $this->assertSession()
    ->pageTextContains('node.type.' . $node_type->id());
  $this->assertSession()
    ->pageTextContains('field.field.node.' . $node_type->id() . '.body');
  $this->assertSession()
    ->pageTextContains('core.entity_view_display.node.' . $node_type->id() . '.teaser');
  $this->assertSession()
    ->pageTextContains('core.entity_view_display.node.' . $node_type->id() . '.default');
  $this->assertSession()
    ->pageTextContains('core.entity_form_display.node.' . $node_type->id() . '.default');
  // Delete the node and try to import again.
  $node->delete();
  $this->submitForm([], 'Import all');
  $this->assertSession()
    ->pageTextNotContains($validation_message);
  $this->assertSession()
    ->pageTextContains('The staged configuration is identical to the active configuration.');
  $this->assertSession()
    ->pageTextNotContains('node.type.' . $node_type->id());
  $this->assertSession()
    ->pageTextNotContains('field.field.node.' . $node_type->id() . '.body');
  $this->assertSession()
    ->pageTextNotContains('core.entity_view_display.node.' . $node_type->id() . '.teaser');
  $this->assertSession()
    ->pageTextNotContains('core.entity_view_display.node.' . $node_type->id() . '.default');
  $this->assertSession()
    ->pageTextNotContains('core.entity_form_display.node.' . $node_type->id() . '.default');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.