From 1be4fea69c93fbc23ba3ce3ce9065c99299d6dfe Mon Sep 17 00:00:00 2001 From: lav45 Date: Sat, 15 Jun 2024 22:15:57 +0300 Subject: [PATCH] Remove legacy code --- ActiveDataProvider.php | 3 --- composer.json | 2 +- tests/ActiveDataProviderTest.php | 19 +++++++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ActiveDataProvider.php b/ActiveDataProvider.php index d800bf0ad..bb89f649d 100644 --- a/ActiveDataProvider.php +++ b/ActiveDataProvider.php @@ -122,9 +122,6 @@ protected function prepareModels() if (is_array(($results = $query->search($this->db)))) { $this->setQueryResults($results); - if ($pagination !== false) { - $pagination->totalCount = $this->getTotalCount(); - } return $results['hits']['hits']; } $this->setQueryResults([]); diff --git a/composer.json b/composer.json index ca696bfab..526f4c452 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } ], "require": { - "yiisoft/yii2": "<=2.0.49", + "yiisoft/yii2": ">=2.0.50", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", diff --git a/tests/ActiveDataProviderTest.php b/tests/ActiveDataProviderTest.php index 6b6bad943..58c283867 100644 --- a/tests/ActiveDataProviderTest.php +++ b/tests/ActiveDataProviderTest.php @@ -138,4 +138,23 @@ public function testRefresh() $dataProvider->refresh(); $this->assertEquals(1, $dataProvider->getTotalCount()); } + + public function testTotalCountAfterSearch() + { + $query = Customer::find(); + $provider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => [ + 'pageSize' => 2, + ], + ]); + + $pagination = $provider->getPagination(); + $this->assertEquals(2, $pagination->getPageCount()); + $this->assertEquals(3, $pagination->getTotalCount()); + + $query->andWhere(['name' => 'user2']); + $this->assertEquals(1, $pagination->getPageCount()); + $this->assertEquals(1, $pagination->getTotalCount()); + } }