TaxonomyTermTestCase::testTermMultipleParentsInterface

7 taxonomy.test TaxonomyTermTestCase::testTermMultipleParentsInterface()
8 taxonomy.test TaxonomyTermTestCase::testTermMultipleParentsInterface()

Test saving a term with multiple parents through the UI.

File

modules/taxonomy/taxonomy.test, line 898
Tests for taxonomy.module.

Code

function testTermMultipleParentsInterface() {
  // Add a new term to the vocabulary so that we can have multiple parents.
  $parent = $this->createTerm($this->vocabulary);

  // Add a new term with multiple parents.
  $edit = array(
    'name' => $this->randomName(12), 
    'description[value]' => $this->randomName(100), 
    'parent[]' => array(0, $parent->tid),
  );
  // Save the new term.
  $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add', $edit, t('Save'));

  // Check that the term was successfully created.
  $terms = taxonomy_get_term_by_name($edit['name']);
  $term = reset($terms);
  $this->assertNotNull($term, t('Term found in database'));
  $this->assertEqual($edit['name'], $term->name, t('Term name was successfully saved.'));
  $this->assertEqual($edit['description[value]'], $term->description, t('Term description was successfully saved.'));
  // Check that the parent tid is still there. The other parent (<root>) is
  // not added by taxonomy_get_parents().
  $parents = taxonomy_get_parents($term->tid);
  $parent = reset($parents);
  $this->assertEqual($edit['parent[]'][1], $parent->tid, t('Term parents were successfully saved.'));
}
Login or register to post comments