') !== false, "adds the 'empty' class");
$this->assertTrue(strpos($actualHtml, '
') === false, "does not display the summary");
}
public function testEmptyListNotShown()
{
$dataProvider = new ArrayDataProvider([
'allModels' => [],
]);
ob_start();
echo ListView::widget([
'dataProvider' => $dataProvider,
'showOnEmpty' => true,
'emptyText' => "Nothing at all",
]);
$actualHtml = ob_get_clean();
$this->assertTrue(strpos($actualHtml, '
') === false, "does not add the 'empty' class");
$this->assertTrue(strpos($actualHtml, '
') === false, "does not display the summary");
$this->assertEmpty(trim(\strip_tags($actualHtml)), "contains no text");
$this->mockWebApplication();
}
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()
{
$listView = $this->getListView();
$this->expectOutputString(<<
Showing 1-3 of 3 items.
0
1
2
HTML
);
$listView->run();
}
public function testWidgetOptions()
{
$listView = $this->getListView(['options' => ['class' => 'test-passed'], 'separator' => '']);
$this->expectOutputString(<<
Showing 1-3 of 3 items.
0
1
2
HTML
);
$listView->run();
}
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)
{
$listView = $this->getListView(['itemView' => $itemView]);
$this->expectOutputString($expected);
$listView->run();
}
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)
{
$listView = $this->getListView(['itemOptions' => $itemOptions]);
$this->expectOutputString($expected);
$listView->run();
}
}