Пример #1
0
    }
    // resets the userAccess property so we can test for current repeatedly.
    public function resetUserAccess()
    {
        $this->_userAccess = null;
    }
}
$t->info('1 - Test basic getters, setters and constructor');
$menu = new ioMenuItem('test menu', '@homepage', array('title' => 'my menu'));
$t->is($menu->getName(), 'test menu', '->getName() returns the given name.');
$menu->setName('new menu name');
$t->is($menu->getName(), 'new menu name', '->setName() sets the name correctly.');
$t->is($menu->getLabel(), 'new menu name', '->getLabel() returns the name if the label does not exist.');
$menu->setLabel('menu label');
$t->is($menu->getLabel(), 'menu label', 'Once set, ->getLabel() returns the actual label.');
$t->is($menu->getRoute(), '@homepage', '->getRoute() returns the given route.');
$menu->setRoute('http://www.sympalphp.org');
$t->is($menu->getRoute(), 'http://www.sympalphp.org', '->setRoute() sets the route correctly.');
$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.');
 /**
  * Render item with all of its children.
  *
  * This renders the li tag to fit into the parent ul as well as its
  * own nested ul tag if this menu item has children
  *
  * @param integer $depth The depth each child should render
  * @return string
  */
 protected function _renderItem(ioMenuItem $item, $depth = null)
 {
     // if we don't have access or this item is marked to not be shown
     if (!$item->shouldBeRendered()) {
         return;
     }
     // explode the class string into an array of classes
     $class = $item->getAttribute('class') ? explode(' ', $item->getAttribute('class')) : array();
     if ($item->isCurrent()) {
         $class[] = 'current';
     } elseif ($item->isCurrentAncestor($depth)) {
         $class[] = 'current_ancestor';
     }
     if ($item->actsLikeFirst()) {
         $class[] = 'first';
     }
     if ($item->actsLikeLast()) {
         $class[] = 'last';
     }
     // retrieve the attributes and put the final class string back on it
     $attributes = $item->getAttributes();
     if (count($class) > 0) {
         $attributes['class'] = implode(' ', $class);
     }
     // opening li tag
     $html = $this->_format($item->getLevel(), '<li' . _tag_options($attributes) . '>', 'li');
     // render the text/link inside the li tag
     $html .= $this->_format($item->getLevel(), $item->getRoute() ? $item->renderLink() : $item->renderLabel(), 'link');
     // renders the embedded ul if there are visible children
     $html .= $this->_render($item, $depth, true);
     // closing li tag
     $html .= $this->_format($item->getLevel(), '</li>', 'li');
     return $html;
 }