RangeQueryTest.php 843 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 14 15 16

  /**
   * Modules to enable.
   *
   * @var array
   */
17
  public static $modules = ['database_test'];
18

19
  /**
20
   * Confirms that range queries work and return the correct result.
21 22 23
   */
  function testRangeQuery() {
    // Test if return correct number of rows.
24
    $range_rows = db_query_range("SELECT name FROM {test} ORDER BY name", 1, 3)->fetchAll();
25
    $this->assertEqual(count($range_rows), 3, 'Range query work and return correct number of rows.');
26 27

    // Test if return target data.
28 29 30
    $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);
31
  }
32

33
}