You are here

function RangeQueryTest::testRangeQuery in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/RangeQueryTest.php \Drupal\system\Tests\Database\RangeQueryTest::testRangeQuery()

Confirms that range queries work and return the correct result.

File

core/modules/system/src/Tests/Database/RangeQueryTest.php, line 27
Contains \Drupal\system\Tests\Database\RangeQueryTest.

Class

RangeQueryTest
Tests the Range query functionality.

Namespace

Drupal\system\Tests\Database

Code

function testRangeQuery() {

  // Test if return correct number of rows.
  $range_rows = db_query_range("SELECT name FROM {test} ORDER BY name", 1, 3)
    ->fetchAll();
  $this
    ->assertEqual(count($range_rows), 3, 'Range query work and return correct number of rows.');

  // Test if return target data.
  $raw_rows = db_query('SELECT name FROM {test} ORDER BY name')
    ->fetchAll();
  $raw_rows = array_slice($raw_rows, 1, 3);
  $this
    ->assertEqual($range_rows, $raw_rows);
}