Skip to content

Commit

Permalink
Improve testPaginationWithUnionQuery to cover more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Izumi-kun committed Jan 16, 2025
1 parent e9a919c commit 96ff732
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tests/framework/data/ActiveDataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,27 @@ public function testDoesNotPerformQueryWhenHasNoModels()

public function testPaginationWithUnionQuery()
{
$q1 = Item::find()->where(['category_id' => 2]);
$q2 = Item::find()->where(['id' => 1]);
$q1 = Item::find()->where(['category_id' => 2])->with('category');
$q2 = Item::find()->where(['id' => [2, 4]]);
$provider = new ActiveDataProvider([
'db' => $this->getConnection(),
'query' => $q1->union($q2),
'query' => $q1->union($q2)->indexBy('id'),
]);
$pagination = $provider->getPagination();
$pagination->pageSize = 2;
$provider->prepare();
$this->assertEquals(2, $pagination->getPageCount());
$this->assertEquals(4, $provider->getTotalCount());
$this->assertCount(2, $provider->getModels());

$pagination->pageSize = 10;
$provider->prepare(true);
/** @var Item[] $models */
$models = $provider->getModels();
$this->assertCount(4, $models);
$this->assertContainsOnlyInstancesOf(Item::class, $models);
$this->assertEquals('Yii 1.1 Application Development Cookbook', $models[2]->name);
$this->assertEquals('Toy Story', $models[4]->name);
$this->assertTrue($models[2]->isRelationPopulated('category'));
$this->assertTrue($models[4]->isRelationPopulated('category'));
}
}

0 comments on commit 96ff732

Please sign in to comment.