function TermFieldTest::testTaxonomyTermFieldChangeMachineName

Tests that vocabulary machine name changes are mirrored in field definitions.

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php, line 150
Definition of Drupal\taxonomy\Tests\TermFieldTest.

Class

TermFieldTest
Tests for taxonomy term field and formatter.

Namespace

Drupal\taxonomy\Tests

Code

function testTaxonomyTermFieldChangeMachineName() {

  // Add several entries in the 'allowed_values' setting, to make sure that
  // they all get updated.
  $this->field['settings']['allowed_values'] = array(
    array(
      'vocabulary' => $this->vocabulary
        ->id(),
      'parent' => '0',
    ),
    array(
      'vocabulary' => $this->vocabulary
        ->id(),
      'parent' => '0',
    ),
    array(
      'vocabulary' => 'foo',
      'parent' => '0',
    ),
  );
  field_update_field($this->field);

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

  // Check that the field instance is still attached to the vocabulary.
  $field = field_info_field($this->field_name);
  $allowed_values = $field['settings']['allowed_values'];
  $this
    ->assertEqual($allowed_values[0]['vocabulary'], $new_name, 'Index 0: Machine name was updated correctly.');
  $this
    ->assertEqual($allowed_values[1]['vocabulary'], $new_name, 'Index 1: Machine name was updated correctly.');
  $this
    ->assertEqual($allowed_values[2]['vocabulary'], 'foo', 'Index 2: Machine name was left untouched.');
}