RangeQueryTest.php 761 Bytes
Newer Older
1 2
<?php

3
namespace Drupal\KernelTests\Core\Database;
4 5

/**
6 7 8
 * Tests the Range query functionality.
 *
 * @group Database
9
 */
10
class RangeQueryTest extends DatabaseTestBase {
11

12
  /**
13
   * Confirms that range queries work and return the correct result.
14
   */
15
  public function testRangeQuery() {
16
    // Test if return correct number of rows.
17
    $range_rows = $this->connection->queryRange("SELECT name FROM {test} ORDER BY name", 1, 3)->fetchAll();
18
    $this->assertEqual(count($range_rows), 3, 'Range query work and return correct number of rows.');
19 20

    // Test if return target data.
21 22 23
    $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);
24
  }
25

26
}