|
|
|
@ -5,6 +5,7 @@ namespace yiiunit\framework\grid;
|
|
|
|
|
|
|
|
|
|
use yii\data\ArrayDataProvider; |
|
|
|
|
use yii\grid\DataColumn; |
|
|
|
|
use yii\web\View; |
|
|
|
|
use yii\grid\GridView; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -13,9 +14,66 @@ use yii\grid\GridView;
|
|
|
|
|
*/ |
|
|
|
|
class GridViewTest extends \yiiunit\TestCase |
|
|
|
|
{ |
|
|
|
|
protected function setUp() |
|
|
|
|
{ |
|
|
|
|
parent::setUp(); |
|
|
|
|
$this->mockApplication([ |
|
|
|
|
'components' => [ |
|
|
|
|
'assetManager' => [ |
|
|
|
|
'bundles' => [ |
|
|
|
|
'yii\grid\GridViewAsset' => false, |
|
|
|
|
'yii\web\JqueryAsset' => false, |
|
|
|
|
], |
|
|
|
|
], |
|
|
|
|
], |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function emptyDataProvider() |
|
|
|
|
{ |
|
|
|
|
return [ |
|
|
|
|
[null, 'No results found.'], |
|
|
|
|
['Empty', 'Empty'], |
|
|
|
|
// https://github.com/yiisoft/yii2/issues/13352 |
|
|
|
|
[false, ''], |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @dataProvider emptyDataProvider |
|
|
|
|
* @param mixed $emptyText |
|
|
|
|
* @param string $expectedText |
|
|
|
|
* @throws \Exception |
|
|
|
|
*/ |
|
|
|
|
public function testEmpty($emptyText, $expectedText) |
|
|
|
|
{ |
|
|
|
|
$html = GridView::widget([ |
|
|
|
|
'id' => 'grid', |
|
|
|
|
'dataProvider' => new ArrayDataProvider(['allModels' => []]), |
|
|
|
|
'showHeader' => false, |
|
|
|
|
'emptyText' => $emptyText, |
|
|
|
|
'options' => [], |
|
|
|
|
'tableOptions' => [], |
|
|
|
|
'view' => new View(), |
|
|
|
|
'filterUrl' => '/', |
|
|
|
|
]); |
|
|
|
|
$html = preg_replace("/\r|\n/", '', $html); |
|
|
|
|
|
|
|
|
|
if ($expectedText) { |
|
|
|
|
$emptyRowHtml = "<tr><td colspan=\"0\"><div class=\"empty\">{$expectedText}</div></td></tr>"; |
|
|
|
|
} else { |
|
|
|
|
$emptyRowHtml = ''; |
|
|
|
|
} |
|
|
|
|
$expectedHtml = "<div id=\"grid\"><table><tbody>{$emptyRowHtml}</tbody></table></div>"; |
|
|
|
|
|
|
|
|
|
$this->assertEquals($expectedHtml, $html); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testGuessColumns() |
|
|
|
|
{ |
|
|
|
|
$this->mockApplication(); |
|
|
|
|
$row = ['id' => 1, 'name' => 'Name1', 'value' => 'Value1', 'description' => 'Description1',]; |
|
|
|
|
|
|
|
|
|
$grid = new GridView([ |
|
|
|
|