diff --git a/tests/Integration/Database/EloquentCursorPaginateTest.php b/tests/Integration/Database/EloquentCursorPaginateTest.php index 01fd4b49e8b8..29920cb9d88c 100644 --- a/tests/Integration/Database/EloquentCursorPaginateTest.php +++ b/tests/Integration/Database/EloquentCursorPaginateTest.php @@ -21,6 +21,7 @@ protected function afterRefreshingDatabase() Schema::create('test_users', function ($table) { $table->increments('id'); + $table->string('name')->nullable(); $table->timestamps(); }); } @@ -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++) {