You are here

public function SqlServerSchemaTest::testAddChangeWithIndex in Drupal driver for SQL Server and SQL Azure 7

Same name and namespace in other branches
  1. 7.3 tests/sqlsrv.schema.test \SqlServerSchemaTest::testAddChangeWithIndex()
  2. 7.2 tests/sqlsrv.schema.test \SqlServerSchemaTest::testAddChangeWithIndex()

Test db_add_field() and db_change_field() with indexes.

File

tests/sqlsrv.schema.test, line 192
Support tests for SQL Server.

Class

SqlServerSchemaTest
@file Support tests for SQL Server.

Code

public function testAddChangeWithIndex() {
  $table_spec = array(
    'fields' => array(
      'id' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  db_create_table('test_table', $table_spec);

  // Add a default value.
  db_add_field('test_table', 'test', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 1,
  ), array(
    'indexes' => array(
      'id_test' => array(
        'id, test',
      ),
    ),
  ));
  $this
    ->assertTrue(db_index_exists('test_table', 'id_test'), t('The index has been created by db_add_field().'));

  // Change the definition, we have by contract to remove the indexes before.
  db_drop_index('test_table', 'id_test');
  $this
    ->assertFalse(db_index_exists('test_table', 'id_test'), t('The index has been dropped.'));
  db_change_field('test_table', 'test', 'test', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 1,
  ), array(
    'indexes' => array(
      'id_test' => array(
        'id, test',
      ),
    ),
  ));
  $this
    ->assertTrue(db_index_exists('test_table', 'id_test'), t('The index has been recreated by db_change_field().'));
}