Merge "Slight improvements to FormSpecialPage behavior."
[lhc/web/wiklou.git] / tests / phpunit / includes / db / DatabaseSqliteTest.php
index 3e71603..91ab33a 100644 (file)
@@ -3,12 +3,13 @@
 class MockDatabaseSqlite extends DatabaseSqliteStandalone {
        var $lastQuery;
 
-       function __construct( ) {
+       function __construct() {
                parent::__construct( ':memory:' );
        }
 
        function query( $sql, $fname = '', $tempIgnore = false ) {
                $this->lastQuery = $sql;
+
                return true;
        }
 
@@ -48,8 +49,8 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
        private function assertResultIs( $expected, $res ) {
                $this->assertNotNull( $res );
                $i = 0;
-               foreach( $res as $row ) {
-                       foreach( $expected[$i] as $key => $value ) {
+               foreach ( $res as $row ) {
+                       foreach ( $expected[$i] as $key => $value ) {
                                $this->assertTrue( isset( $row->$key ) );
                                $this->assertEquals( $value, $row->$key );
                        }
@@ -108,38 +109,38 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
                $this->assertEquals( 'foo', $this->replaceVars( 'foo' ), "Don't break anything accidentally" );
 
                $this->assertEquals( "CREATE TABLE /**/foo (foo_key INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "
-                       . "foo_bar TEXT, foo_name TEXT NOT NULL DEFAULT '', foo_int INTEGER, foo_int2 INTEGER );",
+                               . "foo_bar TEXT, foo_name TEXT NOT NULL DEFAULT '', foo_int INTEGER, foo_int2 INTEGER );",
                        $this->replaceVars( "CREATE TABLE /**/foo (foo_key int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
                        foo_bar char(13), foo_name varchar(255) binary NOT NULL DEFAULT '', foo_int tinyint ( 8 ), foo_int2 int(16) ) ENGINE=MyISAM;" )
-                       );
+               );
 
                $this->assertEquals( "CREATE TABLE foo ( foo1 REAL, foo2 REAL, foo3 REAL );",
                        $this->replaceVars( "CREATE TABLE foo ( foo1 FLOAT, foo2 DOUBLE( 1,10), foo3 DOUBLE PRECISION );" )
-                       );
+               );
 
                $this->assertEquals( "CREATE TABLE foo ( foo_binary1 BLOB, foo_binary2 BLOB );",
                        $this->replaceVars( "CREATE TABLE foo ( foo_binary1 binary(16), foo_binary2 varbinary(32) );" )
-                       );
+               );
 
                $this->assertEquals( "CREATE TABLE text ( text_foo TEXT );",
                        $this->replaceVars( "CREATE TABLE text ( text_foo tinytext );" ),
                        'Table name changed'
-                       );
+               );
 
                $this->assertEquals( "CREATE TABLE foo ( foobar INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL );",
-                       $this->replaceVars("CREATE TABLE foo ( foobar INT PRIMARY KEY NOT NULL AUTO_INCREMENT );" )
-                       );
+                       $this->replaceVars( "CREATE TABLE foo ( foobar INT PRIMARY KEY NOT NULL AUTO_INCREMENT );" )
+               );
                $this->assertEquals( "CREATE TABLE foo ( foobar INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL );",
-                       $this->replaceVars("CREATE TABLE foo ( foobar INT PRIMARY KEY AUTO_INCREMENT NOT NULL );" )
-                       );
+                       $this->replaceVars( "CREATE TABLE foo ( foobar INT PRIMARY KEY AUTO_INCREMENT NOT NULL );" )
+               );
 
                $this->assertEquals( "CREATE TABLE enums( enum1 TEXT, myenum TEXT)",
                        $this->replaceVars( "CREATE TABLE enums( enum1 ENUM('A', 'B'), myenum ENUM ('X', 'Y'))" )
-                       );
+               );
 
                $this->assertEquals( "ALTER TABLE foo ADD COLUMN foo_bar INTEGER DEFAULT 42",
                        $this->replaceVars( "ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42" )
-                       );
+               );
        }
 
        public function testTableName() {
@@ -232,7 +233,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
 
        /**
         * Runs upgrades of older databases and compares results with current schema
-        * @todo: currently only checks list of tables
+        * @todo Currently only checks list of tables
         */
        public function testUpgrades() {
                global $IP, $wgVersion, $wgProfileToDatabase;
@@ -311,7 +312,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
                        $db->query( 'CREATE TABLE a ( a_1 )', __METHOD__ ), "Database creationg" );
                $this->assertTrue( $db->insert( 'a', array( 'a_1' => 10 ), __METHOD__ ),
                        "Insertion worked" );
-               $this->assertEquals( "integer", gettype( $db->insertId() ), "Actual typecheck" );
+               $this->assertInternalType( 'integer', $db->insertId(), "Actual typecheck" );
                $this->assertTrue( $db->close(), "closing database" );
        }
 
@@ -327,12 +328,14 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
                $db->sourceFile( "$IP/tests/phpunit/data/db/sqlite/tables-$version.sql" );
                $updater = DatabaseUpdater::newForDB( $db, false, $maint );
                $updater->doUpdates( array( 'core' ) );
+
                return $db;
        }
 
        private function getTables( $db ) {
                $list = array_flip( $db->listTables() );
                $excluded = array(
+                       'external_user', // removed from core in 1.22
                        'math', // moved out of core in 1.18
                        'trackbacks', // removed from core in 1.19
                        'searchindex',
@@ -348,6 +351,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
                }
                $list = array_flip( $list );
                sort( $list );
+
                return $list;
        }
 
@@ -359,6 +363,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
                        $cols[$col->name] = $col;
                }
                ksort( $cols );
+
                return $cols;
        }
 
@@ -376,14 +381,15 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
                        $indexes[$index->name] = $index;
                }
                ksort( $indexes );
+
                return $indexes;
        }
 
        function testCaseInsensitiveLike() {
                // TODO: Test this for all databases
-               $db = new DatabaseSqliteStandalone( ':memory:' );\r
-               $res = $db->query( 'SELECT "a" LIKE "A" AS a' );\r
-               $row = $res->fetchRow();\r
-               $this->assertFalse( (bool)$row['a'] );\r
+               $db = new DatabaseSqliteStandalone( ':memory:' );
+               $res = $db->query( 'SELECT "a" LIKE "A" AS a' );
+               $row = $res->fetchRow();
+               $this->assertFalse( (bool)$row['a'] );
        }
 }