Merge "(bug 42030) Include original URL params in variant links"
[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 require_once __DIR__ . "/ORMRowTest.php";
42
43 class TestORMRowTest extends ORMRowTest {
44
45 /**
46 * @since 1.20
47 * @return string
48 */
49 protected function getRowClass() {
50 return 'TestORMRow';
51 }
52
53 /**
54 * @since 1.20
55 * @return IORMTable
56 */
57 protected function getTableInstance() {
58 return TestORMTable::singleton();
59 }
60
61 protected function setUp() {
62 parent::setUp();
63
64 $dbw = wfGetDB( DB_MASTER );
65
66 $isSqlite = $GLOBALS['wgDBtype'] === 'sqlite';
67
68 $idField = $isSqlite ? 'INTEGER' : 'INT unsigned';
69 $primaryKey = $isSqlite ? 'PRIMARY KEY AUTOINCREMENT' : 'auto_increment PRIMARY KEY';
70
71 $dbw->query(
72 'CREATE TABLE IF NOT EXISTS ' . $dbw->tableName( 'orm_test' ) . '(
73 test_id ' . $idField . ' NOT NULL ' . $primaryKey . ',
74 test_name VARCHAR(255) NOT NULL,
75 test_age TINYINT unsigned NOT NULL,
76 test_height FLOAT NOT NULL,
77 test_awesome TINYINT unsigned NOT NULL,
78 test_stuff BLOB NOT NULL,
79 test_moarstuff BLOB NOT NULL,
80 test_time varbinary(14) NOT NULL
81 );',
82 __METHOD__
83 );
84 }
85
86 protected function tearDown() {
87 $dbw = wfGetDB( DB_MASTER );
88 $dbw->dropTable( 'orm_test', __METHOD__ );
89
90 parent::tearDown();
91 }
92
93 public function constructorTestProvider() {
94 return array(
95 array(
96 array(
97 'name' => 'Foobar',
98 'time' => '20120101020202',
99 'age' => 42,
100 'height' => 9000.1,
101 'awesome' => true,
102 'stuff' => array( 13, 11, 7, 5, 3, 2 ),
103 'moarstuff' => (object)array( 'foo' => 'bar', 'bar' => array( 4, 2 ), 'baz' => true )
104 ),
105 true
106 ),
107 );
108 }
109
110 }
111
112 class TestORMRow extends ORMRow {}
113
114 class TestORMTable extends ORMTable {
115
116 /**
117 * Returns the name of the database table objects of this type are stored in.
118 *
119 * @since 1.20
120 *
121 * @return string
122 */
123 public function getName() {
124 return 'orm_test';
125 }
126
127 /**
128 * Returns the name of a IORMRow implementing class that
129 * represents single rows in this table.
130 *
131 * @since 1.20
132 *
133 * @return string
134 */
135 public function getRowClass() {
136 return 'TestORMRow';
137 }
138
139 /**
140 * Returns an array with the fields and their types this object contains.
141 * This corresponds directly to the fields in the database, without prefix.
142 *
143 * field name => type
144 *
145 * Allowed types:
146 * * id
147 * * str
148 * * int
149 * * float
150 * * bool
151 * * array
152 * * blob
153 *
154 * @since 1.20
155 *
156 * @return array
157 */
158 public function getFields() {
159 return array(
160 'id' => 'id',
161 'name' => 'str',
162 'age' => 'int',
163 'height' => 'float',
164 'awesome' => 'bool',
165 'stuff' => 'array',
166 'moarstuff' => 'blob',
167 'time' => 'str', // TS_MW
168 );
169 }
170
171 /**
172 * Gets the db field prefix.
173 *
174 * @since 1.20
175 *
176 * @return string
177 */
178 protected function getFieldPrefix() {
179 return 'test_';
180 }
181
182
183 }