Browse Source

[Fixes #86] Fixed handling empty items in Nav

tags/2.0.6
freezy 10 years ago
parent
commit
94840e6794
  1. 1
      CHANGELOG.md
  2. 6
      Nav.php
  3. 35
      tests/NavTest.php

1
CHANGELOG.md

@ -4,6 +4,7 @@ Yii Framework 2 bootstrap extension Change Log
2.0.6 under development
-----------------------
- Bug #68: Fixed `yii\bootstrap\Nav` handling empty items (freezy-sk)
2.0.5 September 23, 2015

6
Nav.php

@ -176,7 +176,7 @@ class Nav extends Widget
$active = $this->isItemActive($item);
}
if ($items !== null) {
if (!empty($items)) {
$linkOptions['data-toggle'] = 'dropdown';
Html::addCssClass($options, ['widget' => 'dropdown']);
Html::addCssClass($linkOptions, ['widget' => 'dropdown-toggle']);
@ -191,6 +191,10 @@ class Nav extends Widget
}
}
if (empty($items)) {
$items = '';
}
if ($this->activateItems && $active) {
Html::addCssClass($options, 'active');
}

35
tests/NavTest.php

@ -85,5 +85,38 @@ EXPECTED;
EXPECTED;
$this->assertEqualsWithoutLE($expected, $out);
}
}
public function testEmptyItems()
{
Nav::$counter = 0;
$out = Nav::widget([
'items' => [
[
'label' => 'Page1',
'items' => null,
],
[
'label' => 'Dropdown1',
'items' => [
['label' => 'Page2', 'content' => 'Page2'],
['label' => 'Page3', 'content' => 'Page3'],
],
],
[
'label' => 'Page4',
'items' => [],
],
],
]);
$expected = <<<EXPECTED
<ul id="w0" class="nav"><li><a href="#">Page1</a></li>
<li class="dropdown"><a class="dropdown-toggle" href="#" data-toggle="dropdown">Dropdown1 <b class="caret"></b></a><ul id="w1" class="dropdown-menu"><li class="dropdown-header">Page2</li>
<li class="dropdown-header">Page3</li></ul></li>
<li><a href="#">Page4</a></li></ul>
EXPECTED;
$this->assertEqualsWithoutLE($expected, $out);
}
}

Loading…
Cancel
Save