function SelectPagerDefaultTest::testInnerPagerQuery

Same name in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php \Drupal\Tests\system\Functional\Database\SelectPagerDefaultTest::testInnerPagerQuery()
  2. 10 core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php \Drupal\Tests\system\Functional\Database\SelectPagerDefaultTest::testInnerPagerQuery()
  3. 11.x core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php \Drupal\Tests\system\Functional\Database\SelectPagerDefaultTest::testInnerPagerQuery()

Confirms that a pager query results with an inner pager query are valid.

This is a regression test for #467984.

File

core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php, line 95

Class

SelectPagerDefaultTest
Tests the pager query select extender.

Namespace

Drupal\Tests\system\Functional\Database

Code

public function testInnerPagerQuery() {
    $connection = Database::getConnection();
    $query = $connection->select('test', 't')
        ->extend(PagerSelectExtender::class);
    $query->fields('t', [
        'age',
    ])
        ->orderBy('age')
        ->limit(5);
    $outer_query = $connection->select($query);
    $outer_query->addField('subquery', 'age');
    $outer_query->orderBy('age');
    $ages = $outer_query->execute()
        ->fetchCol();
    $this->assertEquals([
        25,
        26,
        27,
        28,
    ], $ages, 'Inner pager query returned the correct ages.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.