public function TaxonomyMenuUnitTest::testTaxonomyMenuTermsHierarchy in Taxonomy menu 7.2
Tests the hierarchy of menu links in a menu.
File
- tests/
taxonomy_menu.test, line 367 - Defines abstract base test class for the Taxonomy menu module tests.
Class
- TaxonomyMenuUnitTest
- Tests for taxonomy vocabulary functions.
Code
public function testTaxonomyMenuTermsHierarchy() {
$vocab_machine_name = $this->vocabulary->machine_name;
$vid = $this->vocabulary->vid;
$edit = array();
// Settings
$edit['taxonomy_menu[vocab_parent]'] = 'main-menu:0';
$this
->drupalPost('admin/structure/taxonomy/' . $vocab_machine_name . '/edit', $edit, t('Save'));
$this
->assertResponse(200);
// Given a taxonomy term, which id is tid:
// - ptid --> - plid
// - tid --> - mlid
// Do the following verification for each term in the hierarchy; the ending
// plid determined by the methods below should be equal.
// - method1: tid --> mlid --> plid
// - method2: tid --> ptid --> plid
foreach ($this->terms_hierarchy as $term) {
// 1. Get plid by getting the associated mlid for the term tid.
$mlid = _taxonomy_menu_get_mlid($term->tid, $vid);
if ($mlid) {
$menu_link = menu_link_load($mlid);
$plid_from_mlid = $menu_link['plid'];
// 2. Get plid by getting the associated mlid for the parent term ptid.
// We don't handle multiple parents, break after first one.
$parents = taxonomy_get_parents($term->tid);
if (!empty($parents)) {
foreach ($parents as $ptid => $parent) {
$plid_from_ptid = _taxonomy_menu_get_mlid($ptid, $vid);
// Assert that both plid found by the two different methods are equal.
$message = 'Parent mlids from taxonomy term ' . $term->tid . ' are a match.';
$this
->assertEqual($plid_from_mlid, $plid_from_ptid, $message);
break;
}
}
else {
// Current term has no parent term. This means that the name of the
// vocabulary should be associated to the 'navigation' root.
// Menu link of the current term as defined by taxonomy menu table.
$this
->assertEqual($menu_link['plid'], 0);
}
}
else {
$this
->fail("mlid for taxonomy term " . $term->tid . " could not be found.");
}
}
}