Browse Source

fix #15798 (yii\grid\CheckboxColumn, yii\grid\RadioButtonColumn conte… (#16021)

* fix #15798 (yii\grid\CheckboxColumn, yii\grid\RadioButtonColumn content option has no effect)

* fix #15798 update pl, call parent method

* add test for content options in checkboxcolumn and radiobuttoncolumn

* update changelog by #15798
tags/2.0.16
Alexey 6 years ago committed by Dmitry Naumenko
parent
commit
f5665a0544
  1. 1
      framework/CHANGELOG.md
  2. 4
      framework/grid/CheckboxColumn.php
  3. 4
      framework/grid/RadioButtonColumn.php
  4. 20
      tests/framework/grid/CheckboxColumnTest.php
  5. 18
      tests/framework/grid/RadiobuttonColumnTest.php

1
framework/CHANGELOG.md

@ -8,6 +8,7 @@ Yii Framework 2 Change Log
- Bug #16010: Fixed `yii\filters\ContentNegotiator` behavior when GET parameters contain an array (rugabarbo)
- Bug #14660: Fixed `yii\caching\DbCache` concurrency issue when set values with the same key (rugabarbo)
- Bug #15988: Fixed bash completion (alekciy)
- Bug #15798: Fixed render `yii\grid\RadioButtonColumn::$content` and `yii\grid\CheckboxColumn::$content` (lesha724)
- Bug #15117: Fixed `yii\db\Schema::getTableMetadata` cache refreshing (boboldehampsink)
- Bug #15875: afterSave for new models flushes unsaved data (shirase)
- Bug #16073: Fixed regression in Oracle `IN` condition builder for more than 1000 items (cebe)

4
framework/grid/CheckboxColumn.php

@ -113,6 +113,10 @@ class CheckboxColumn extends Column
*/
protected function renderDataCellContent($model, $key, $index)
{
if ($this->content !== null) {
return parent::renderDataCellContent($model, $key, $index);
}
if ($this->checkboxOptions instanceof Closure) {
$options = call_user_func($this->checkboxOptions, $model, $key, $index, $this);
} else {

4
framework/grid/RadioButtonColumn.php

@ -80,6 +80,10 @@ class RadioButtonColumn extends Column
*/
protected function renderDataCellContent($model, $key, $index)
{
if ($this->content !== null) {
return parent::renderDataCellContent($model, $key, $index);
}
if ($this->radioOptions instanceof Closure) {
$options = call_user_func($this->radioOptions, $model, $key, $index, $this);
} else {

20
tests/framework/grid/CheckboxColumnTest.php

@ -12,6 +12,7 @@ use yii\data\ArrayDataProvider;
use yii\grid\CheckboxColumn;
use yii\grid\GridView;
use yii\helpers\FileHelper;
use yii\helpers\Html;
use yiiunit\framework\i18n\IntlTestHelper;
use yiiunit\TestCase;
@ -83,6 +84,25 @@ class CheckboxColumnTest extends TestCase
$this->assertContains('value="42"', $column->renderDataCell([], 1, 0));
}
public function testContent()
{
$column = new CheckboxColumn([
'content' => function ($model, $key, $index, $column) {
return null;
},
'grid' => $this->getGrid(),
]);
$this->assertContains('<td></td>', $column->renderDataCell([], 1, 0));
$column = new CheckboxColumn([
'content' => function ($model, $key, $index, $column) {
return Html::checkBox('checkBoxInput', false);
},
'grid' => $this->getGrid(),
]);
$this->assertContains(Html::checkBox('checkBoxInput', false), $column->renderDataCell([], 1, 0));
}
/**
* @return GridView a mock gridview
*/

18
tests/framework/grid/RadiobuttonColumnTest.php

@ -11,6 +11,7 @@ use Yii;
use yii\data\ArrayDataProvider;
use yii\grid\GridView;
use yii\grid\RadioButtonColumn;
use yii\helpers\Html;
use yii\web\Request;
use yiiunit\TestCase;
@ -59,6 +60,23 @@ class RadiobuttonColumnTest extends TestCase
$this->assertEquals('<td><input type="radio" name="radioButtonSelection" value="' . $model['value'] . '"></td>', $actual);
}
public function testContent()
{
$column = new RadioButtonColumn([
'content' => function ($model, $key, $index, $column) {
return null;
}
]);
$this->assertContains('<td></td>', $column->renderDataCell([], 1, 0));
$column = new RadioButtonColumn([
'content' => function ($model, $key, $index, $column) {
return Html::radio('radioButtonInput', false);
}
]);
$this->assertContains(Html::radio('radioButtonInput', false), $column->renderDataCell([], 1, 0));
}
public function testMultipleInGrid()
{
$this->mockApplication();

Loading…
Cancel
Save