function VocabularyCrudTest::testUninstallReinstall

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php \Drupal\Tests\taxonomy\Kernel\VocabularyCrudTest::testUninstallReinstall()
  2. 8.9.x core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php \Drupal\Tests\taxonomy\Kernel\VocabularyCrudTest::testUninstallReinstall()
  3. 11.x 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 129

Class

VocabularyCrudTest
Tests loading, saving and deleting vocabularies.

Namespace

Drupal\Tests\taxonomy\Kernel

Code

public function testUninstallReinstall() : void {
  $vocabulary = $this->createVocabulary();
  // Field storages and fields attached to taxonomy term bundles should be
  // removed when the module is uninstalled.
  $field_name = $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();
}

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