Merge "API: HTMLize and internationalize the help, add Special:ApiHelp"
[lhc/web/wiklou.git] / tests / phpunit / includes / installer / DatabaseUpdaterTest.php
1 <?php
2
3 class DatabaseUpdaterTest extends MediaWikiTestCase {
4
5 public function testSetAppliedUpdates() {
6 $db = new FakeDatabase();
7 $dbu = new FakeDatabaseUpdater( $db );
8 $dbu->setAppliedUpdates( "test", array() );
9 $expected = "updatelist-test-" . time() . "0";
10 $actual = $db->lastInsertData['ul_key'];
11 $this->assertEquals( $expected, $actual, var_export( $db->lastInsertData, true ) );
12 $dbu->setAppliedUpdates( "test", array() );
13 $expected = "updatelist-test-" . time() . "1";
14 $actual = $db->lastInsertData['ul_key'];
15 $this->assertEquals( $expected, $actual, var_export( $db->lastInsertData, true ) );
16 }
17 }
18
19 class FakeDatabase extends DatabaseBase {
20 public $lastInsertTable;
21 public $lastInsertData;
22
23 function __construct() {
24 }
25
26 function clearFlag( $arg ) {
27 }
28
29 function setFlag( $arg ) {
30 }
31
32 public function insert( $table, $a, $fname = __METHOD__, $options = array() ) {
33 $this->lastInsertTable = $table;
34 $this->lastInsertData = $a;
35 }
36
37 /**
38 * Get the type of the DBMS, as it appears in $wgDBtype.
39 *
40 * @return string
41 */
42 function getType() {
43 // TODO: Implement getType() method.
44 }
45
46 /**
47 * Open a connection to the database. Usually aborts on failure
48 *
49 * @param string $server Database server host
50 * @param string $user Database user name
51 * @param string $password Database user password
52 * @param string $dbName Database name
53 * @return bool
54 * @throws DBConnectionError
55 */
56 function open( $server, $user, $password, $dbName ) {
57 // TODO: Implement open() method.
58 }
59
60 /**
61 * Fetch the next row from the given result object, in object form.
62 * Fields can be retrieved with $row->fieldname, with fields acting like
63 * member variables.
64 * If no more rows are available, false is returned.
65 *
66 * @param ResultWrapper|stdClass $res Object as returned from DatabaseBase::query(), etc.
67 * @return stdClass|bool
68 * @throws DBUnexpectedError Thrown if the database returns an error
69 */
70 function fetchObject( $res ) {
71 // TODO: Implement fetchObject() method.
72 }
73
74 /**
75 * Fetch the next row from the given result object, in associative array
76 * form. Fields are retrieved with $row['fieldname'].
77 * If no more rows are available, false is returned.
78 *
79 * @param ResultWrapper $res Result object as returned from DatabaseBase::query(), etc.
80 * @return array|bool
81 * @throws DBUnexpectedError Thrown if the database returns an error
82 */
83 function fetchRow( $res ) {
84 // TODO: Implement fetchRow() method.
85 }
86
87 /**
88 * Get the number of rows in a result object
89 *
90 * @param mixed $res A SQL result
91 * @return int
92 */
93 function numRows( $res ) {
94 // TODO: Implement numRows() method.
95 }
96
97 /**
98 * Get the number of fields in a result object
99 * @see http://www.php.net/mysql_num_fields
100 *
101 * @param mixed $res A SQL result
102 * @return int
103 */
104 function numFields( $res ) {
105 // TODO: Implement numFields() method.
106 }
107
108 /**
109 * Get a field name in a result object
110 * @see http://www.php.net/mysql_field_name
111 *
112 * @param mixed $res A SQL result
113 * @param int $n
114 * @return string
115 */
116 function fieldName( $res, $n ) {
117 // TODO: Implement fieldName() method.
118 }
119
120 /**
121 * Get the inserted value of an auto-increment row
122 *
123 * The value inserted should be fetched from nextSequenceValue()
124 *
125 * Example:
126 * $id = $dbw->nextSequenceValue( 'page_page_id_seq' );
127 * $dbw->insert( 'page', array( 'page_id' => $id ) );
128 * $id = $dbw->insertId();
129 *
130 * @return int
131 */
132 function insertId() {
133 // TODO: Implement insertId() method.
134 }
135
136 /**
137 * Change the position of the cursor in a result object
138 * @see http://www.php.net/mysql_data_seek
139 *
140 * @param mixed $res A SQL result
141 * @param int $row
142 */
143 function dataSeek( $res, $row ) {
144 // TODO: Implement dataSeek() method.
145 }
146
147 /**
148 * Get the last error number
149 * @see http://www.php.net/mysql_errno
150 *
151 * @return int
152 */
153 function lastErrno() {
154 // TODO: Implement lastErrno() method.
155 }
156
157 /**
158 * Get a description of the last error
159 * @see http://www.php.net/mysql_error
160 *
161 * @return string
162 */
163 function lastError() {
164 // TODO: Implement lastError() method.
165 }
166
167 /**
168 * mysql_fetch_field() wrapper
169 * Returns false if the field doesn't exist
170 *
171 * @param string $table Table name
172 * @param string $field Field name
173 *
174 * @return Field
175 */
176 function fieldInfo( $table, $field ) {
177 // TODO: Implement fieldInfo() method.
178 }
179
180 /**
181 * Get information about an index into an object
182 * @param string $table Table name
183 * @param string $index Index name
184 * @param string $fname Calling function name
185 * @return mixed Database-specific index description class or false if the index does not exist
186 */
187 function indexInfo( $table, $index, $fname = __METHOD__ ) {
188 // TODO: Implement indexInfo() method.
189 }
190
191 /**
192 * Get the number of rows affected by the last write query
193 * @see http://www.php.net/mysql_affected_rows
194 *
195 * @return int
196 */
197 function affectedRows() {
198 // TODO: Implement affectedRows() method.
199 }
200
201 /**
202 * Wrapper for addslashes()
203 *
204 * @param string $s String to be slashed.
205 * @return string Slashed string.
206 */
207 function strencode( $s ) {
208 // TODO: Implement strencode() method.
209 }
210
211 /**
212 * Returns a wikitext link to the DB's website, e.g.,
213 * return "[http://www.mysql.com/ MySQL]";
214 * Should at least contain plain text, if for some reason
215 * your database has no website.
216 *
217 * @return string Wikitext of a link to the server software's web site
218 */
219 function getSoftwareLink() {
220 // TODO: Implement getSoftwareLink() method.
221 }
222
223 /**
224 * A string describing the current software version, like from
225 * mysql_get_server_info().
226 *
227 * @return string Version information from the database server.
228 */
229 function getServerVersion() {
230 // TODO: Implement getServerVersion() method.
231 }
232
233 /**
234 * Closes underlying database connection
235 * @since 1.20
236 * @return bool Whether connection was closed successfully
237 */
238 protected function closeConnection() {
239 // TODO: Implement closeConnection() method.
240 }
241
242 /**
243 * The DBMS-dependent part of query()
244 *
245 * @param string $sql SQL query.
246 * @return ResultWrapper|bool Result object to feed to fetchObject,
247 * fetchRow, ...; or false on failure
248 */
249 protected function doQuery( $sql ) {
250 // TODO: Implement doQuery() method.
251 }
252 }
253
254 class FakeDatabaseUpdater extends DatabaseUpdater {
255 function __construct( $db ) {
256 $this->db = $db;
257 self::$updateCounter = 0;
258 }
259
260 /**
261 * Get an array of updates to perform on the database. Should return a
262 * multi-dimensional array. The main key is the MediaWiki version (1.12,
263 * 1.13...) with the values being arrays of updates, identical to how
264 * updaters.inc did it (for now)
265 *
266 * @return array
267 */
268 protected function getCoreUpdateList() {
269 return array();
270 }
271
272 public function canUseNewUpdatelog() {
273 return true;
274 }
275
276 public function setAppliedUpdates( $version, $updates = array() ) {
277 parent::setAppliedUpdates( $version, $updates );
278 }
279 }