[ [ 'label' => 'Collapsible Group Item #1', 'content' => [ 'test content1', 'test content2' ], ], [ 'label' => 'Collapsible Group Item #2', 'content' => 'Das ist das Haus vom Nikolaus', 'contentOptions' => [ 'class' => 'testContentOptions' ], 'options' => [ 'class' => 'testClass', 'id' => 'testId' ], 'footer' => 'Footer' ], [ 'label' => '

Collapsible Group Item #3

', 'content' => [ '

test content1

', '

test content2

' ], 'contentOptions' => [ 'class' => 'testContentOptions2' ], 'options' => [ 'class' => 'testClass2', 'id' => 'testId2' ], 'encode' => false, 'footer' => 'Footer2' ], [ 'label' => '

Collapsible Group Item #4

', 'content' => [ '

test content1

', '

test content2

' ], 'contentOptions' => [ 'class' => 'testContentOptions3' ], 'options' => [ 'class' => 'testClass3', 'id' => 'testId3' ], 'encode' => true, 'footer' => 'Footer3' ], ] ]); $this->assertEqualsWithoutLE(<<
Das ist das Haus vom Nikolaus
HTML , $output); } public function testLabelKeys() { ob_start(); $form = ActiveForm::begin(['action' => '/something']); ActiveForm::end(); ob_end_clean(); Accordion::$counter = 0; $output = Accordion::widget([ 'items' => [ 'Item1' => 'Content1', 'Item2' => [ 'content' => 'Content2', ], [ 'label' => 'Item3', 'content' => 'Content3', ], 'FormField' => $form->field(new DynamicModel(['test']), 'test',['template' => '{input}']), ] ]); $this->assertEqualsWithoutLE(<<
Content1
Content2
Content3
HTML , $output); } public function testExpandOptions() { Accordion::$counter = 0; $output = Accordion::widget([ 'items' => [ 'Item1' => 'Content1', 'Item2' => [ 'content' => 'Content2', 'expand' => true, ], ] ]); $this->assertEqualsWithoutLE(<<
Content1
Content2
HTML , $output); } public function invalidItemsProvider() { return [ [ ['content'] ], // only content without label key [ [[]] ], // only content array without label [ [['content' => 'test']] ], // only content array without label ]; } /** * @dataProvider invalidItemsProvider * @expectedException \yii\base\InvalidConfigException */ public function testMissingLabel($items) { Accordion::widget([ 'items' => $items, ]); } /** * @see https://github.com/yiisoft/yii2/issues/8357 */ public function testRenderObject() { $template = ['template' => '{input}']; ob_start(); $form = ActiveForm::begin(['action' => '/something']); ActiveForm::end(); ob_end_clean(); $model = new data\Singer; Accordion::$counter = 0; $output = Accordion::widget([ 'items' => [ [ 'label' => 'Collapsible Group Item #1', 'content' => $form->field($model, 'firstName', $template) ], ] ]); $this->assertEqualsWithoutLE(<<
HTML , $output); } public function testAutoCloseItems() { $items = [ [ 'label' => 'Item 1', 'content' => 'Content 1', ], [ 'label' => 'Item 2', 'content' => 'Content 2', ], ]; $output = Accordion::widget([ 'items' => $items ]); $this->assertContains('data-bs-parent="', $output); $output = Accordion::widget([ 'autoCloseItems' => false, 'items' => $items ]); $this->assertNotContains('data-bs-parent="', $output); } /** * @depends testRender */ public function testItemToggleTag() { $items = [ [ 'label' => 'Item 1', 'content' => 'Content 1', ], [ 'label' => 'Item 2', 'content' => 'Content 2', ], ]; Accordion::$counter = 0; $output = Accordion::widget([ 'items' => $items, 'itemToggleOptions' => [ 'tag' => 'a', 'class' => 'custom-toggle', ], ]); $this->assertContains('
assertNotContains(' $items, 'itemToggleOptions' => [ 'tag' => 'a', 'class' => ['widget' => 'custom-toggle'], ], ]); $this->assertContains('
assertNotContains('collapse-toggle', $output); } }