[ [ 'label' => 'Collapsible Group Item #1', 'content' => [ 'test content1', 'test content2' ], ], [ 'label' => 'Collapsible Group Item #2', 'content' => [ 'test content1', 'test content2' ], '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(<<

HTML , $output); } public function testLabelKeys() { ob_start(); $form = ActiveForm::begin(['action' => '/something']); ActiveForm::end(); ob_end_clean(); Collapse::$counter = 0; $output = Collapse::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 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) { Collapse::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; Collapse::$counter = 0; $output = Collapse::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 = Collapse::widget([ 'items' => $items ]); $this->assertContains('data-parent="', $output); $output = Collapse::widget([ 'autoCloseItems' => false, 'items' => $items ]); $this->assertNotContains('data-parent="', $output); } /** * @depends testRender */ public function testItemToggleTag() { $items = [ [ 'label' => 'Item 1', 'content' => 'Content 1', ], [ 'label' => 'Item 2', 'content' => 'Content 2', ], ]; $output = Collapse::widget([ 'items' => $items, 'itemToggleOptions' => [ 'tag' => 'span', 'class' => 'custom-toggle', ], ]); $this->assertContains('