diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test
index aa7cc2e..92d1350 100644
--- a/modules/taxonomy/taxonomy.test
+++ b/modules/taxonomy/taxonomy.test
@@ -829,6 +829,204 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
 }
 
 /**
+ * Tests for taxonomy term index.
+ */
+class TaxonomyTermIndexTestCase extends TaxonomyWebTestCase {
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Taxonomy term index',
+      'description' => 'Test the index of tid to nid (taxonomy_index).',
+      'group' => 'Taxonomy',
+    );
+  }
+
+  function setUp() {
+    parent::setUp('taxonomy');
+    $this->admin_user = $this->drupalCreateUser(array('administer taxonomy', 'bypass node access'));
+    $this->drupalLogin($this->admin_user);
+    $this->vocabulary = $this->createVocabulary();
+
+    $this->field_name_1 = drupal_strtolower($this->randomName());
+    $this->field_1 = array(
+      'field_name' => $this->field_name_1,
+      'type' => 'taxonomy_term_reference',
+      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
+      'settings' => array(
+        'allowed_values' => array(
+          array(
+            'vocabulary' => $this->vocabulary->machine_name,
+            'parent' => 0,
+          ),
+        ),
+      ),
+    );
+    field_create_field($this->field_1);
+    $this->instance_1 = array(
+      'field_name' => $this->field_name_1,
+      'bundle' => 'article',
+      'entity_type' => 'node',
+      'widget' => array(
+        'type' => 'options_select',
+      ),
+      'display' => array(
+        'default' => array(
+          'type' => 'taxonomy_term_reference_link',
+        ),
+      ),
+    );
+    field_create_instance($this->instance_1);
+
+    $this->field_name_2 = drupal_strtolower($this->randomName());
+    $this->field_2 = array(
+      'field_name' => $this->field_name_2,
+      'type' => 'taxonomy_term_reference',
+      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
+      'settings' => array(
+        'allowed_values' => array(
+          array(
+            'vocabulary' => $this->vocabulary->machine_name,
+            'parent' => 0,
+          ),
+        ),
+      ),
+    );
+    field_create_field($this->field_2);
+    $this->instance_2 = array(
+      'field_name' => $this->field_name_2,
+      'bundle' => 'article',
+      'entity_type' => 'node',
+      'widget' => array(
+        'type' => 'options_select',
+      ),
+      'display' => array(
+        'default' => array(
+          'type' => 'taxonomy_term_reference_link',
+        ),
+      ),
+    );
+    field_create_instance($this->instance_2);
+  }
+
+  /**
+   * Test index.
+   */
+  function testTaxonomyIndex() {
+    // Create terms in the vocabulary.
+    $term_1 = $this->createTerm($this->vocabulary);
+    $term_2 = $this->createTerm($this->vocabulary);
+
+    // Post an article.
+    $edit = array();
+    $langcode = LANGUAGE_NONE;
+    $edit["title"] = $this->randomName();
+    $edit["body[$langcode][0][value]"] = $this->randomName();
+    $edit["{$this->field_name_1}[$langcode][]"] = $term_1->tid;
+    $edit["{$this->field_name_2}[$langcode][]"] = $term_1->tid;
+    $this->drupalPost('node/add/article', $edit, t('Save'));
+
+    // Check that the term is indexed, and only once.
+    $node = $this->drupalGetNodeByTitle($edit["title"]);
+    $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
+      ':nid' => $node->nid,
+      ':tid' => $term_1->tid,
+    ))->fetchField();
+    $this->assertEqual(1, $index_count, t('Term 1 is indexed.'));
+
+    // Update the article to change one term.
+    $edit["{$this->field_name_1}[$langcode][]"] = $term_2->tid;
+    $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
+
+    // Check that both terms are indexed.
+    $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
+      ':nid' => $node->nid,
+      ':tid' => $term_1->tid,
+    ))->fetchField();
+    $this->assertEqual(1, $index_count, t('Term 1 is indexed.'));
+    $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
+      ':nid' => $node->nid,
+      ':tid' => $term_2->tid,
+    ))->fetchField();
+    $this->assertEqual(1, $index_count, t('Term 2 is indexed.'));
+
+    // Update the article to change another term.
+    $edit["{$this->field_name_2}[$langcode][]"] = $term_2->tid;
+    $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
+
+    // Check that only one term is indexed.
+    $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
+      ':nid' => $node->nid,
+      ':tid' => $term_1->tid,
+    ))->fetchField();
+    $this->assertEqual(0, $index_count, t('Term 1 is not indexed.'));
+    $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
+      ':nid' => $node->nid,
+      ':tid' => $term_2->tid,
+    ))->fetchField();
+    $this->assertEqual(1, $index_count, t('Term 2 is indexed.'));
+
+    // Redo the above tests without interface.
+    $update_node = array(
+      'nid' => $node->nid,
+      'vid' => $node->vid,
+      'uid' => $node->uid,
+      'type' => $node->type,
+      'title' => $this->randomName(),
+    );
+
+    // Update the article with no term changed.
+    $updated_node = (object) $update_node;
+    node_save($updated_node);
+
+    // Check that the index was not changed.
+    $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
+      ':nid' => $node->nid,
+      ':tid' => $term_1->tid,
+    ))->fetchField();
+    $this->assertEqual(0, $index_count, t('Term 1 is not indexed.'));
+    $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
+      ':nid' => $node->nid,
+      ':tid' => $term_2->tid,
+    ))->fetchField();
+    $this->assertEqual(1, $index_count, t('Term 2 is indexed.'));
+
+    // Update the article to change one term.
+    $update_node[$this->field_name_1][$langcode] = array(array('tid' => $term_1->tid));
+    $updated_node = (object) $update_node;
+    node_save($updated_node);
+
+    // Check that both terms are indexed.
+    $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
+      ':nid' => $node->nid,
+      ':tid' => $term_1->tid,
+    ))->fetchField();
+    $this->assertEqual(1, $index_count, t('Term 1 is indexed.'));
+    $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
+      ':nid' => $node->nid,
+      ':tid' => $term_2->tid,
+    ))->fetchField();
+    $this->assertEqual(1, $index_count, t('Term 2 is indexed.'));
+
+    // Update the article to change another term.
+    $update_node[$this->field_name_2][$langcode] = array(array('tid' => $term_1->tid));
+    $updated_node = (object) $update_node;
+    node_save($updated_node);
+
+    // Check that only one term is indexed.
+    $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
+      ':nid' => $node->nid,
+      ':tid' => $term_1->tid,
+    ))->fetchField();
+    $this->assertEqual(1, $index_count, t('Term 1 is not indexed.'));
+    $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
+      ':nid' => $node->nid,
+      ':tid' => $term_2->tid,
+    ))->fetchField();
+    $this->assertEqual(0, $index_count, t('Term 2 is indexed.'));
+  }
+}
+
+/**
  * Test the taxonomy_term_load_multiple() function.
  */
 class TaxonomyLoadMultipleUnitTest extends TaxonomyWebTestCase {
