Files
yii2/tests/framework/widgets/ListViewTest.php
François Gannaz 7669d60df6 Document and test ListView.showOnEmpty
This addresses #11627 by completing the documentation without changing
the behavior. Some basic unit tests are added on ListView to ensure this
won't change unintentionnally.

That means a ListView widget with an empty provider and
`showOnEmpty=true` will still display an empty element (by default, an
empty "div.list-view").
2016-10-14 15:40:23 +02:00

57 lines
1.6 KiB
PHP

<?php
namespace yiiunit\framework\widgets;
use yii\data\ArrayDataProvider;
use yii\widgets\ListView;
/**
* @group widgets
*/
class ListViewTest extends \yiiunit\TestCase
{
protected function setUp()
{
parent::setUp();
$this->mockApplication();
}
public function testEmptyListShown()
{
$dataProvider = new ArrayDataProvider([
'allModels' => [],
]);
ob_start();
echo ListView::widget([
'dataProvider' => $dataProvider,
'showOnEmpty' => false,
'emptyText' => "Nothing at all",
]);
$actualHtml = ob_get_clean();
$this->assertTrue(strpos($actualHtml, "Nothing at all") !== false, "displays the empty message");
$this->assertTrue(strpos($actualHtml, '<div class="empty">') !== false, "adds the 'empty' class");
$this->assertTrue(strpos($actualHtml, '<div class="summary">') === 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, '<div class="empty">') === false, "does not add the 'empty' class");
$this->assertTrue(strpos($actualHtml, '<div class="summary">') === false, "does not display the summary");
$this->assertEmpty(trim(\strip_tags($actualHtml)), "contains no text");
}
}