forked from yiisoft/yii2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes yiisoft#12828: Fixed handling of nested arrays, objects in `\yi…
…i\grid\GridView::guessColumns`
- Loading branch information
1 parent
333c4b6
commit 757b3de
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
|
||
namespace yiiunit\framework\grid; | ||
|
||
use yii\data\ArrayDataProvider; | ||
use yii\grid\DataColumn; | ||
use yii\grid\GridView; | ||
|
||
/** | ||
* @author Evgeniy Tkachenko <[email protected]> | ||
* @group grid | ||
*/ | ||
class GridViewTest extends \yiiunit\TestCase | ||
{ | ||
public function testGuessColumns() | ||
{ | ||
$this->mockApplication(); | ||
$row = ['id' => 1, 'name' => 'Name1', 'value' => 'Value1', 'description' => 'Description1',]; | ||
|
||
$grid = new GridView([ | ||
'dataProvider' => new ArrayDataProvider( | ||
[ | ||
'allModels' => [ | ||
$row, | ||
], | ||
] | ||
), | ||
]); | ||
|
||
$columns = $grid->columns; | ||
$this->assertCount(count($row), $columns); | ||
|
||
foreach ($columns as $index => $column) { | ||
$this->assertInstanceOf(DataColumn::className(), $column); | ||
$this->assertArrayHasKey($column->attribute, $row); | ||
} | ||
|
||
$row = array_merge($row, ['relation' => ['id' => 1, 'name' => 'RelationName',],]); | ||
$row = array_merge($row, ['otherRelation' => (object)$row['relation']]); | ||
|
||
$grid = new GridView([ | ||
'dataProvider' => new ArrayDataProvider( | ||
[ | ||
'allModels' => [ | ||
$row, | ||
], | ||
] | ||
), | ||
]); | ||
|
||
$columns = $grid->columns; | ||
$this->assertCount(count($row) - 2, $columns); | ||
|
||
foreach ($columns as $index => $column) { | ||
$this->assertInstanceOf(DataColumn::className(), $column); | ||
$this->assertArrayHasKey($column->attribute, $row); | ||
$this->assertNotEquals('relation', $column->attribute); | ||
$this->assertNotEquals('otherRelation', $column->attribute); | ||
} | ||
} | ||
} |