function TermTest::testTermMultipleParentsInterface
Same name in other branches
- 9 core/modules/taxonomy/tests/src/Functional/TermTest.php \Drupal\Tests\taxonomy\Functional\TermTest::testTermMultipleParentsInterface()
- 10 core/modules/taxonomy/tests/src/Functional/TermTest.php \Drupal\Tests\taxonomy\Functional\TermTest::testTermMultipleParentsInterface()
- 11.x core/modules/taxonomy/tests/src/Functional/TermTest.php \Drupal\Tests\taxonomy\Functional\TermTest::testTermMultipleParentsInterface()
Test saving a term with multiple parents through the UI.
File
-
core/
modules/ taxonomy/ tests/ src/ Functional/ TermTest.php, line 469
Class
- TermTest
- Tests load, save and delete for taxonomy terms.
Namespace
Drupal\Tests\taxonomy\FunctionalCode
public 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 = [
'name[0][value]' => $this->randomMachineName(12),
'description[0][value]' => $this->randomMachineName(100),
'parent[]' => [
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_type.manager')
->getStorage('taxonomy_term')
->loadParents($term->id());
$parent = reset($parents);
$this->assertEqual($edit['parent[]'][1], $parent->id(), 'Term parents were successfully saved.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.