[
[
'label' => 'Page1',
'content' => 'Page1',
],
[
'label' => 'Page2',
'content' => 'Page2',
],
]
]);
$this->assertContainsWithoutLE('
', $out);
}
/**
* Each tab should have a corresponding unique ID
*
* @see https://github.com/yiisoft/yii2/issues/6150
*/
public function testIds()
{
Tabs::$counter = 0;
$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'],
]
],
[
'label' => $extAnchor1 = 'External link',
'url' => $extUrl1 = ['//other/route'],
],
[
'label' => 'Dropdown3',
'items' => [
[
'label' => $extAnchor2 = 'External Dropdown Link',
'url' => $extUrl2 = ['//other/dropdown/route']
],
]
],
]
]);
$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
'w3', // Dropdown3
// containers
"id=\"$page1\"",
"id=\"$page2\"",
"id=\"$page3\"",
"id=\"$page4\"",
"id=\"$page5\"",
Html::a($extAnchor1, $extUrl1, ['class' => 'nav-link']),
Html::a($extAnchor2, $extUrl2, [/*'tabindex' => -1, */
'class' => 'dropdown-item'
]),
];
foreach ($shouldContain as $string) {
$this->assertContainsWithoutLE($string, $out);
}
}
public function testVisible()
{
Tabs::$counter = 0;
$html = Tabs::widget([
'items' => [
[
'label' => 'Page1',
'content' => 'Page1',
],
[
'label' => 'InvisiblePage',
'content' => 'Invisible Page Content',
'visible' => false
],
[
'label' => 'Dropdown1',
'items' => [
['label' => 'Page2', 'content' => 'Page2'],
['label' => 'InvisibleItem', 'content' => 'Invisible Item Content', 'visible' => false],
['label' => 'Page3', 'content' => 'Page3'],
['label' => 'External Link', 'url' => ['//other/dropdown/route']],
['label' => 'Invisible External Link', 'url' => ['//other/dropdown/route'], 'visible' => false],
]
],
]
]);
$this->assertStringNotContainsString('InvisiblePage', $html);
$this->assertStringNotContainsString('Invisible Page Content', $html);
$this->assertStringNotContainsString('InvisibleItem', $html);
$this->assertStringNotContainsString('Invisible Item Content', $html);
$this->assertStringNotContainsString('Invisible External Link', $html);
}
public function testDisabled()
{
Tabs::$counter = 0;
$html = Tabs::widget([
'items' => [
[
'label' => 'Page1',
'content' => 'Page1',
'disabled' => true
],
[
'label' => 'Page2',
'content' => 'Page2',
],
[
'label' => 'DisabledPage',
'content' => 'Disabled Page Content',
'disabled' => true
],
[
'label' => 'Dropdown1',
'items' => [
['label' => 'Page2', 'content' => 'Page2'],
['label' => 'DisabledItem', 'content' => 'Disabled Item Content', 'disabled' => true],
['label' => 'Page3', 'content' => 'Page3'],
['label' => 'External Link', 'url' => ['//other/dropdown/route']],
['label' => 'Disabled External Link', 'url' => ['//other/dropdown/route'], 'disabled' => true],
]
],
]
]);
$this->assertStringContainsString(
'- Page1
',
$html
);
$this->assertStringContainsString(
'- Page2
',
$html
);
$this->assertStringContainsString(
'- DisabledPage
',
$html
);
$this->assertStringContainsString(
'DisabledItem',
$html
);
$this->assertStringContainsString(
'Disabled External Link',
$html
);
}
public function testItem()
{
$checkTag = 'article';
$out = Tabs::widget([
'items' => [
[
'label' => 'Page1',
'content' => 'Page1',
],
[
'label' => 'Page2',
'content' => 'Page2',
],
],
'itemOptions' => ['tag' => $checkTag],
'renderTabContent' => true,
]);
$this->assertStringContainsString('<' . $checkTag, $out);
}
public function testTabContentOptions()
{
$checkAttribute = "test_attribute";
$checkValue = "check_attribute";
$out = Tabs::widget([
'items' => [
[
'label' => 'Page1',
'content' => 'Page1'
]
],
'tabContentOptions' => [
$checkAttribute => $checkValue
]
]);
$this->assertStringContainsString($checkAttribute . '=', $out);
$this->assertStringContainsString($checkValue, $out);
}
public function testActivateFirstVisibleTab()
{
$html = Tabs::widget([
'id' => 'mytab',
'items' => [
[
'label' => 'Tab 1',
'content' => 'some content',
'visible' => false
],
[
'label' => 'Tab 2',
'content' => 'some content',
'disabled' => true
],
[
'label' => 'Tab 3',
'content' => 'some content'
],
[
'label' => 'Tab 4',
'content' => 'some content'
]
]
]);
$this->assertStringNotContainsString(
'- Tab 1
',
$html
);
$this->assertStringNotContainsString(
'- Tab 2
',
$html
);
$this->assertStringContainsString(
'- Tab 3
',
$html
);
}
public function testActivateTab()
{
$html = Tabs::widget([
'id' => 'mytab',
'items' => [
[
'label' => 'Tab 1',
'content' => 'some content',
'visible' => false
],
[
'label' => 'Tab 2',
'content' => 'some content'
],
[
'label' => 'Tab 3',
'content' => 'some content',
'active' => true
],
[
'label' => 'Tab 4',
'content' => 'some content'
]
]
]);
$this->assertStringContainsString(
'- Tab 3
',
$html
);
}
public function testTabLabelEncoding()
{
$html = Tabs::widget([
'encodeLabels' => false,
'id' => 'mytab',
'items' => [
[
'label' => 'Tab 1encoded',
'content' => 'some content',
'encode' => true,
],
[
'label' => 'Tab 2not encoded',
'content' => 'some content',
],
[
'label' => 'Tab 3not encoded too',
'content' => 'some content',
],
]
]);
$this->assertStringContainsString('<span>encoded</span>', $html);
$this->assertStringContainsString('not encoded', $html);
$this->assertStringContainsString('not encoded too', $html);
}
/**
* @see https://github.com/yiisoft/yii2-bootstrap5/issues/108#issuecomment-465219339
*/
public function testIdRendering()
{
Tabs::$counter = 0;
$html = Tabs::widget([
'items' => [
[
'options' => ['id' => 'pane1'],
'label' => 'Tab 1',
'content' => 'Content 1
',
],
[
'label' => 'Tab 2',
'content' => 'Content 2
',
],
],
]);
$expected = <<- Tab 1
- Tab 2
HTML;
$this->assertEqualsWithoutLE($expected, $html);
}
public function testHeaderOptions()
{
Tabs::$counter = 0;
$html = Tabs::widget([
'items' => [
[
'label' => 'Tab 1',
'content' => 'Content 1
',
],
[
'label' => 'Tab 2',
'content' => 'Content 2
',
'headerOptions' => ['class' => 'col-6'],
],
[
'label' => 'Link',
'url' => 'http://www.example.com/',
'headerOptions' => ['class' => 'col-3'],
],
],
'options' => ['class' => 'row'],
'headerOptions' => ['class' => 'col'],
]);
$expected = <<Tab 1
Tab 2
Link
HTML;
$this->assertEqualsWithoutLE($expected, $html);
}
}