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