Test that hook_node_$op implementations work correctly.
Save & edit a node and assert that taxonomy terms are saved/loaded properly.
function testTaxonomyNode() {
// Create two taxonomy terms.
$term1 = $this
->createTerm($this->vocabulary);
$term2 = $this
->createTerm($this->vocabulary);
// Post an article.
$edit = array();
$langcode = LANGUAGE_NOT_SPECIFIED;
$edit["title"] = $this
->randomName();
$edit["body[{$langcode}][0][value]"] = $this
->randomName();
$edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term1->tid;
$this
->drupalPost('node/add/article', $edit, t('Save'));
// Check that the term is displayed when the node is viewed.
$node = $this
->drupalGetNodeByTitle($edit["title"]);
$this
->drupalGet('node/' . $node->nid);
$this
->assertText($term1->name, 'Term is displayed when viewing the node.');
$this
->clickLink(t('Edit'));
$this
->assertText($term1->name, 'Term is displayed when editing the node.');
$this
->drupalPost(NULL, array(), t('Save'));
$this
->assertText($term1->name, 'Term is displayed after saving the node with no changes.');
// Edit the node with a different term.
$edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term2->tid;
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this
->drupalGet('node/' . $node->nid);
$this
->assertText($term2->name, 'Term is displayed when viewing the node.');
// Preview the node.
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Preview'));
$this
->assertNoUniqueText($term2->name, 'Term is displayed when previewing the node.');
$this
->drupalPost(NULL, NULL, t('Preview'));
$this
->assertNoUniqueText($term2->name, 'Term is displayed when previewing the node again.');
}