Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / installer / DatabaseUpdaterTest.php
blobabff3e68203228c108d91a11798f266000cb059d
1 <?php
3 class DatabaseUpdaterTest extends MediaWikiTestCase {
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 ) );
19 class FakeDatabase extends DatabaseBase {
20 public $lastInsertTable;
21 public $lastInsertData;
23 function __construct() {
26 function clearFlag( $arg ) {
29 function setFlag( $arg ) {
32 public function insert( $table, $a, $fname = __METHOD__, $options = array() ) {
33 $this->lastInsertTable = $table;
34 $this->lastInsertData = $a;
37 /**
38 * Get the type of the DBMS, as it appears in $wgDBtype.
40 * @return string
42 function getType() {
43 // TODO: Implement getType() method.
46 /**
47 * Open a connection to the database. Usually aborts on failure
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
56 function open( $server, $user, $password, $dbName ) {
57 // TODO: Implement open() method.
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.
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
70 function fetchObject( $res ) {
71 // TODO: Implement fetchObject() method.
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.
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
83 function fetchRow( $res ) {
84 // TODO: Implement fetchRow() method.
87 /**
88 * Get the number of rows in a result object
90 * @param mixed $res A SQL result
91 * @return int
93 function numRows( $res ) {
94 // TODO: Implement numRows() method.
97 /**
98 * Get the number of fields in a result object
99 * @see http://www.php.net/mysql_num_fields
101 * @param mixed $res A SQL result
102 * @return int
104 function numFields( $res ) {
105 // TODO: Implement numFields() method.
109 * Get a field name in a result object
110 * @see http://www.php.net/mysql_field_name
112 * @param mixed $res A SQL result
113 * @param int $n
114 * @return string
116 function fieldName( $res, $n ) {
117 // TODO: Implement fieldName() method.
121 * Get the inserted value of an auto-increment row
123 * The value inserted should be fetched from nextSequenceValue()
125 * Example:
126 * $id = $dbw->nextSequenceValue( 'page_page_id_seq' );
127 * $dbw->insert( 'page', array( 'page_id' => $id ) );
128 * $id = $dbw->insertId();
130 * @return int
132 function insertId() {
133 // TODO: Implement insertId() method.
137 * Change the position of the cursor in a result object
138 * @see http://www.php.net/mysql_data_seek
140 * @param mixed $res A SQL result
141 * @param int $row
143 function dataSeek( $res, $row ) {
144 // TODO: Implement dataSeek() method.
148 * Get the last error number
149 * @see http://www.php.net/mysql_errno
151 * @return int
153 function lastErrno() {
154 // TODO: Implement lastErrno() method.
158 * Get a description of the last error
159 * @see http://www.php.net/mysql_error
161 * @return string
163 function lastError() {
164 // TODO: Implement lastError() method.
168 * mysql_fetch_field() wrapper
169 * Returns false if the field doesn't exist
171 * @param string $table Table name
172 * @param string $field Field name
174 * @return Field
176 function fieldInfo( $table, $field ) {
177 // TODO: Implement fieldInfo() method.
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
187 function indexInfo( $table, $index, $fname = __METHOD__ ) {
188 // TODO: Implement indexInfo() method.
192 * Get the number of rows affected by the last write query
193 * @see http://www.php.net/mysql_affected_rows
195 * @return int
197 function affectedRows() {
198 // TODO: Implement affectedRows() method.
202 * Wrapper for addslashes()
204 * @param string $s String to be slashed.
205 * @return string Slashed string.
207 function strencode( $s ) {
208 // TODO: Implement strencode() method.
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.
217 * @return string Wikitext of a link to the server software's web site
219 function getSoftwareLink() {
220 // TODO: Implement getSoftwareLink() method.
224 * A string describing the current software version, like from
225 * mysql_get_server_info().
227 * @return string Version information from the database server.
229 function getServerVersion() {
230 // TODO: Implement getServerVersion() method.
234 * Closes underlying database connection
235 * @since 1.20
236 * @return bool Whether connection was closed successfully
238 protected function closeConnection() {
239 // TODO: Implement closeConnection() method.
243 * The DBMS-dependent part of query()
245 * @param string $sql SQL query.
246 * @return ResultWrapper|bool Result object to feed to fetchObject,
247 * fetchRow, ...; or false on failure
249 protected function doQuery( $sql ) {
250 // TODO: Implement doQuery() method.
254 class FakeDatabaseUpdater extends DatabaseUpdater {
255 function __construct( $db ) {
256 $this->db = $db;
257 self::$updateCounter = 0;
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)
266 * @return array
268 protected function getCoreUpdateList() {
269 return array();
272 public function canUseNewUpdatelog() {
273 return true;
276 public function setAppliedUpdates( $version, $updates = array() ) {
277 parent::setAppliedUpdates( $version, $updates );