1 taxonomy.test TaxonomyVocabularyUnitTest::testUninstallReinstall()

Test uninstall and reinstall of the taxonomy module.

File

core/modules/taxonomy/tests/taxonomy.test, line 384
Tests for taxonomy.module.

Class

TaxonomyVocabularyUnitTest
Tests for taxonomy vocabulary functions.

Code

function testUninstallReinstall() {
  // Fields and field instances attached to taxonomy term bundles should be
  // removed when the module is uninstalled.
  $field_name = backdrop_strtolower($this->randomName() . '_field_name');
  $field = array(
    'field_name' => $field_name,
    'type' => 'text',
    'cardinality' => 4,
  );
  $field = field_create_field($field);
  $instance = array(
    'field_name' => $field_name,
    'entity_type' => 'taxonomy_term',
    'bundle' => $this->vocabulary->machine_name,
    'label' => $this->randomName() . '_label',
  );
  field_create_instance($instance);

  module_disable(array('taxonomy'));
  require_once BACKDROP_ROOT . '/core/includes/install.inc';
  backdrop_uninstall_modules(array('taxonomy'));
  module_enable(array('taxonomy'));

  // Now create a vocabulary with the same name. All field instances
  // 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.
  taxonomy_vocabulary_save($this->vocabulary);
  unset($field['id']);
  field_create_field($field);
  field_create_instance($instance);
}