public function TaxonomyMenuConfigurationTest::testTaxonomyMenuHideEmptyTerms in Taxonomy menu 7.2
Tests Taxonommy Menu "Hide Empty terms" option.
File
- tests/
taxonomy_menu.test, line 653 - Defines abstract base test class for the Taxonomy menu module tests.
Class
- TaxonomyMenuConfigurationTest
- Tests Taxonomy menu configuration options.
Code
public function testTaxonomyMenuHideEmptyTerms() {
$voc_machine_name = $this->vocabulary->machine_name;
// Create several nodes and attach them to different terms of our hierarchy
// in order to match the following scheme.
/** terms[1] | depth: 0 | 0 node -> hidden
* -- terms[2] | depth: 1 | 0 node -> hidden
* -- terms[3] | depth: 1 | 2 nodes -> displayed
* ---- terms[4] | depth: 2 | 0 node -> hidden
* -- terms[5] | depth: 1 | 1 node -> displayed
* terms[6] | depth: 0 | 0 node -> hidden
* -- terms[7] | depth: 1 | 0 node -> hidden */
$this
->setUpTermReferenceAndNodes('article', array(
3,
3,
5,
));
// Set settings (don't hide empty terms) and save.
$edit = array(
'taxonomy_menu[vocab_parent]' => 'main-menu:0',
'taxonomy_menu[options_structure][hide_empty_terms]' => FALSE,
);
$this
->drupalPost('admin/structure/taxonomy/' . $voc_machine_name . '/edit', $edit, t('Save'));
// Assert that all links are displayed.
foreach ($this->terms_hierarchy as $term) {
$mlid = _taxonomy_menu_get_mlid($term->tid, $this->vocabulary->vid);
if ($mlid) {
$this
->assertMenuLink($mlid, array(
'hidden' => FALSE,
));
}
else {
$this
->fail('No mlid could be found for the term ' . $term->tid);
}
}
// Set settings (hide empty terms) and save.
$edit['taxonomy_menu[options_structure][hide_empty_terms]'] = TRUE;
$this
->drupalPost('admin/structure/taxonomy/' . $voc_machine_name . '/edit', $edit, t('Save'));
// Assert that the hidden property of the taxonomy menu's menu links are
// set according to the scheme.
$visible_terms_index = array(
3,
5,
);
$index = 1;
foreach ($this->terms_hierarchy as $term) {
$mlid = _taxonomy_menu_get_mlid($term->tid, $this->vocabulary->vid);
if ($mlid) {
if (in_array($index, $visible_terms_index)) {
$this
->assertMenuLink($mlid, array(
'hidden' => FALSE,
));
}
else {
$this
->assertMenuLink($mlid, array(
'hidden' => TRUE,
));
}
}
else {
$this
->fail('No mlid could be found for the term ' . $term->tid);
}
$index++;
}
}