Skip to content

Commit

Permalink
Fix ActiveDataProviderTest::testPaginationBeforeModels
Browse files Browse the repository at this point in the history
  • Loading branch information
lav45 committed Nov 17, 2023
1 parent 7fa103c commit 4a7639a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
11 changes: 5 additions & 6 deletions framework/data/BaseDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,15 @@ public function getPagination()
public function setPagination($value)
{
if (is_array($value)) {
$config = [
'class' => Pagination::className(),
'totalCount' => $this->getTotalCount(),
];
$config = ['class' => Pagination::className()];
if ($this->id !== null) {
$config['pageParam'] = $this->id . '-page';
$config['pageSizeParam'] = $this->id . '-per-page';
}
$this->_pagination = Yii::createObject(array_merge($config, $value));
} elseif ($value instanceof Pagination || $value === false) {
$value = Yii::createObject(array_merge($config, $value));
}
if ($value instanceof Pagination || $value === false) {
$value->totalCount = $this->getTotalCount();
$this->_pagination = $value;
} else {
throw new InvalidArgumentException('Only Pagination instance, configuration array or false is allowed.');
Expand Down
3 changes: 1 addition & 2 deletions tests/framework/data/ActiveDataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ public function testPaginationBeforeModels()
'query' => $query->from('order')->orderBy('id'),
]);
$pagination = $provider->getPagination();
$this->assertEquals(0, $pagination->getPageCount());
$this->assertCount(3, $provider->getModels());
$this->assertEquals(1, $pagination->getPageCount());
$this->assertCount(3, $provider->getModels());

$provider->getPagination()->pageSize = 2;
$this->assertCount(3, $provider->getModels());
Expand Down

0 comments on commit 4a7639a

Please sign in to comment.