public function ConfigImportUITest::testEntityBundleDelete in Drupal 8
Same name and namespace in other branches
- 9 core/modules/config/tests/src/Functional/ConfigImportUITest.php \Drupal\Tests\config\Functional\ConfigImportUITest::testEntityBundleDelete()
- 10 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 456
Class
- ConfigImportUITest
- Tests the user interface for importing configuration.
Namespace
Drupal\Tests\config\FunctionalCode
public function testEntityBundleDelete() {
\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
->assertText(new FormattableMarkup('node.type.@type', [
'@type' => $node_type
->id(),
]));
$this
->assertText(new FormattableMarkup('field.field.node.@type.body', [
'@type' => $node_type
->id(),
]));
$this
->assertText(new FormattableMarkup('core.entity_view_display.node.@type.teaser', [
'@type' => $node_type
->id(),
]));
$this
->assertText(new FormattableMarkup('core.entity_view_display.node.@type.default', [
'@type' => $node_type
->id(),
]));
$this
->assertText(new FormattableMarkup('core.entity_form_display.node.@type.default', [
'@type' => $node_type
->id(),
]));
// 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
->drupalPostForm(NULL, [], t('Import all'));
$validation_message = t('Entities exist of type %entity_type and %bundle_label %bundle. These entities need to be deleted before importing.', [
'%entity_type' => $node
->getEntityType()
->getLabel(),
'%bundle_label' => $node
->getEntityType()
->getBundleLabel(),
'%bundle' => $node_type
->label(),
]);
$this
->assertRaw($validation_message);
$this
->assertText(new FormattableMarkup('node.type.@type', [
'@type' => $node_type
->id(),
]));
$this
->assertText(new FormattableMarkup('field.field.node.@type.body', [
'@type' => $node_type
->id(),
]));
$this
->assertText(new FormattableMarkup('core.entity_view_display.node.@type.teaser', [
'@type' => $node_type
->id(),
]));
$this
->assertText(new FormattableMarkup('core.entity_view_display.node.@type.default', [
'@type' => $node_type
->id(),
]));
$this
->assertText(new FormattableMarkup('core.entity_form_display.node.@type.default', [
'@type' => $node_type
->id(),
]));
// Delete the node and try to import again.
$node
->delete();
$this
->drupalPostForm(NULL, [], t('Import all'));
$this
->assertNoRaw($validation_message);
$this
->assertText(t('There are no configuration changes to import.'));
$this
->assertNoText(new FormattableMarkup('node.type.@type', [
'@type' => $node_type
->id(),
]));
$this
->assertNoText(new FormattableMarkup('field.field.node.@type.body', [
'@type' => $node_type
->id(),
]));
$this
->assertNoText(new FormattableMarkup('core.entity_view_display.node.@type.teaser', [
'@type' => $node_type
->id(),
]));
$this
->assertNoText(new FormattableMarkup('core.entity_view_display.node.@type.default', [
'@type' => $node_type
->id(),
]));
$this
->assertNoText(new FormattableMarkup('core.entity_form_display.node.@type.default', [
'@type' => $node_type
->id(),
]));
}