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