You are here

schema_regression.test in Schema 6

Same filename and directory in other branches
  1. 7 tests/schema_regression.test

Regression tests for the Schema module

File

tests/schema_regression.test
View source
<?php

/**
 * @file
 * Regression tests for the Schema module
 *
 */
class SchemaRegressionTest extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Schema Regression Tests',
      'description' => 'Schema Regression Tests',
      'group' => 'Schema',
    );
  }
  function setUp() {
    parent::setUp('schema');
  }
  function tearDown() {
    $ret = array();
    db_drop_table($ret, 'schema_testtbl');
    db_query("DROP TABLE schema_testtbl");
    parent::tearDown();
  }

  /**
   * Test API for adding tables
   */
  function testInspectionConflict518210() {

    // Create an unprefixed table...
    $tablename = "schema_testtbl";
    $sql = "CREATE TABLE {$tablename} (\n              fid INT NOT NULL,\n              destid INT NOT NULL\n            )";
    db_query($sql);

    // ...and a prefixed table, with a different column list
    $ret = array();
    $schema = array(
      'fields' => array(
        'sourceid' => array(
          'type' => 'int',
          'not null' => TRUE,
        ),
        'destid' => array(
          'type' => 'int',
          'not null' => TRUE,
        ),
      ),
    );
    db_create_table($ret, $tablename, $schema);

    // Do the full inspection, and get our specified tablename
    $inspect = schema_invoke('inspect');
    $fields = $inspect[$tablename]['fields'];

    // We should see only the columns from the prefixed version
    $this
      ->assertFalse(isset($fields['fid']), t('fid does not exist'));
    $this
      ->assertTrue(isset($fields['sourceid']), t('sourceid exists'));
    $this
      ->assertTrue(isset($fields['destid']), t('destid exists'));

    // Inspect the table by using schema_compare().
    $comparison = schema_compare_table($inspect[$tablename]);
    $this
      ->assertEqual($comparison['status'], 'same');
  }

}

Classes

Namesort descending Description
SchemaRegressionTest @file Regression tests for the Schema module