You are here

public function SelectQueryTest::testTemporaryTables in Drupal driver for SQL Server and SQL Azure 8

Test the temporary table functionality.

File

src/Tests/SelectQueryTest.php, line 180
Definition of Drupal\sqlsrv\Tests\SelectQueryTest.

Class

SelectQueryTest
General tests for SQL Server database driver.

Namespace

Drupal\sqlsrv\Tests

Code

public function testTemporaryTables() {
  $query = db_select('test_task', 't');
  $query
    ->fields('t');
  $table = db_query_temporary((string) $query);

  // First assert that the table exists
  $this
    ->assertTRUE(db_table_exists($table), 'The temporary table exists.');
  $query2 = db_select($table, 't');
  $query2
    ->fields('t');

  // Now make sure that both tables are exactly the same.
  $data1 = $query
    ->execute()
    ->fetchAllAssoc('tid');
  $data2 = $query2
    ->execute()
    ->fetchAllAssoc('tid');

  // User ID's are negative, so this should return 0 matches.
  $this
    ->assertEqual(count($data1), count($data2), 'Temporary table has the same number of rows.');

  // $this->assertEqual(count($data1[0]), count($data2[0]), 'Temporary table has the same number of columns.');
  // Drop the table.
  db_drop_table($table);

  // The table should not exist now.
  $this
    ->assertFALSE(db_table_exists($table), 'The temporary table does not exists.');
}