예제 #1
0
$rendered = '<ul class="root"><li class="first">Parent 1</li><li class="parent2_class last" title="parent2 title">Parent 2</li></ul>';
$t->is($menu->render(1), $rendered, '->render(1) returns only the pt1 and pt2 elements');
$rendered = '<ul class="root"><li class="current_ancestor first">Parent 1<ul class="menu_level_1"><li class="first">Child 1</li><li class="current">Child 2</li><li class="last">Child 3</li></ul></li><li class="parent2_class last" title="parent2 title">Parent 2<ul class="menu_level_1"><li class="first last">Child 4</li></ul></li></ul>';
$t->is($menu->render(2), $rendered, '->render(2) returns down to the ch1-ch4 level.');
$rendered = '<ul class="root"><li class="current_ancestor first">Parent 1<ul class="menu_level_1"><li class="first">Child 1</li><li class="current">Child 2</li><li class="last">Child 3</li></ul></li><li class="parent2_class last" title="parent2 title">Parent 2<ul class="menu_level_1"><li class="first last">Child 4<ul class="menu_level_2"><li class="first last">Grandchild 1</li></ul></li></ul></li></ul>';
$t->is($menu->render(3), $rendered, '->render(3) returns the entire tree.');
$t->info('    Use render(2) but set pt1\'s showChildren() to false.');
$menu['Parent 1']->showChildren(false);
$rendered = '<ul class="root"><li class="first">Parent 1</li><li class="parent2_class last" title="parent2 title">Parent 2<ul class="menu_level_1"><li class="first last">Child 4</li></ul></li></ul>';
$t->is($menu->render(2), $rendered, 'Displays ch4 and not gc1 because depth = 2. Hides ch1-3 because showChildren() is false on pt1.');
$t->info('9 - Test i18n functionaliy.');
$menu = new ioMenuItem('i18n');
$menu->addChild('admin');
$t->info('  9.1 - Test the setCulture() and getCulture() methods');
$context->getUser()->setCulture('es');
$t->is($menu->getCulture(), 'es', '->getCulture() returns the user default culture if none is set.');
$menu->setCulture('klingon');
$t->is($menu->getCulture(), 'klingon', '->getCulture() returns the culture that was explicitly set.');
$t->is($menu['admin']->getCulture(), 'klingon', '->getCulture() returns the parent menu items culture if not set.');
$menu['admin']->setCulture('mars');
$t->is($menu['admin']->getCulture(), 'mars', '->getCulture() returns the set culture, not the parent\'s culture.');
$t->info('  9.2 - Test the useI18n() and get/setLabel() methods');
$menu = new ioMenuItem('admin');
$context->getUser()->setCulture('en');
$t->is($menu->useI18n(), false, '->useI18n() returns false, there are no i18n labels set.');
$menu->setLabel('administración', 'es');
$t->is($menu->useI18n(), true, '->useI18n() returns true after an i18n label is set.');
$t->is($menu->getLabel('es'), 'administración', '->getLabel(es) correctly returns the spanish label I just set.');
$t->is($menu->getLabel(), 'admin', '->getLabel() still returns "admin", which is the name since no en label is set.');
$menu->setLabel('admin default');
$t->is($menu->getLabel(), 'admin default', '->getLabel() returns "admin default", the default label');