1 taxonomy.test TaxonomyTermTestCase::testTaxonomyNode()

Test that hook_node_$op implementations work correctly.

Save & edit a node and assert that taxonomy terms are saved/loaded properly.

File

core/modules/taxonomy/tests/taxonomy.test, line 570
Tests for taxonomy.module.

Class

TaxonomyTermTestCase
Tests for taxonomy term functions.

Code

function testTaxonomyNode() {
  // Create two taxonomy terms.
  $term1 = $this->createTerm($this->vocabulary);
  $term2 = $this->createTerm($this->vocabulary);

  // Post a post.
  $edit = array();
  $langcode = LANGUAGE_NONE;
  $edit["title"] = $this->randomName();
  $edit["body[$langcode][0][value]"] = $this->randomName();
  $edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term1->tid;
  $this->backdropPost('node/add/post', $edit, t('Save'));

  // Check that the term is displayed when the node is viewed.
  $node = $this->backdropGetNodeByTitle($edit["title"]);
  $this->backdropGet('node/' . $node->nid);
  $this->assertText($term1->name, 'Term is displayed when viewing the node.');

  // Edit the node with a different term.
  $edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term2->tid;
  $this->backdropPost('node/' . $node->nid . '/edit', $edit, t('Save'));

  $this->backdropGet('node/' . $node->nid);
  $this->assertText($term2->name, 'Term is displayed when viewing the node.');
}