*/ require_once __DIR__ . "/ORMRowTest.php"; class TestORMRowTest extends ORMRowTest { /** * @since 1.20 * @return string */ protected function getRowClass() { return 'TestORMRow'; } /** * @since 1.20 * @return IORMTable */ protected function getTableInstance() { return TestORMTable::singleton(); } protected function setUp() { parent::setUp(); $dbw = wfGetDB( DB_MASTER ); $isSqlite = $GLOBALS['wgDBtype'] === 'sqlite'; $idField = $isSqlite ? 'INTEGER' : 'INT unsigned'; $primaryKey = $isSqlite ? 'PRIMARY KEY AUTOINCREMENT' : 'auto_increment PRIMARY KEY'; $dbw->query( 'CREATE TABLE IF NOT EXISTS ' . $dbw->tableName( 'orm_test' ) . '( test_id ' . $idField . ' NOT NULL ' . $primaryKey . ', test_name VARCHAR(255) NOT NULL, test_age TINYINT unsigned NOT NULL, test_height FLOAT NOT NULL, test_awesome TINYINT unsigned NOT NULL, test_stuff BLOB NOT NULL, test_moarstuff BLOB NOT NULL, test_time varbinary(14) NOT NULL );', __METHOD__ ); } protected function tearDown() { $dbw = wfGetDB( DB_MASTER ); $dbw->dropTable( 'orm_test', __METHOD__ ); parent::tearDown(); } public function constructorTestProvider() { return array( array( array( 'name' => 'Foobar', 'time' => '20120101020202', 'age' => 42, 'height' => 9000.1, 'awesome' => true, 'stuff' => array( 13, 11, 7, 5, 3, 2 ), 'moarstuff' => (object)array( 'foo' => 'bar', 'bar' => array( 4, 2 ), 'baz' => true ) ), true ), ); } /** * @since 1.21 * @return array */ protected function getMockValues() { return array( 'id' => 1, 'str' => 'foobar4645645', 'int' => 42, 'float' => 4.2, 'bool' => '', 'array' => array( 42, 'foobar' ), 'blob' => new stdClass() ); } } class TestORMRow extends ORMRow {} class TestORMTable extends ORMTable { /** * Returns the name of the database table objects of this type are stored in. * * @since 1.20 * * @return string */ public function getName() { return 'orm_test'; } /** * Returns the name of a IORMRow implementing class that * represents single rows in this table. * * @since 1.20 * * @return string */ public function getRowClass() { return 'TestORMRow'; } /** * Returns an array with the fields and their types this object contains. * This corresponds directly to the fields in the database, without prefix. * * field name => type * * Allowed types: * * id * * str * * int * * float * * bool * * array * * blob * * @since 1.20 * * @return array */ public function getFields() { return array( 'id' => 'id', 'name' => 'str', 'age' => 'int', 'height' => 'float', 'awesome' => 'bool', 'stuff' => 'array', 'moarstuff' => 'blob', 'time' => 'str', // TS_MW ); } /** * Gets the db field prefix. * * @since 1.20 * * @return string */ protected function getFieldPrefix() { return 'test_'; } }