Commit e6450be6 by Alexander Makarov

Fixes #6150: `yii\bootstrap\Tabs` dropdown IDs were generated incorrectly

parent 25a7c84e
...@@ -5,6 +5,7 @@ Yii Framework 2 bootstrap extension Change Log ...@@ -5,6 +5,7 @@ Yii Framework 2 bootstrap extension Change Log
----------------------- -----------------------
- Bug #5570: `yii\bootstrap\Tabs` would throw an exception if `content` is not set for one of its `items` (RomeroMsk) - Bug #5570: `yii\bootstrap\Tabs` would throw an exception if `content` is not set for one of its `items` (RomeroMsk)
- Bug #6150: `yii\bootstrap\Tabs` dropdown IDs were generated incorrectly (samdark)
- Enh #4181: Added `yii\bootstrap\Modal::$headerOptions` and `yii\bootstrap\Modal::$footerOptions` (tuxoff, samdark) - Enh #4181: Added `yii\bootstrap\Modal::$headerOptions` and `yii\bootstrap\Modal::$footerOptions` (tuxoff, samdark)
- Enh #4450: Added `yii\bootstrap\Nav::renderDropdown()` (qiangxue) - Enh #4450: Added `yii\bootstrap\Nav::renderDropdown()` (qiangxue)
- Enh #5735: Added `yii\bootstrap\Tabs::renderTabContent` to support manually rendering tab contents (RomeroMsk) - Enh #5735: Added `yii\bootstrap\Tabs::renderTabContent` to support manually rendering tab contents (RomeroMsk)
......
...@@ -154,7 +154,7 @@ class Tabs extends Widget ...@@ -154,7 +154,7 @@ class Tabs extends Widget
$label .= ' <b class="caret"></b>'; $label .= ' <b class="caret"></b>';
Html::addCssClass($headerOptions, 'dropdown'); Html::addCssClass($headerOptions, 'dropdown');
if ($this->renderDropdown($item['items'], $panes)) { if ($this->renderDropdown($n, $item['items'], $panes)) {
Html::addCssClass($headerOptions, 'active'); Html::addCssClass($headerOptions, 'active');
} }
...@@ -202,12 +202,13 @@ class Tabs extends Widget ...@@ -202,12 +202,13 @@ class Tabs extends Widget
/** /**
* Normalizes dropdown item options by removing tab specific keys `content` and `contentOptions`, and also * Normalizes dropdown item options by removing tab specific keys `content` and `contentOptions`, and also
* configure `panes` accordingly. * configure `panes` accordingly.
* @param string $itemNumber number of the item
* @param array $items the dropdown items configuration. * @param array $items the dropdown items configuration.
* @param array $panes the panes reference array. * @param array $panes the panes reference array.
* @return boolean whether any of the dropdown items is `active` or not. * @return boolean whether any of the dropdown items is `active` or not.
* @throws InvalidConfigException * @throws InvalidConfigException
*/ */
protected function renderDropdown(&$items, &$panes) protected function renderDropdown($itemNumber, &$items, &$panes)
{ {
$itemActive = false; $itemActive = false;
...@@ -228,7 +229,7 @@ class Tabs extends Widget ...@@ -228,7 +229,7 @@ class Tabs extends Widget
$itemActive = true; $itemActive = true;
} }
$options['id'] = ArrayHelper::getValue($options, 'id', $this->options['id'] . '-dd-tab' . $n); $options['id'] = ArrayHelper::getValue($options, 'id', $this->options['id'] . '-dd' . $itemNumber . '-tab' . $n);
$item['url'] = '#' . $options['id']; $item['url'] = '#' . $options['id'];
$item['linkOptions']['data-toggle'] = 'tab'; $item['linkOptions']['data-toggle'] = 'tab';
......
...@@ -34,6 +34,7 @@ Yii Framework 2 Change Log ...@@ -34,6 +34,7 @@ Yii Framework 2 Change Log
- Bug #6172: `yii\rbac\DbManager` should properly quote table and column names (qiangxue) - Bug #6172: `yii\rbac\DbManager` should properly quote table and column names (qiangxue)
- Bug #6164: Added missing support for `yii\db\Expression` to QueryBuilder `BETWEEN` and `LIKE` conditions (cebe) - Bug #6164: Added missing support for `yii\db\Expression` to QueryBuilder `BETWEEN` and `LIKE` conditions (cebe)
- Bug #6236: No JS scripts should be registered when `yii\widgets\ActiveForm::enableClientScript` is false (qiangxue) - Bug #6236: No JS scripts should be registered when `yii\widgets\ActiveForm::enableClientScript` is false (qiangxue)
- Bug #6150: `yii\bootstrap\Tabs` dropdown IDs were generated incorrectly (samdark)
- Bug #6266: Clicking on reset button does not hide error summary when using `ActiveForm` (InteLigent, qiangxue) - Bug #6266: Clicking on reset button does not hide error summary when using `ActiveForm` (InteLigent, qiangxue)
- Bug #6271: Query caching returns the same data when running the same SQL with different fetch modes (grachov) - Bug #6271: Query caching returns the same data when running the same SQL with different fetch modes (grachov)
- Bug: Gii console command help information does not contain global options (qiangxue) - Bug: Gii console command help information does not contain global options (qiangxue)
......
<?php
namespace yiiunit\extensions\bootstrap;
use yiiunit\TestCase;
/**
* BootstrapTestCase is the base class for all bootstrap extension test cases
*/
abstract class BootstrapTestCase extends TestCase
{
public function setUp()
{
$this->mockWebApplication();
}
}
\ No newline at end of file
<?php
namespace yiiunit\extensions\bootstrap;
use yii\bootstrap\Tabs;
/**
* Tests for Tabs widget
*/
class TabsTest extends BootstrapTestCase
{
/**
* Each tab should have a corresponding unique ID
*
* @see https://github.com/yiisoft/yii2/issues/6150
*/
public function testIds()
{
$out = Tabs::widget([
'items' => [
[
'label' => 'Page1', 'content' => 'Page1',
],
[
'label' => 'Dropdown1',
'items' => [
['label' => 'Page2', 'content' => 'Page2'],
['label' => 'Page3', 'content' => 'Page3'],
]
],
[
'label' => 'Dropdown2',
'items' => [
['label' => 'Page4', 'content' => 'Page4'],
['label' => 'Page5', 'content' => 'Page5'],
]
]
]
]);
$page1 = 'w0-tab0';
$page2 = 'w0-dd1-tab0';
$page3 = 'w0-dd1-tab1';
$page4 = 'w0-dd2-tab0';
$page5 = 'w0-dd2-tab1';
$shouldContain = [
'w0', // nav widget container
"#$page1", // Page1
'w1', // Dropdown1
"$page2", // Page2
"$page3", // Page3
'w2', // Dropdown2
"#$page4", // Page4
"#$page5", // Page5
// containers
"id=\"$page1\"",
"id=\"$page2\"",
"id=\"$page3\"",
"id=\"$page4\"",
"id=\"$page5\"",
];
foreach ($shouldContain as $string) {
$this->assertContains($string, $out);
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment