public function TaxonomyMenuConfigurationTest::testTaxonomyMenuCountNodes in Taxonomy menu 7.2
Tests Taxonommy Menu "Node count" option.
@TODO Add a test for recursive count.
File
- tests/
taxonomy_menu.test, line 717 - Defines abstract base test class for the Taxonomy menu module tests.
Class
- TaxonomyMenuConfigurationTest
- Tests Taxonomy menu configuration options.
Code
public function testTaxonomyMenuCountNodes() {
$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. We don't use "hide empty terms".
option.
terms[1] | depth: 0 | 0 node attached
-- terms[2] | depth: 1 | 0 node attached
-- terms[3] | depth: 1 | 2 nodes attached
---- terms[4] | depth: 2 | 2 nodes attached
-- terms[5] | depth: 1 | 1 node attached
terms[6] | depth: 0 | 1 node attached
-- terms[7] | depth: 1 | 0 node attached
We expect the following result for number of items:
- terms[1]: count is 0
- terms[3]: count is 2
- terms[4]: count is 2
- terms[5]: count is 1
- terms[6]: count is 1
- Others : count is 0
*/
$this
->setUpTermReferenceAndNodes('article', array(
3,
3,
4,
4,
5,
6,
));
// Set settings and save.
$edit = array(
'taxonomy_menu[vocab_parent]' => 'main-menu:0',
'taxonomy_menu[options_structure][hide_empty_terms]' => FALSE,
'taxonomy_menu[options_markup][display_num]' => TRUE,
);
$this
->drupalPost('admin/structure/taxonomy/' . $voc_machine_name . '/edit', $edit, t('Save'));
// Assert that the count is correct in the menu links according to the scheme.
$index = 1;
$positive_count_terms_index = array(
3,
4,
5,
6,
);
$visible_item = array(
'hidden' => FALSE,
);
foreach ($this->terms_hierarchy as $term) {
$mlid = _taxonomy_menu_get_mlid($term->tid, $this->vocabulary->vid);
$menu_link = menu_link_load($mlid);
if ($mlid) {
switch ($index) {
case '3':
case '4':
$count = 2;
break;
case '5':
case '6':
$count = 1;
break;
default:
$count = 0;
break;
}
if (in_array($index, $positive_count_terms_index)) {
$this
->assertMenuLink($mlid, array(
'link_title' => $term->name . ' (' . $count . ')',
));
}
else {
$this
->assertMenuLink($mlid, array(
'link_title' => $term->name,
));
}
}
else {
$this
->fail('No mlid could be found for the term ' . $term->tid);
}
$index++;
}
}