Browse Source

add tests for buttonsVisible suggestion (issue #9198)

tags/2.0.7
Vit S 9 years ago
parent
commit
6698b8154b
  1. 63
      tests/framework/grid/ActionColumnTest.php

63
tests/framework/grid/ActionColumnTest.php

@ -0,0 +1,63 @@
<?php
namespace yiiunit\framework\grid;
use yii\base\Model;
use yii\grid\ActionColumn;
/**
* @author Vitaly S. <fornit1917@gmail.com>
*
* @group grid
*/
class ActionColumnTest extends \yiiunit\TestCase
{
public function testRenderDataCell()
{
$column = new ActionColumn();
$column->urlCreator = function($model, $key, $index) {
return 'http://test.com';
};
$column->template = '{update}';
$column->buttons = [
'update' => function($url, $model, $key) {
return 'update_button';
}
];
//test default visible button
$columnContents = $column->renderDataCell(['id' => 1], 1, 0);
$this->assertContains('update_button', $columnContents);
//test visible button
$column->buttonsVisible = [
'update' => true
];
$columnContents = $column->renderDataCell(['id' => 1], 1, 0);
$this->assertContains('update_button', $columnContents);
//test visible button (condition is callback)
$column->buttonsVisible = [
'update' => function($model){return $model['id'] == 1;}
];
$columnContents = $column->renderDataCell(['id' => 1], 1, 0);
$this->assertContains('update_button', $columnContents);
//test invisible button
$column->buttonsVisible = [
'update' => false
];
$columnContents = $column->renderDataCell(['id' => 1], 1, 0);
$this->assertNotContains('update_button', $columnContents);
//test invisible button (condition is callback)
$column->buttonsVisible = [
'update' => function($model){return $model['id'] != 1;}
];
$columnContents = $column->renderDataCell(['id' => 1], 1, 0);
$this->assertNotContains('update_button', $columnContents);
}
}
Loading…
Cancel
Save