MediaWiki  REL1_20
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         public function setUp() {
00062                 parent::setUp();
00063 
00064                 $dbw = wfGetDB( DB_MASTER );
00065 
00066                 $isSqlite = $GLOBALS['wgDBtype'] === 'sqlite';
00067 
00068                 $idField = $isSqlite ? 'INTEGER' : 'INT unsigned';
00069                 $primaryKey = $isSqlite ? 'PRIMARY KEY AUTOINCREMENT' : 'auto_increment PRIMARY KEY';
00070 
00071                 $dbw->query(
00072                         'CREATE TABLE IF NOT EXISTS ' . $dbw->tableName( 'orm_test' ) . '(
00073                                 test_id                    ' . $idField . '        NOT NULL ' . $primaryKey . ',
00074                                 test_name                  VARCHAR(255)        NOT NULL,
00075                                 test_age                   TINYINT unsigned    NOT NULL,
00076                                 test_height                FLOAT               NOT NULL,
00077                                 test_awesome               TINYINT unsigned    NOT NULL,
00078                                 test_stuff                 BLOB                NOT NULL,
00079                                 test_moarstuff             BLOB                NOT NULL,
00080                                 test_time                  varbinary(14)       NOT NULL
00081                         );'
00082                 );
00083         }
00084 
00085         public function constructorTestProvider() {
00086                 return array(
00087                         array(
00088                                 array(
00089                                         'name' => 'Foobar',
00090                                         'age' => 42,
00091                                         'height' => 9000.1,
00092                                         'awesome' => true,
00093                                         'stuff' => array( 13, 11, 7, 5, 3, 2 ),
00094                                         'moarstuff' => (object)array( 'foo' => 'bar', 'bar' => array( 4, 2 ), 'baz' => true )
00095                                 ),
00096                                 true
00097                         ),
00098                 );
00099         }
00100 
00101 }
00102 
00103 class TestORMRow extends ORMRow {}
00104 
00105 class TestORMTable extends ORMTable {
00106 
00114         public function getName() {
00115                 return 'orm_test';
00116         }
00117 
00126         public function getRowClass() {
00127                 return 'TestORMRow';
00128         }
00129 
00149         public function getFields() {
00150                 return array(
00151                         'id' => 'id',
00152                         'name' => 'str',
00153                         'age' => 'int',
00154                         'height' => 'float',
00155                         'awesome' => 'bool',
00156                         'stuff' => 'array',
00157                         'moarstuff' => 'blob',
00158                         'time' => 'int', // TS_MW
00159                 );
00160         }
00161 
00169         protected function getFieldPrefix() {
00170                 return 'test_';
00171         }
00172 
00173 
00174 }