3 class DatabaseUpdaterTest
extends MediaWikiTestCase
{
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 ) );
19 class FakeDatabase
extends DatabaseBase
{
20 public $lastInsertTable;
21 public $lastInsertData;
23 function __construct() {
24 $this->currentDomain
= DatabaseDomain
::newUnspecified();
27 function clearFlag( $arg, $remember = self
::REMEMBER_NOTHING
) {
30 function setFlag( $arg, $remember = self
::REMEMBER_NOTHING
) {
33 public function insert( $table, $a, $fname = __METHOD__
, $options = [] ) {
34 $this->lastInsertTable
= $table;
35 $this->lastInsertData
= $a;
39 * Get the type of the DBMS, as it appears in $wgDBtype.
44 // TODO: Implement getType() method.
48 * Open a connection to the database. Usually aborts on failure
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
55 * @throws DBConnectionError
57 function open( $server, $user, $password, $dbName ) {
58 // TODO: Implement open() method.
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
65 * If no more rows are available, false is returned.
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
71 function fetchObject( $res ) {
72 // TODO: Implement fetchObject() method.
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.
80 * @param ResultWrapper $res Result object as returned from DatabaseBase::query(), etc.
82 * @throws DBUnexpectedError Thrown if the database returns an error
84 function fetchRow( $res ) {
85 // TODO: Implement fetchRow() method.
89 * Get the number of rows in a result object
91 * @param mixed $res A SQL result
94 function numRows( $res ) {
95 // TODO: Implement numRows() method.
99 * Get the number of fields in a result object
100 * @see http://www.php.net/mysql_num_fields
102 * @param mixed $res A SQL result
105 function numFields( $res ) {
106 // TODO: Implement numFields() method.
110 * Get a field name in a result object
111 * @see http://www.php.net/mysql_field_name
113 * @param mixed $res A SQL result
117 function fieldName( $res, $n ) {
118 // TODO: Implement fieldName() method.
122 * Get the inserted value of an auto-increment row
124 * The value inserted should be fetched from nextSequenceValue()
127 * $id = $dbw->nextSequenceValue( 'page_page_id_seq' );
128 * $dbw->insert( 'page', [ 'page_id' => $id ] );
129 * $id = $dbw->insertId();
133 function insertId() {
134 // TODO: Implement insertId() method.
138 * Change the position of the cursor in a result object
139 * @see http://www.php.net/mysql_data_seek
141 * @param mixed $res A SQL result
144 function dataSeek( $res, $row ) {
145 // TODO: Implement dataSeek() method.
149 * Get the last error number
150 * @see http://www.php.net/mysql_errno
154 function lastErrno() {
155 // TODO: Implement lastErrno() method.
159 * Get a description of the last error
160 * @see http://www.php.net/mysql_error
164 function lastError() {
165 // TODO: Implement lastError() method.
169 * mysql_fetch_field() wrapper
170 * Returns false if the field doesn't exist
172 * @param string $table Table name
173 * @param string $field Field name
177 function fieldInfo( $table, $field ) {
178 // TODO: Implement fieldInfo() method.
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
188 function indexInfo( $table, $index, $fname = __METHOD__
) {
189 // TODO: Implement indexInfo() method.
193 * Get the number of rows affected by the last write query
194 * @see http://www.php.net/mysql_affected_rows
198 function affectedRows() {
199 // TODO: Implement affectedRows() method.
203 * Wrapper for addslashes()
205 * @param string $s String to be slashed.
206 * @return string Slashed string.
208 function strencode( $s ) {
209 // TODO: Implement strencode() method.
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.
218 * @return string Wikitext of a link to the server software's web site
220 function getSoftwareLink() {
221 // TODO: Implement getSoftwareLink() method.
225 * A string describing the current software version, like from
226 * mysql_get_server_info().
228 * @return string Version information from the database server.
230 function getServerVersion() {
231 // TODO: Implement getServerVersion() method.
235 * Closes underlying database connection
237 * @return bool Whether connection was closed successfully
239 protected function closeConnection() {
240 // TODO: Implement closeConnection() method.
244 * The DBMS-dependent part of query()
246 * @param string $sql SQL query.
247 * @return ResultWrapper|bool Result object to feed to fetchObject,
248 * fetchRow, ...; or false on failure
250 protected function doQuery( $sql ) {
251 // TODO: Implement doQuery() method.
255 class FakeDatabaseUpdater
extends DatabaseUpdater
{
256 function __construct( $db ) {
258 self
::$updateCounter = 0;
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)
269 protected function getCoreUpdateList() {
273 public function canUseNewUpdatelog() {
277 public function setAppliedUpdates( $version, $updates = [] ) {
278 parent
::setAppliedUpdates( $version, $updates );