MediaWiki  REL1_21
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 
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                         __METHOD__
00083                 );
00084         }
00085 
00086         protected function tearDown() {
00087                 $dbw = wfGetDB( DB_MASTER );
00088                 $dbw->dropTable( 'orm_test', __METHOD__ );
00089 
00090                 parent::tearDown();
00091         }
00092 
00093         public function constructorTestProvider() {
00094                 return array(
00095                         array(
00096                                 array(
00097                                         'name' => 'Foobar',
00098                                         'time' => '20120101020202',
00099                                         'age' => 42,
00100                                         'height' => 9000.1,
00101                                         'awesome' => true,
00102                                         'stuff' => array( 13, 11, 7, 5, 3, 2 ),
00103                                         'moarstuff' => (object)array( 'foo' => 'bar', 'bar' => array( 4, 2 ), 'baz' => true )
00104                                 ),
00105                                 true
00106                         ),
00107                 );
00108         }
00109 
00114         protected function getMockValues() {
00115                 return array(
00116                         'id' => 1,
00117                         'str' => 'foobar4645645',
00118                         'int' => 42,
00119                         'float' => 4.2,
00120                         'bool' => '',
00121                         'array' => array( 42, 'foobar' ),
00122                         'blob' => new stdClass()
00123                 );
00124         }
00125 
00126 }
00127 
00128 class TestORMRow extends ORMRow {}
00129 
00130 class TestORMTable extends ORMTable {
00131 
00139         public function getName() {
00140                 return 'orm_test';
00141         }
00142 
00151         public function getRowClass() {
00152                 return 'TestORMRow';
00153         }
00154 
00174         public function getFields() {
00175                 return array(
00176                         'id' => 'id',
00177                         'name' => 'str',
00178                         'age' => 'int',
00179                         'height' => 'float',
00180                         'awesome' => 'bool',
00181                         'stuff' => 'array',
00182                         'moarstuff' => 'blob',
00183                         'time' => 'str', // TS_MW
00184                 );
00185         }
00186 
00194         protected function getFieldPrefix() {
00195                 return 'test_';
00196         }
00197 
00198 
00199 }