Merge "Revert "Adding sanity check to Title::isRedirect().""
[lhc/web/wiklou.git] / tests / phpunit / includes / db / TestORMRowTest.php
1 <?php
2
3 /**
4 * Tests for the TestORMRow class.
5 * TestORMRow is a dummy class to be able to test the abstract ORMRow class.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
21 *
22 * @file
23 * @since 1.20
24 *
25 * @ingroup Test
26 *
27 * @group ORM
28 *
29 * The database group has as a side effect that temporal database tables are created. This makes
30 * it possible to test without poisoning a production database.
31 * @group Database
32 *
33 * Some of the tests takes more time, and needs therefor longer time before they can be aborted
34 * as non-functional. The reason why tests are aborted is assumed to be set up of temporal databases
35 * that hold the first tests in a pending state awaiting access to the database.
36 * @group medium
37 *
38 * @licence GNU GPL v2+
39 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
40 */
41 class TestORMRowTest extends ORMRowTest {
42
43 /**
44 * @since 1.20
45 * @return string
46 */
47 protected function getRowClass() {
48 return 'TestORMRow';
49 }
50
51 /**
52 * @since 1.20
53 * @return IORMTable
54 */
55 protected function getTableInstance() {
56 return TestORMtable::singleton();
57 }
58
59 public function setUp() {
60 parent::setUp();
61
62 $dbw = wfGetDB( DB_MASTER );
63
64 $isSqlite = $GLOBALS['wgDBtype'] === 'sqlite';
65
66 $idField = $isSqlite ? 'INTEGER' : 'INT unsigned';
67 $primaryKey = $isSqlite ? 'PRIMARY KEY AUTOINCREMENT' : 'auto_increment PRIMARY KEY';
68
69 $dbw->safeQuery(
70 'CREATE TABLE IF NOT EXISTS ' . $dbw->tableName( 'orm_test' ) . '(
71 test_id ' . $idField . ' NOT NULL ' . $primaryKey . ',
72 test_name VARCHAR(255) NOT NULL,
73 test_age TINYINT unsigned NOT NULL,
74 test_height FLOAT NOT NULL,
75 test_awesome TINYINT unsigned NOT NULL,
76 test_stuff BLOB NOT NULL,
77 test_moarstuff BLOB NOT NULL,
78 test_time varbinary(14) NOT NULL
79 );'
80 );
81 }
82
83 public function constructorTestProvider() {
84 return array(
85 array(
86 array(
87 'name' => 'Foobar',
88 'age' => 42,
89 'height' => 9000.1,
90 'awesome' => true,
91 'stuff' => array( 13, 11, 7, 5, 3, 2 ),
92 'moarstuff' => (object)array( 'foo' => 'bar', 'bar' => array( 4, 2 ), 'baz' => true )
93 ),
94 true
95 ),
96 );
97 }
98
99 }
100
101 class TestORMRow extends ORMRow {}
102
103 class TestORMTable extends ORMTable {
104
105 /**
106 * Returns the name of the database table objects of this type are stored in.
107 *
108 * @since 1.20
109 *
110 * @return string
111 */
112 public function getName() {
113 return 'orm_test';
114 }
115
116 /**
117 * Returns the name of a IORMRow implementing class that
118 * represents single rows in this table.
119 *
120 * @since 1.20
121 *
122 * @return string
123 */
124 public function getRowClass() {
125 return 'TestORMRow';
126 }
127
128 /**
129 * Returns an array with the fields and their types this object contains.
130 * This corresponds directly to the fields in the database, without prefix.
131 *
132 * field name => type
133 *
134 * Allowed types:
135 * * id
136 * * str
137 * * int
138 * * float
139 * * bool
140 * * array
141 * * blob
142 *
143 * @since 1.20
144 *
145 * @return array
146 */
147 public function getFields() {
148 return array(
149 'id' => 'id',
150 'name' => 'str',
151 'age' => 'int',
152 'height' => 'float',
153 'awesome' => 'bool',
154 'stuff' => 'array',
155 'moarstuff' => 'blob',
156 'time' => 'int', // TS_MW
157 );
158 }
159
160 /**
161 * Gets the db field prefix.
162 *
163 * @since 1.20
164 *
165 * @return string
166 */
167 protected function getFieldPrefix() {
168 return 'test_';
169 }
170
171
172 }