public function BundlePluginTest::testBundlePluginModuleUninstallation in Entity API 8
Tests the uninstallation for a bundle provided by a module.
File
- tests/
src/ Kernel/ BundlePluginTest.php, line 101
Class
- BundlePluginTest
- Tests the bundle plugin API.
Namespace
Drupal\Tests\entity\KernelCode
public function testBundlePluginModuleUninstallation() {
/** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
$module_installer = $this->container
->get('module_installer');
// One should be possible to uninstall without any actual content.
$violations = $module_installer
->validateUninstall([
'entity_module_bundle_plugin_examples_test',
]);
$this
->assertEmpty($violations);
$first_entity = EntityTestBundlePlugin::create([
'type' => 'first',
'first_mail' => 'admin@test.com',
]);
$first_entity
->save();
$second_entity = EntityTestBundlePlugin::create([
'type' => 'second',
'second_mail' => 'admin@example.com',
]);
$second_entity
->save();
$violations = $module_installer
->validateUninstall([
'entity_module_bundle_plugin_examples_test',
]);
$this
->assertCount(1, $violations);
$this
->assertCount(1, $violations['entity_module_bundle_plugin_examples_test']);
$this
->assertEquals('There is data for the bundle Second on the entity type Entity test bundle plugin. Please remove all content before uninstalling the module.', $violations['entity_module_bundle_plugin_examples_test'][0]);
$second_entity
->delete();
// The first entity is defined by entity_module_bundle_plugin_test, so it should be possible
// to uninstall the module providing the second bundle plugin.
$violations = $module_installer
->validateUninstall([
'entity_module_bundle_plugin_examples_test',
]);
$this
->assertEmpty($violations);
$module_installer
->uninstall([
'entity_module_bundle_plugin_examples_test',
]);
// The first entity is provided by entity_module_bundle_plugin_test which we cannot uninstall,
// until all the entities are deleted.
$violations = $module_installer
->validateUninstall([
'entity_module_bundle_plugin_test',
]);
$this
->assertNotEmpty($violations);
$first_entity
->delete();
$violations = $module_installer
->validateUninstall([
'entity_module_bundle_plugin_test',
]);
$this
->assertEmpty($violations);
}