summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/installer/DatabaseUpdaterTest.php
blob: abff3e68203228c108d91a11798f266000cb059d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?php

class DatabaseUpdaterTest extends MediaWikiTestCase {

	public function testSetAppliedUpdates() {
		$db = new FakeDatabase();
		$dbu = new FakeDatabaseUpdater( $db );
		$dbu->setAppliedUpdates( "test", array() );
		$expected = "updatelist-test-" . time() . "0";
		$actual = $db->lastInsertData['ul_key'];
		$this->assertEquals( $expected, $actual, var_export( $db->lastInsertData, true ) );
		$dbu->setAppliedUpdates( "test", array() );
		$expected = "updatelist-test-" . time() . "1";
		$actual = $db->lastInsertData['ul_key'];
		$this->assertEquals( $expected, $actual, var_export( $db->lastInsertData, true ) );
	}
}

class FakeDatabase extends DatabaseBase {
	public $lastInsertTable;
	public $lastInsertData;

	function __construct() {
	}

	function clearFlag( $arg ) {
	}

	function setFlag( $arg ) {
	}

	public function insert( $table, $a, $fname = __METHOD__, $options = array() ) {
		$this->lastInsertTable = $table;
		$this->lastInsertData = $a;
	}

	/**
	 * Get the type of the DBMS, as it appears in $wgDBtype.
	 *
	 * @return string
	 */
	function getType() {
		// TODO: Implement getType() method.
	}

	/**
	 * Open a connection to the database. Usually aborts on failure
	 *
	 * @param string $server Database server host
	 * @param string $user Database user name
	 * @param string $password Database user password
	 * @param string $dbName Database name
	 * @return bool
	 * @throws DBConnectionError
	 */
	function open( $server, $user, $password, $dbName ) {
		// TODO: Implement open() method.
	}

	/**
	 * Fetch the next row from the given result object, in object form.
	 * Fields can be retrieved with $row->fieldname, with fields acting like
	 * member variables.
	 * If no more rows are available, false is returned.
	 *
	 * @param ResultWrapper|stdClass $res Object as returned from DatabaseBase::query(), etc.
	 * @return stdClass|bool
	 * @throws DBUnexpectedError Thrown if the database returns an error
	 */
	function fetchObject( $res ) {
		// TODO: Implement fetchObject() method.
	}

	/**
	 * Fetch the next row from the given result object, in associative array
	 * form. Fields are retrieved with $row['fieldname'].
	 * If no more rows are available, false is returned.
	 *
	 * @param ResultWrapper $res Result object as returned from DatabaseBase::query(), etc.
	 * @return array|bool
	 * @throws DBUnexpectedError Thrown if the database returns an error
	 */
	function fetchRow( $res ) {
		// TODO: Implement fetchRow() method.
	}

	/**
	 * Get the number of rows in a result object
	 *
	 * @param mixed $res A SQL result
	 * @return int
	 */
	function numRows( $res ) {
		// TODO: Implement numRows() method.
	}

	/**
	 * Get the number of fields in a result object
	 * @see http://www.php.net/mysql_num_fields
	 *
	 * @param mixed $res A SQL result
	 * @return int
	 */
	function numFields( $res ) {
		// TODO: Implement numFields() method.
	}

	/**
	 * Get a field name in a result object
	 * @see http://www.php.net/mysql_field_name
	 *
	 * @param mixed $res A SQL result
	 * @param int $n
	 * @return string
	 */
	function fieldName( $res, $n ) {
		// TODO: Implement fieldName() method.
	}

	/**
	 * Get the inserted value of an auto-increment row
	 *
	 * The value inserted should be fetched from nextSequenceValue()
	 *
	 * Example:
	 * $id = $dbw->nextSequenceValue( 'page_page_id_seq' );
	 * $dbw->insert( 'page', array( 'page_id' => $id ) );
	 * $id = $dbw->insertId();
	 *
	 * @return int
	 */
	function insertId() {
		// TODO: Implement insertId() method.
	}

	/**
	 * Change the position of the cursor in a result object
	 * @see http://www.php.net/mysql_data_seek
	 *
	 * @param mixed $res A SQL result
	 * @param int $row
	 */
	function dataSeek( $res, $row ) {
		// TODO: Implement dataSeek() method.
	}

	/**
	 * Get the last error number
	 * @see http://www.php.net/mysql_errno
	 *
	 * @return int
	 */
	function lastErrno() {
		// TODO: Implement lastErrno() method.
	}

	/**
	 * Get a description of the last error
	 * @see http://www.php.net/mysql_error
	 *
	 * @return string
	 */
	function lastError() {
		// TODO: Implement lastError() method.
	}

	/**
	 * mysql_fetch_field() wrapper
	 * Returns false if the field doesn't exist
	 *
	 * @param string $table Table name
	 * @param string $field Field name
	 *
	 * @return Field
	 */
	function fieldInfo( $table, $field ) {
		// TODO: Implement fieldInfo() method.
	}

	/**
	 * Get information about an index into an object
	 * @param string $table Table name
	 * @param string $index Index name
	 * @param string $fname Calling function name
	 * @return mixed Database-specific index description class or false if the index does not exist
	 */
	function indexInfo( $table, $index, $fname = __METHOD__ ) {
		// TODO: Implement indexInfo() method.
	}

	/**
	 * Get the number of rows affected by the last write query
	 * @see http://www.php.net/mysql_affected_rows
	 *
	 * @return int
	 */
	function affectedRows() {
		// TODO: Implement affectedRows() method.
	}

	/**
	 * Wrapper for addslashes()
	 *
	 * @param string $s String to be slashed.
	 * @return string Slashed string.
	 */
	function strencode( $s ) {
		// TODO: Implement strencode() method.
	}

	/**
	 * Returns a wikitext link to the DB's website, e.g.,
	 *   return "[http://www.mysql.com/ MySQL]";
	 * Should at least contain plain text, if for some reason
	 * your database has no website.
	 *
	 * @return string Wikitext of a link to the server software's web site
	 */
	function getSoftwareLink() {
		// TODO: Implement getSoftwareLink() method.
	}

	/**
	 * A string describing the current software version, like from
	 * mysql_get_server_info().
	 *
	 * @return string Version information from the database server.
	 */
	function getServerVersion() {
		// TODO: Implement getServerVersion() method.
	}

	/**
	 * Closes underlying database connection
	 * @since 1.20
	 * @return bool Whether connection was closed successfully
	 */
	protected function closeConnection() {
		// TODO: Implement closeConnection() method.
	}

	/**
	 * The DBMS-dependent part of query()
	 *
	 * @param string $sql SQL query.
	 * @return ResultWrapper|bool Result object to feed to fetchObject,
	 *   fetchRow, ...; or false on failure
	 */
	protected function doQuery( $sql ) {
		// TODO: Implement doQuery() method.
	}
}

class FakeDatabaseUpdater extends DatabaseUpdater {
	function __construct( $db ) {
		$this->db = $db;
		self::$updateCounter = 0;
	}

	/**
	 * Get an array of updates to perform on the database. Should return a
	 * multi-dimensional array. The main key is the MediaWiki version (1.12,
	 * 1.13...) with the values being arrays of updates, identical to how
	 * updaters.inc did it (for now)
	 *
	 * @return array
	 */
	protected function getCoreUpdateList() {
		return array();
	}

	public function canUseNewUpdatelog() {
		return true;
	}

	public function setAppliedUpdates( $version, $updates = array() ) {
		parent::setAppliedUpdates( $version, $updates );
	}
}