menu() публичный статический Метод

Generates a menu.
public static menu ( array $items, array $htmlOptions = [], integer $depth ) : string
$items array the menu items.
$htmlOptions array additional HTML attributes.
$depth integer the current depth.
Результат string the generated menu.
Пример #1
0
 public function testMenu()
 {
     $I = $this->codeGuy;
     $items = array(array('icon' => TbHtml::ICON_HOME, 'label' => 'Home', 'url' => '#'), array('label' => 'Profile', 'url' => '#', 'htmlOptions' => array('disabled' => true)), array('label' => 'Dropdown', 'active' => true, 'items' => array(array('label' => 'Action', 'url' => '#'), array('label' => 'Another action', 'url' => '#'), array('label' => 'Dropdown', 'items' => array(array('label' => 'Action', 'url' => '#'))), TbHtml::menuDivider(), array('label' => 'Separate link', 'url' => '#'))), array('label' => 'Hidden', 'url' => '#', 'visible' => false));
     $html = TbHtml::menu($items, array('class' => 'ul'));
     $nav = $I->createNode($html, 'ul');
     $I->seeNodeAttribute($nav, 'role', 'menu');
     $I->seeNodeNumChildren($nav, 3);
     foreach ($nav->children() as $i => $liElement) {
         $li = $I->createNode($liElement);
         if ($i === 2) {
             $I->seeNodeCssClass($li, 'dropdown active');
             $I->seeNodeChildren($li, array('a.dropdown-toggle', 'ul.dropdown-menu'));
             $ul = $li->filter('ul.dropdown-menu');
             $I->seeNodeNumChildren($ul, 5);
             foreach ($ul->children() as $j => $subLiElement) {
                 $subLi = $I->createNode($subLiElement);
                 if ($j === 2) {
                     $I->seeNodeCssClass($subLi, 'dropdown-submenu');
                     $I->seeNodeChildren($subLi, array('a.dropdown-toggle', 'ul.dropdown-menu'));
                     $subUl = $subLi->filter('ul.dropdown-menu');
                     $I->seeNodeNumChildren($subUl, 1);
                 } else {
                     if ($j === 3) {
                         $I->seeNodeCssClass($subLi, 'divider');
                     } else {
                         $subA = $subLi->filter('a');
                         $I->seeNodeText($subA, $items[$i]['items'][$j]['label']);
                     }
                 }
             }
         } else {
             if ($i === 0) {
                 $I->seeNodeChildren($li, array('i.icon-home', 'a'));
             }
             if ($i === 2) {
                 $I->seeNodeCssClass($li, 'disabled');
             }
             $a = $li->filter('a');
             $I->seeNodeAttributes($a, array('href' => '#', 'tabindex' => '-1'));
             $I->seeNodeText($a, $items[$i]['label']);
         }
     }
     $html = TbHtml::menu(array());
     $this->assertEquals('', $html);
 }