summaryrefslogtreecommitdiff
path: root/modules/taxonomy/taxonomy.test
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-10-13 05:19:26 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-10-13 05:19:26 +0000
commit3e6b9b5ea35dfb32e3c30a4d012f67c1d268a570 (patch)
treec7622db5a5d010790e58a567958a331ccb3eee6c /modules/taxonomy/taxonomy.test
parent09ba396ead3d326e7b7fab485c019fcae76f07bc (diff)
downloadbrdo-3e6b9b5ea35dfb32e3c30a4d012f67c1d268a570.tar.gz
brdo-3e6b9b5ea35dfb32e3c30a4d012f67c1d268a570.tar.bz2
#876762 by Dave Reid, yched: Fixed modules have no way of knowing if vocabulary machine names are changed.
Diffstat (limited to 'modules/taxonomy/taxonomy.test')
-rw-r--r--modules/taxonomy/taxonomy.test111
1 files changed, 69 insertions, 42 deletions
diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test
index 31d5ae4e5..174e258ac 100644
--- a/modules/taxonomy/taxonomy.test
+++ b/modules/taxonomy/taxonomy.test
@@ -192,7 +192,7 @@ class TaxonomyVocabularyUnitTest extends TaxonomyWebTestCase {
}
function setUp() {
- parent::setUp('taxonomy');
+ parent::setUp('taxonomy', 'field_test');
$admin_user = $this->drupalCreateUser(array('create article content', 'administer taxonomy'));
$this->drupalLogin($admin_user);
$this->vocabulary = $this->createVocabulary();
@@ -325,6 +325,32 @@ class TaxonomyVocabularyUnitTest extends TaxonomyWebTestCase {
// Fetch vocabulary 1 by name and ID.
$this->assertTrue(current(taxonomy_vocabulary_load_multiple(array($vocabulary1->vid), array('name' => $vocabulary1->name)))->vid == $vocabulary1->vid, t('Vocabulary loaded successfully by name and ID.'));
}
+
+ /**
+ * Tests that machine name changes are properly reflected.
+ */
+ 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), t('The bundle name was updated correctly.'));
+ }
}
/**
@@ -835,15 +861,9 @@ class TaxonomyTermFieldTestCase extends TaxonomyWebTestCase {
$web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content', 'administer taxonomy'));
$this->drupalLogin($web_user);
$this->vocabulary = $this->createVocabulary();
- }
- /**
- * Test term field validation.
- */
- function testTaxonomyTermFieldValidation() {
+ // Setup a field and instance.
$this->field_name = drupal_strtolower($this->randomName());
-
- // Create a field with settings to validate.
$this->field = array(
'field_name' => $this->field_name,
'type' => 'taxonomy_term_reference',
@@ -871,7 +891,12 @@ class TaxonomyTermFieldTestCase extends TaxonomyWebTestCase {
),
);
field_create_instance($this->instance);
+ }
+ /**
+ * Test term field validation.
+ */
+ function testTaxonomyTermFieldValidation() {
// Test valid and invalid values with field_attach_validate().
$langcode = LANGUAGE_NONE;
$entity = field_test_create_stub_entity();
@@ -901,38 +926,6 @@ class TaxonomyTermFieldTestCase extends TaxonomyWebTestCase {
* Test widgets.
*/
function testTaxonomyTermFieldWidgets() {
- // Setup a field and instance.
- $entity_type = 'test_entity';
- $this->field_name = drupal_strtolower($this->randomName());
- $this->field = array(
- 'field_name' => $this->field_name,
- 'type' => 'taxonomy_term_reference',
- 'settings' => array(
- 'allowed_values' => array(
- array(
- 'vocabulary' => $this->vocabulary->machine_name,
- 'parent' => '0',
- ),
- ),
- )
- );
- field_create_field($this->field);
- $this->instance = array(
- 'field_name' => $this->field_name,
- 'entity_type' => 'test_entity',
- 'bundle' => 'test_bundle',
- 'label' => $this->randomName() . '_label',
- 'widget' => array(
- 'type' => 'options_select',
- ),
- 'display' => array(
- 'full' => array(
- 'type' => 'taxonomy_term_reference_link',
- ),
- ),
- );
- field_create_instance($this->instance);
-
// Create a term in the vocabulary.
$term = $this->createTerm($this->vocabulary);
@@ -953,11 +946,45 @@ class TaxonomyTermFieldTestCase extends TaxonomyWebTestCase {
// Display the object.
$entity = field_test_entity_test_load($id);
$entities = array($id => $entity);
- field_attach_prepare_view($entity_type, $entities, 'full');
- $entity->content = field_attach_view($entity_type, $entity, 'full');
+ field_attach_prepare_view('test_entity', $entities, 'full');
+ $entity->content = field_attach_view('test_entity', $entity, 'full');
$this->content = drupal_render($entity->content);
$this->assertText($term->name, t('Term name is displayed'));
}
+
+ /**
+ * Tests that vocabulary machine name changes are mirrored in field definitions.
+ */
+ 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.
+ $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.
+ $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.'));
+ }
}
/**