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