mockApplication(); } public function testEmptyListShown() { $this->getListView([ 'dataProvider' => new ArrayDataProvider(['allModels' => []]), 'emptyText' => "Nothing at all", ])->run(); $this->expectOutputString('
Nothing at all
'); } public function testEmpty() { $this->getListView([ 'dataProvider' => new ArrayDataProvider(['allModels' => []]), 'emptyText' => false, ])->run(); $this->expectOutputString('
'); } public function testEmptyListNotShown() { $this->getListView([ 'dataProvider' => new ArrayDataProvider(['allModels' => []]), 'showOnEmpty' => true, ])->run(); $this->expectOutputString(<< HTML ); } private function getListView($options = []) { return new ListView(array_merge([ 'id' => 'w0', 'dataProvider' => $this->getDataProvider(), ], $options)); } private function getDataProvider() { return new ArrayDataProvider([ 'allModels' => [ ['id' => 1, 'login' => 'silverfire'], ['id' => 2, 'login' => 'samdark'], ['id' => 3, 'login' => 'cebe'], ], ]); } public function testSimplyListView() { $this->getListView()->run(); $this->expectOutputString(<<
Showing 1-3 of 3 items.
0
1
2
HTML ); } public function testWidgetOptions() { $this->getListView(['options' => ['class' => 'test-passed'], 'separator' => ''])->run(); $this->expectOutputString(<<
Showing 1-3 of 3 items.
0
1
2
HTML ); } public function itemViewOptions() { return [ [ null, '
Showing 1-3 of 3 items.
0
1
2
', ], [ function ($model, $key, $index, $widget) { return "Item #{$index}: {$model['login']} - Widget: " . $widget->className(); }, '
Showing 1-3 of 3 items.
Item #0: silverfire - Widget: yii\widgets\ListView
Item #1: samdark - Widget: yii\widgets\ListView
Item #2: cebe - Widget: yii\widgets\ListView
', ], [ '@yiiunit/data/views/widgets/ListView/item', '
Showing 1-3 of 3 items.
Item #0: silverfire - Widget: yii\widgets\ListView
Item #1: samdark - Widget: yii\widgets\ListView
Item #2: cebe - Widget: yii\widgets\ListView
', ], ]; } /** * @dataProvider itemViewOptions */ public function testItemViewOptions($itemView, $expected) { $this->getListView(['itemView' => $itemView])->run(); $this->expectOutputString($expected); } public function itemOptions() { return [ [ null, '
Showing 1-3 of 3 items.
0
1
2
', ], [ function ($model, $key, $index, $widget) { return [ 'tag' => 'span', 'data' => [ 'test' => 'passed', 'key' => $key, 'index' => $index, 'id' => $model['id'], ], ]; }, '
Showing 1-3 of 3 items.
0 1 2
', ], ]; } /** * @dataProvider itemOptions */ public function testItemOptions($itemOptions, $expected) { $this->getListView(['itemOptions' => $itemOptions])->run(); $this->expectOutputString($expected); } public function testBeforeAndAfterItem() { $before = function ($model, $key, $index, $widget) { $widget = get_class($widget); return ""; }; $after = function ($model, $key, $index, $widget) { if ($model['id'] === 1) { return null; } $widget = get_class($widget); return ""; }; $this->getListView([ 'beforeItem' => $before, 'afterItem' => $after ])->run(); $this->expectOutputString(<<
Showing 1-3 of 3 items.
0
1
2
HTML ); } }