| 7 taxonomy.test | TaxonomyTermFieldTestCase::testTaxonomyTermFieldChangeMachineName() |
| 8 taxonomy.test | TaxonomyTermFieldTestCase::testTaxonomyTermFieldChangeMachineName() |
Tests that vocabulary machine name changes are mirrored in field definitions.
File
- modules/
taxonomy/ taxonomy.test, line 1532 - Tests for taxonomy.module.
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->machine_name,
'parent' => '0',
),
array(
'vocabulary' => $this->vocabulary->machine_name,
'parent' => '0',
),
array(
'vocabulary' => 'foo',
'parent' => '0',
),
);
field_update_field($this->field);
// Change the machine name.
$old_name = $this->vocabulary->machine_name;
$new_name = drupal_strtolower($this->randomName());
$this->vocabulary->machine_name = $new_name;
taxonomy_vocabulary_save($this->vocabulary);
// Check that entity bundles are properly updated.
$info = entity_get_info('taxonomy_term');
$this->assertFalse(isset($info['bundles'][$old_name]), t('The old bundle name does not appear in entity_get_info().'));
$this->assertTrue(isset($info['bundles'][$new_name]), t('The new bundle name appears in entity_get_info().'));
// 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, t('Index 0: Machine name was updated correctly.'));
$this->assertEqual($allowed_values[1]['vocabulary'], $new_name, t('Index 1: Machine name was updated correctly.'));
$this->assertEqual($allowed_values[2]['vocabulary'], 'foo', t('Index 2: Machine name was left untouched.'));
}
Login or register to post comments