public function VocabularyCrudTest::testUninstallReinstall in Drupal 10
Same name and namespace in other branches
- 8 core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php \Drupal\Tests\taxonomy\Kernel\VocabularyCrudTest::testUninstallReinstall()
- 9 core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php \Drupal\Tests\taxonomy\Kernel\VocabularyCrudTest::testUninstallReinstall()
Tests uninstall and reinstall of the taxonomy module.
File
- core/
modules/ taxonomy/ tests/ src/ Kernel/ VocabularyCrudTest.php, line 127
Class
- VocabularyCrudTest
- Tests loading, saving and deleting vocabularies.
Namespace
Drupal\Tests\taxonomy\KernelCode
public function testUninstallReinstall() {
$vocabulary = $this
->createVocabulary();
// Field storages and fields attached to taxonomy term bundles should be
// removed when the module is uninstalled.
$field_name = mb_strtolower($this
->randomMachineName() . '_field_name');
$storage_definition = [
'field_name' => $field_name,
'entity_type' => 'taxonomy_term',
'type' => 'text',
'cardinality' => 4,
];
FieldStorageConfig::create($storage_definition)
->save();
$field_definition = [
'field_name' => $field_name,
'entity_type' => 'taxonomy_term',
'bundle' => $vocabulary
->id(),
'label' => $this
->randomMachineName() . '_label',
];
FieldConfig::create($field_definition)
->save();
// Remove the third party setting from the memory copy of the vocabulary.
// We keep this invalid copy around while the taxonomy module is not even
// installed for testing below.
$vocabulary
->unsetThirdPartySetting('taxonomy_crud', 'foo');
$this->container
->get('module_installer')
->uninstall([
'taxonomy',
]);
$this->container
->get('module_installer')
->install([
'taxonomy',
]);
// Now create a vocabulary with the same name. All fields connected to this
// vocabulary name should have been removed when the module was uninstalled.
// Creating a new field with the same name and an instance of this field on
// the same bundle name should be successful.
$vocabulary
->enforceIsNew()
->save();
FieldStorageConfig::create($storage_definition)
->save();
FieldConfig::create($field_definition)
->save();
}