public function TaxonomyMenuUnitTest::testTaxonomyMenuCRUD in Taxonomy menu 8
Tests CRUD functions.
File
- lib/
Drupal/ taxonomy_menu/ Tests/ TaxonomyMenuUnitTest.php, line 51 - Contains \Drupal\taxonomy_menu\Tests\TaxonomyMenuUnitTest.
Class
- TaxonomyMenuUnitTest
- Tests for taxonomy vocabulary functions.
Namespace
Drupal\taxonomy_menu\TestsCode
public function testTaxonomyMenuCRUD() {
$menu_name = 'main';
$vocabulary = $this->vocabulary;
$terms = $this->terms_hierarchy;
$hierarchy_term = $this->terms_hierarchy[3];
$vid = $this->vocabulary
->id();
// Ensure that the taxonomy vocabulary form is successfully submitted.
$edit['taxonomy_menu[vocab_parent]'] = $menu_name . ':0';
$this
->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
$this
->assertResponse(200);
// Ensure that the same number of menu links are created from the taxonomy
// terms of the vocabulary.
$this
->assertEqualNumberTermsMenuLinks(count($terms), $vocabulary, $menu_name);
// Ensure that the menu link is updated when the taxonomy term is updated.
$new_name = $this
->randomName();
$hierarchy_term->name = $new_name;
$hierarchy_term
->save();
$this
->drupalGet('admin/structure/menu/manage/' . $menu_name);
$this
->assertLink($new_name);
// Ensure that the menu link is deleted when the taxonomy term is deleted.
// Hierarchy term [3] has 1 children, if we delete it, 2 taxonomy terms
// should be deleted.
$orig_mlid = _taxonomy_menu_get_mlid($hierarchy_term
->id(), $vid);
entity_load('taxonomy_term', $hierarchy_term
->id())
->delete();
$this
->assertEqualNumberTermsMenuLinks(count($terms) - 2, $vocabulary, $menu_name);
$menu_link = menu_link_load($orig_mlid);
$message = 'The menu link ' . $orig_mlid . ' associated to the term ' . $hierarchy_term
->id() . ' could not be found.';
$this
->assertFalse($menu_link, $message);
$mlid = _taxonomy_menu_get_mlid($hierarchy_term
->id(), $vid);
$message = 'The ( mlid = ' . $orig_mlid . ' / tid = ' . $hierarchy_term
->id() . ') association could not be found in {taxonomy_menu} table.';
$this
->assertFalse($mlid, $message);
// Ensure that all menu links and all associations in {taxonomy_menu} table
// are deleted when a vocabulary is deleted.
$mlids = _taxonomy_menu_get_menu_items($vid);
$vocabulary
->delete();
$this
->assertEqualNumberTermsMenuLinks(0, $vocabulary, $menu_name);
}