MediaWiki  REL1_22
TestORMRowTest.php
Go to the documentation of this file.
00001 <?php
00002 
00041 require_once __DIR__ . "/ORMRowTest.php";
00042 
00043 class TestORMRowTest extends ORMRowTest {
00044 
00049     protected function getRowClass() {
00050         return 'TestORMRow';
00051     }
00052 
00057     protected function getTableInstance() {
00058         return TestORMTable::singleton();
00059     }
00060 
00061     protected function setUp() {
00062         parent::setUp();
00063 
00064         $dbw = wfGetDB( DB_MASTER );
00065 
00066         $isSqlite = $GLOBALS['wgDBtype'] === 'sqlite';
00067         $isPostgres = $GLOBALS['wgDBtype'] === 'postgres';
00068 
00069         $idField = $isSqlite ? 'INTEGER' : 'INT unsigned';
00070         $primaryKey = $isSqlite ? 'PRIMARY KEY AUTOINCREMENT' : 'auto_increment PRIMARY KEY';
00071 
00072         if ( $isPostgres ) {
00073             $dbw->query(
00074                 'CREATE TABLE IF NOT EXISTS ' . $dbw->tableName( 'orm_test' ) . "(
00075                     test_id serial PRIMARY KEY,
00076                     test_name TEXT NOT NULL DEFAULT '',
00077                     test_age INTEGER NOT NULL DEFAULT 0,
00078                     test_height REAL NOT NULL DEFAULT 0,
00079                     test_awesome INTEGER NOT NULL DEFAULT 0,
00080                     test_stuff BYTEA,
00081                     test_moarstuff BYTEA,
00082                     test_time TIMESTAMPTZ
00083                     );",
00084                     __METHOD__
00085                 );
00086         } else {
00087             $dbw->query(
00088                 'CREATE TABLE IF NOT EXISTS ' . $dbw->tableName( 'orm_test' ) . '(
00089                     test_id                    ' . $idField . '        NOT NULL ' . $primaryKey . ',
00090                     test_name                  VARCHAR(255)        NOT NULL,
00091                     test_age                   TINYINT unsigned    NOT NULL,
00092                     test_height                FLOAT               NOT NULL,
00093                     test_awesome               TINYINT unsigned    NOT NULL,
00094                     test_stuff                 BLOB                NOT NULL,
00095                     test_moarstuff             BLOB                NOT NULL,
00096                     test_time                  varbinary(14)       NOT NULL
00097                 );',
00098                 __METHOD__
00099             );
00100         }
00101     }
00102 
00103     protected function tearDown() {
00104         $dbw = wfGetDB( DB_MASTER );
00105         $dbw->dropTable( 'orm_test', __METHOD__ );
00106 
00107         parent::tearDown();
00108     }
00109 
00110     public function constructorTestProvider() {
00111         $dbw = wfGetDB( DB_MASTER );
00112         return array(
00113             array(
00114                 array(
00115                     'name' => 'Foobar',
00116                     'time' => $dbw->timestamp( '20120101020202' ),
00117                     'age' => 42,
00118                     'height' => 9000.1,
00119                     'awesome' => true,
00120                     'stuff' => array( 13, 11, 7, 5, 3, 2 ),
00121                     'moarstuff' => (object)array( 'foo' => 'bar', 'bar' => array( 4, 2 ), 'baz' => true )
00122                 ),
00123                 true
00124             ),
00125         );
00126     }
00127 
00132     protected function getMockValues() {
00133         return array(
00134             'id' => 1,
00135             'str' => 'foobar4645645',
00136             'int' => 42,
00137             'float' => 4.2,
00138             'bool' => '',
00139             'array' => array( 42, 'foobar' ),
00140             'blob' => new stdClass()
00141         );
00142     }
00143 }
00144 
00145 class TestORMRow extends ORMRow {
00146 }
00147 
00148 class TestORMTable extends ORMTable {
00149 
00157     public function getName() {
00158         return 'orm_test';
00159     }
00160 
00169     public function getRowClass() {
00170         return 'TestORMRow';
00171     }
00172 
00192     public function getFields() {
00193         return array(
00194             'id' => 'id',
00195             'name' => 'str',
00196             'age' => 'int',
00197             'height' => 'float',
00198             'awesome' => 'bool',
00199             'stuff' => 'array',
00200             'moarstuff' => 'blob',
00201             'time' => 'str', // TS_MW
00202         );
00203     }
00204 
00212     protected function getFieldPrefix() {
00213         return 'test_';
00214     }
00215 }