MediaWiki  1.23.0
TestORMRowTest.php
Go to the documentation of this file.
1 <?php
2 
41 require_once __DIR__ . "/ORMRowTest.php";
42 
46 class TestORMRowTest extends ORMRowTest {
47 
52  protected function getRowClass() {
53  return 'TestORMRow';
54  }
55 
60  protected function getTableInstance() {
61  return TestORMTable::singleton();
62  }
63 
64  protected function setUp() {
65  parent::setUp();
66 
67  $dbw = wfGetDB( DB_MASTER );
68 
69  $isSqlite = $GLOBALS['wgDBtype'] === 'sqlite';
70  $isPostgres = $GLOBALS['wgDBtype'] === 'postgres';
71 
72  $idField = $isSqlite ? 'INTEGER' : 'INT unsigned';
73  $primaryKey = $isSqlite ? 'PRIMARY KEY AUTOINCREMENT' : 'auto_increment PRIMARY KEY';
74 
75  if ( $isPostgres ) {
76  $dbw->query(
77  'CREATE TABLE IF NOT EXISTS ' . $dbw->tableName( 'orm_test' ) . "(
78  test_id serial PRIMARY KEY,
79  test_name TEXT NOT NULL DEFAULT '',
80  test_age INTEGER NOT NULL DEFAULT 0,
81  test_height REAL NOT NULL DEFAULT 0,
82  test_awesome INTEGER NOT NULL DEFAULT 0,
83  test_stuff BYTEA,
84  test_moarstuff BYTEA,
85  test_time TIMESTAMPTZ
86  );",
87  __METHOD__
88  );
89  } else {
90  $dbw->query(
91  'CREATE TABLE IF NOT EXISTS ' . $dbw->tableName( 'orm_test' ) . '(
92  test_id ' . $idField . ' NOT NULL ' . $primaryKey . ',
93  test_name VARCHAR(255) NOT NULL,
94  test_age TINYINT unsigned NOT NULL,
95  test_height FLOAT NOT NULL,
96  test_awesome TINYINT unsigned NOT NULL,
97  test_stuff BLOB NOT NULL,
98  test_moarstuff BLOB NOT NULL,
99  test_time varbinary(14) NOT NULL
100  );',
101  __METHOD__
102  );
103  }
104  }
105 
106  protected function tearDown() {
107  $dbw = wfGetDB( DB_MASTER );
108  $dbw->dropTable( 'orm_test', __METHOD__ );
109 
110  parent::tearDown();
111  }
112 
113  public function constructorTestProvider() {
114  $dbw = wfGetDB( DB_MASTER );
115  return array(
116  array(
117  array(
118  'name' => 'Foobar',
119  'time' => $dbw->timestamp( '20120101020202' ),
120  'age' => 42,
121  'height' => 9000.1,
122  'awesome' => true,
123  'stuff' => array( 13, 11, 7, 5, 3, 2 ),
124  'moarstuff' => (object)array( 'foo' => 'bar', 'bar' => array( 4, 2 ), 'baz' => true )
125  ),
126  true
127  ),
128  );
129  }
130 
135  protected function getMockValues() {
136  return array(
137  'id' => 1,
138  'str' => 'foobar4645645',
139  'int' => 42,
140  'float' => 4.2,
141  'bool' => '',
142  'array' => array( 42, 'foobar' ),
143  'blob' => new stdClass()
144  );
145  }
146 }
147 
148 class TestORMRow extends ORMRow {
149 }
150 
151 class TestORMTable extends ORMTable {
152 
160  public function getName() {
161  return 'orm_test';
162  }
163 
172  public function getRowClass() {
173  return 'TestORMRow';
174  }
175 
195  public function getFields() {
196  return array(
197  'id' => 'id',
198  'name' => 'str',
199  'age' => 'int',
200  'height' => 'float',
201  'awesome' => 'bool',
202  'stuff' => 'array',
203  'moarstuff' => 'blob',
204  'time' => 'str', // TS_MW
205  );
206  }
207 
215  protected function getFieldPrefix() {
216  return 'test_';
217  }
218 }
object
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Definition: globals.txt:25
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ORMTable
Definition: ORMTable.php:31
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
TestORMRowTest\getRowClass
getRowClass()
Definition: TestORMRowTest.php:52
TestORMTable\getName
getName()
Returns the name of the database table objects of this type are stored in.
Definition: TestORMRowTest.php:160
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1530
TestORMTable\getRowClass
getRowClass()
Returns the name of a IORMRow implementing class that represents single rows in this table.
Definition: TestORMRowTest.php:172
TestORMRow
Definition: TestORMRowTest.php:148
TestORMRowTest\getTableInstance
getTableInstance()
Definition: TestORMRowTest.php:60
TestORMRowTest\tearDown
tearDown()
Definition: TestORMRowTest.php:106
TestORMRowTest
@covers TestORMRow
Definition: TestORMRowTest.php:46
TestORMRowTest\constructorTestProvider
constructorTestProvider()
Definition: TestORMRowTest.php:113
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
TestORMTable
Definition: TestORMRowTest.php:151
TestORMTable\getFieldPrefix
getFieldPrefix()
Gets the db field prefix.
Definition: TestORMRowTest.php:215
ORMRow
Definition: ORMRow.php:34
TestORMRowTest\setUp
setUp()
Definition: TestORMRowTest.php:64
TestORMTable\getFields
getFields()
Returns an array with the fields and their types this object contains.
Definition: TestORMRowTest.php:195
$GLOBALS
$GLOBALS['IP']
Definition: ComposerHookHandler.php:6
ORMTable\singleton
static singleton()
Get an instance of this class.
Definition: ORMTable.php:804
TestORMRowTest\getMockValues
getMockValues()
Definition: TestORMRowTest.php:135
ORMRowTest
Definition: ORMRowTest.php:40