From aa7a5ecea00f1853bcf4b95fe7ca0a21c27101b0 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Tue, 25 May 2010 17:32:18 +0000 Subject: [PATCH] New test for SQLite that checks tables.sql conversion as a whole --- maintenance/tests/DatabaseSqliteTest.php | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/maintenance/tests/DatabaseSqliteTest.php b/maintenance/tests/DatabaseSqliteTest.php index 6ca0976056..69d4cb1d51 100644 --- a/maintenance/tests/DatabaseSqliteTest.php +++ b/maintenance/tests/DatabaseSqliteTest.php @@ -54,4 +54,31 @@ class DatabaseSqliteTest extends PHPUnit_Framework_TestCase { $this->replaceVars( "ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42" ) ); } + + function testEntireSchema() { + global $IP; + + $allowedTypes = array_flip( array( + 'integer', + 'real', + 'text', + 'blob', // NULL type is omitted intentionally + ) ); + + $db = new DatabaseSqliteStandalone( ':memory:' ); + $db->sourceFile( "$IP/maintenance/tables.sql" ); + + $tables = $db->query( "SELECT name FROM sqlite_master WHERE type='table'", __METHOD__ ); + foreach ( $tables as $table ) { + if ( strpos( $table->name, 'sqlite_' ) === 0 ) continue; + + $columns = $db->query( "PRAGMA table_info({$table->name})", __METHOD__ ); + foreach ( $columns as $col ) { + if ( !isset( $allowedTypes[strtolower( $col->type )] ) ) { + $this->fail( "Table {$table->name} has column {$col->name} with non-native type '{$col->type}'" ); + } + } + } + $db->close(); + } } \ No newline at end of file -- 2.20.1