function TaxonomyVocabularyTestCase::testTaxonomyVocabularyChangeMachineName

7.x taxonomy.test TaxonomyVocabularyTestCase::testTaxonomyVocabularyChangeMachineName()

Tests that machine name changes are properly reflected.

File

drupal-7.x/modules/taxonomy/taxonomy.test, line 345
Tests for taxonomy.module.

Class

TaxonomyVocabularyTestCase
Tests for taxonomy vocabulary functions.

Code

function testTaxonomyVocabularyChangeMachineName() {
  // Add a field instance to the vocabulary.
  $field = array(
    'field_name' => 'field_test',
    'type' => 'test_field',
  );
  field_create_field($field);
  $instance = array(
    'field_name' => 'field_test',
    'entity_type' => 'taxonomy_term',
    'bundle' => $this->vocabulary->machine_name,
  );
  field_create_instance($instance);

  // Change the machine name.
  $new_name = drupal_strtolower($this->randomName());
  $this->vocabulary->machine_name = $new_name;
  taxonomy_vocabulary_save($this->vocabulary);

  // Check that the field instance is still attached to the vocabulary.
  $this->assertTrue(field_info_instance('taxonomy_term', 'field_test', $new_name), 'The bundle name was updated correctly.');
}