function TermTest::testTermMultipleParentsInterface in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/taxonomy/src/Tests/TermTest.php \Drupal\taxonomy\Tests\TermTest::testTermMultipleParentsInterface()
Test saving a term with multiple parents through the UI.
File
- core/
modules/ taxonomy/ src/ Tests/ TermTest.php, line 440 - Contains \Drupal\taxonomy\Tests\TermTest.
Class
- TermTest
- Tests load, save and delete for taxonomy terms.
Namespace
Drupal\taxonomy\TestsCode
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[0][value]' => $this
->randomMachineName(12),
'description[0][value]' => $this
->randomMachineName(100),
'parent[]' => array(
0,
$parent
->id(),
),
);
// Save the new term.
$this
->drupalPostForm('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[0][value]']);
$term = reset($terms);
$this
->assertNotNull($term, 'Term found in database.');
$this
->assertEqual($edit['name[0][value]'], $term
->getName(), 'Term name was successfully saved.');
$this
->assertEqual($edit['description[0][value]'], $term
->getDescription(), 'Term description was successfully saved.');
// Check that the parent tid is still there. The other parent (<root>) is
// not added by \Drupal\taxonomy\TermStorageInterface::loadParents().
$parents = $this->container
->get('entity.manager')
->getStorage('taxonomy_term')
->loadParents($term
->id());
$parent = reset($parents);
$this
->assertEqual($edit['parent[]'][1], $parent
->id(), 'Term parents were successfully saved.');
}