/**
  * Renders menu tree. Internal method.
  *
  * @param ioMenuItem  $item      Menu item
  * @param integer $depth         The depth of children to render
  * @param boolean $renderAsChild Render with attributes on the li (true) or the ul around the children (false)
  *
  * @return string
  */
 protected function _render(ioMenuItem $item, $depth = null, $renderAsChild = false)
 {
     /**
      * Return an empty string if any of the following are true:
      *   a) The menu has no children eligible to be displayed
      *   b) The depth is 0
      *   c) This menu item has been explicitly set to hide its children
      */
     if (!$item->hasChildren() || $depth === 0 || !$item->showChildren()) {
         return;
     }
     if ($renderAsChild) {
         $attributes = array('class' => 'menu_level_' . $item->getLevel());
     } else {
         $attributes = $item->getAttributes();
         // give the top ul a class of "menu" of none specified
         if (!isset($attributes['class'])) {
             $attributes['class'] = 'menu';
         }
     }
     // render children with a depth - 1
     $childDepth = $depth === null ? null : $depth - 1;
     $html = $this->_format($item->getLevel(), '<ul' . _tag_options($attributes) . '>', 'ul');
     $html .= $this->_renderChildren($item, $childDepth);
     $html .= $this->_format($item->getLevel(), '</ul>', 'ul');
     return $html;
 }
$t->is($menu->getAttributes(), array('title' => 'my menu'), '->getAttributes() returns the attributes array.');
$menu->setAttributes(array('id' => 'unit_test'));
$t->is($menu->getAttributes(), array('id' => 'unit_test'), '->setAttributes() sets the attributes array.');
$t->is($menu->getAttribute('id', 'default'), 'unit_test', '->getAttribute() returns an existing attribute correctly.');
$t->is($menu->getAttribute('fake', 'default'), 'default', '->getAttribute() returns the default for a non-existent attribute.');
$menu->setAttribute('class', 'testing classes');
$t->is($menu->getAttribute('class'), 'testing classes', '->setAttribute() correctly sets an attribute.');
$t->is($menu->requiresAuth(), false, 'By default ->requiresAuth() returns false.');
$menu->requiresAuth(true);
$t->is($menu->requiresAuth(), true, 'Calling ->requiresAuth() with an argument sets the property.');
$t->is($menu->requiresNoAuth(), false, 'By default ->requiresNoAuth() returns false.');
$menu->requiresNoAuth(true);
$t->is($menu->requiresNoAuth(), true, 'Calling ->requiresNoAuth() with an argument sets the property.');
$menu->setCredentials(array('c1', 'c2'));
$t->is($menu->getCredentials(), array('c1', 'c2'), '->setCredentials() with an array sets all of the given credentials.');
$t->is($menu->showChildren(), true, '->showChildren() return true by default.');
$menu->showChildren(false);
$t->is($menu->showChildren(), false, '->showChildren() with an argument properly sets the property.');
$childMenu = new ioMenuItem('child');
$childMenu->setParent($menu);
$t->is($childMenu->getParent(), $menu, '->setParent() sets the parent menu item.');
$t->is(count($menu->getChildren()), 0, '->getChildren() returns no children to start.');
$menu->setChildren(array($childMenu));
$t->is($menu->getChildren(), array($childMenu), '->getChildren() returns the proper children array.');
$menu->setNum(5);
$t->is($menu->getNum(), 5, '->setNum() sets the num property.');
$t->info('### Creating the test tree.');
// create the tree and make the variables available
extract(create_test_tree($t, 'ioMenuItemTest'));
$t->info('2 - Test the construction of trees');
check_test_tree($t, $menu);