From 94840e67944d8705d41ed81906a8da050d5c441b Mon Sep 17 00:00:00 2001 From: freezy Date: Wed, 12 Aug 2015 17:53:32 +0200 Subject: [PATCH] [Fixes #86] Fixed handling empty items in Nav --- CHANGELOG.md | 1 + Nav.php | 6 +++++- tests/NavTest.php | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c083a0a..4a11584 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/Nav.php b/Nav.php index d59e9b0..226ed19 100644 --- a/Nav.php +++ b/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'); } diff --git a/tests/NavTest.php b/tests/NavTest.php index 3510af4..7044e22 100644 --- a/tests/NavTest.php +++ b/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 = <<
  • Page1
  • + +
  • Page4
  • +EXPECTED; + + $this->assertEqualsWithoutLE($expected, $out); + } }