Skip to content

Commit

Permalink
Add eloquent test for cursor pagination with union and multiple aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsvdanker committed Apr 16, 2024
1 parent 678b6f6 commit 5593882
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/Integration/Database/EloquentCursorPaginateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected function afterRefreshingDatabase()

Schema::create('test_users', function ($table) {
$table->increments('id');
$table->string('name')->nullable();
$table->timestamps();
});
}
Expand Down Expand Up @@ -167,6 +168,32 @@ public function testPaginationWithMultipleWhereClauses()
);
}

public function testPaginationWithMultipleAliases()
{
TestUser::create(['name' => 'A (user)']);
TestUser::create(['name' => 'C (user)']);

TestPost::create(['title' => 'B (post)']);
TestPost::create(['title' => 'D (post)']);

$table1 = TestPost::select(['title as alias']);
$table2 = TestUser::select(['name as alias']);

$columns = ['alias'];
$cursorName = 'cursor-name';
$cursor = new Cursor(['alias' => 'A (user)']);

$result = $table1->toBase()
->union($table2->toBase())
->orderBy('alias', 'asc')
->cursorPaginate(1, $columns, $cursorName, $cursor);

$this->assertSame(['alias'], $result->getOptions()['parameters']);

$this->assertCount(1, $result->items(), 'Expect cursor paginated query should have 1 result');
$this->assertEquals('B (post)', current($result->items())->alias, 'Expect the paginated query would return `B (post)`');
}

public function testPaginationWithAliasedOrderBy()
{
for ($i = 1; $i <= 6; $i++) {
Expand Down

0 comments on commit 5593882

Please sign in to comment.