mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 05:48:11 +08:00
Fix #20605: Fix return value in SerialColumn::renderDataCellContent()
This commit is contained in:
@ -54,6 +54,7 @@ Yii Framework 2 Change Log
|
|||||||
- Enh #20591: Add PHPStan/Psalm annotations for `yii\rbac\BaseManager::getItems()` (mspirkov)
|
- Enh #20591: Add PHPStan/Psalm annotations for `yii\rbac\BaseManager::getItems()` (mspirkov)
|
||||||
- Bug #20594: Fix `@return` annotation for `Instance::get()` (mspirkov)
|
- Bug #20594: Fix `@return` annotation for `Instance::get()` (mspirkov)
|
||||||
- Bug #20595: Fix `@return` annotation for `BaseHtml::getAttributeValue()` (mspirkov)
|
- Bug #20595: Fix `@return` annotation for `BaseHtml::getAttributeValue()` (mspirkov)
|
||||||
|
- Bug #20605: Fix return value in `SerialColumn::renderDataCellContent()` (mspirkov)
|
||||||
- Bug #20604: Fix `@var` annotation for `yii\db\Command::$pdoStatement` (mspirkov)
|
- Bug #20604: Fix `@var` annotation for `yii\db\Command::$pdoStatement` (mspirkov)
|
||||||
- Bug #20600: Fix `@var` annotation for `yii\test\FileFixtureTrait::$dataFile` (mspirkov)
|
- Bug #20600: Fix `@var` annotation for `yii\test\FileFixtureTrait::$dataFile` (mspirkov)
|
||||||
- Bug #20608: Fix `@return` annotations for `yii\rest\Serializer` methods (mspirkov)
|
- Bug #20608: Fix `@return` annotations for `yii\rest\Serializer` methods (mspirkov)
|
||||||
|
|||||||
@ -42,9 +42,9 @@ class SerialColumn extends Column
|
|||||||
{
|
{
|
||||||
$pagination = $this->grid->dataProvider->getPagination();
|
$pagination = $this->grid->dataProvider->getPagination();
|
||||||
if ($pagination !== false) {
|
if ($pagination !== false) {
|
||||||
return $pagination->getOffset() + $index + 1;
|
return (string) ($pagination->getOffset() + $index + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $index + 1;
|
return (string) ($index + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
108
tests/framework/grid/SerialColumnTest.php
Normal file
108
tests/framework/grid/SerialColumnTest.php
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @link https://www.yiiframework.com/
|
||||||
|
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||||
|
* @license https://www.yiiframework.com/license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace yiiunit\framework\grid;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use yii\data\ArrayDataProvider;
|
||||||
|
use yii\data\Pagination;
|
||||||
|
use yii\grid\GridView;
|
||||||
|
use yii\grid\SerialColumn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group grid
|
||||||
|
*/
|
||||||
|
class SerialColumnTest extends \yiiunit\TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @dataProvider provideRenderDataCellData
|
||||||
|
*/
|
||||||
|
public function testRenderDataCell(
|
||||||
|
array $dataProviderConfig,
|
||||||
|
?string $page,
|
||||||
|
int $index,
|
||||||
|
string $expectedResult
|
||||||
|
): void {
|
||||||
|
$this->mockWebApplication();
|
||||||
|
|
||||||
|
Yii::$app->getRequest()->setQueryParams([
|
||||||
|
'page' => $page,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$column = new SerialColumn([
|
||||||
|
'grid' => new GridView([
|
||||||
|
'dataProvider' => new ArrayDataProvider($dataProviderConfig),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$result = $column->renderDataCell(['id' => 1], 1, $index);
|
||||||
|
$this->assertSame($expectedResult, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function provideRenderDataCellData(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'pagination' => false,
|
||||||
|
],
|
||||||
|
null,
|
||||||
|
0,
|
||||||
|
'<td>1</td>',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'pagination' => false,
|
||||||
|
],
|
||||||
|
null,
|
||||||
|
5,
|
||||||
|
'<td>6</td>',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'pagination' => new Pagination(),
|
||||||
|
],
|
||||||
|
null,
|
||||||
|
0,
|
||||||
|
'<td>1</td>',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'pagination' => new Pagination(),
|
||||||
|
],
|
||||||
|
null,
|
||||||
|
4,
|
||||||
|
'<td>5</td>',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'pagination' => new Pagination([
|
||||||
|
'totalCount' => 20,
|
||||||
|
'defaultPageSize' => 10,
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
'2',
|
||||||
|
0,
|
||||||
|
'<td>11</td>',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'pagination' => new Pagination([
|
||||||
|
'totalCount' => 20,
|
||||||
|
'defaultPageSize' => 10,
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
'2',
|
||||||
|
3,
|
||||||
|
'<td>14</td>',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user