function TermTest::testTermMultipleParentsInterface

Test saving a term with multiple parents through the UI.

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php, line 426
Definition of Drupal\taxonomy\Tests\TermTest.

Class

TermTest
Tests for taxonomy term functions.

Namespace

Drupal\taxonomy\Tests

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
        ->id(),
    ),
  );

  // Save the new term.
  $this
    ->drupalPost('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id() . '/add', $edit, t('Save'));

  // Check that the term was successfully created.
  $terms = taxonomy_term_load_multiple_by_name($edit['name']);
  $term = reset($terms);
  $this
    ->assertNotNull($term, 'Term found in database.');
  $this
    ->assertEqual($edit['name'], $term
    ->label(), 'Term name was successfully saved.');
  $this
    ->assertEqual($edit['description[value]'], $term->description->value, 'Term description was successfully saved.');

  // Check that the parent tid is still there. The other parent (<root>) is
  // not added by taxonomy_term_load_parents().
  $parents = taxonomy_term_load_parents($term
    ->id());
  $parent = reset($parents);
  $this
    ->assertEqual($edit['parent[]'][1], $parent
    ->id(), 'Term parents were successfully saved.');
}