3 * Holds tests for DatabaseMysqlBase MediaWiki class.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
22 * @author Antoine Musso
24 * @copyright © 2013 Antoine Musso
25 * @copyright © 2013 Bryan Davis
26 * @copyright © 2013 Wikimedia Foundation Inc.
30 * Fake class around abstract class so we can call concrete methods.
32 class FakeDatabaseMysqlBase
extends DatabaseMysqlBase
{
34 protected function closeConnection() {}
35 protected function doQuery( $sql ) {}
38 protected function mysqlConnect( $realServer ) {}
39 protected function mysqlFreeResult( $res ) {}
40 protected function mysqlFetchObject( $res ) {}
41 protected function mysqlFetchArray( $res ) {}
42 protected function mysqlNumRows( $res ) {}
43 protected function mysqlNumFields( $res ) {}
44 protected function mysqlFieldName( $res, $n ) {}
45 protected function mysqlDataSeek( $res, $row ) {}
46 protected function mysqlError( $conn = null ) {}
47 protected function mysqlFetchField( $res, $n ) {}
48 protected function mysqlPing() {}
50 // From interface DatabaseType
51 function insertId() {}
52 function lastErrno() {}
53 function affectedRows() {}
54 function getServerVersion() {}
57 class DatabaseMysqlBaseTest
extends MediaWikiTestCase
{
60 * @dataProvider provideDiapers
61 * @covers DatabaseMysqlBase::addIdentifierQuotes
63 function testAddIdentifierQuotes( $expected, $in ) {
64 $db = new FakeDatabaseMysqlBase();
65 $quoted = $db->addIdentifierQuotes( $in );
66 $this->assertEquals($expected, $quoted);
71 * Feeds testAddIdentifierQuotes
73 * Named per bug 20281 convention.
75 function provideDiapers() {
77 // Format: expected, input
80 // Yeah I really hate loosely typed PHP idiocies nowadays
83 // Dear codereviewer, guess what addIdentifierQuotes()
84 // will return with thoses:
88 // We never know what could happen
92 // Whatchout! Should probably use something more meaningful
93 array( "`'`", "'" ), # single quote
94 array( '`"`', '"' ), # double quote
95 array( '````', '`' ), # backtick
96 array( '`’`', '’' ), # apostrophe (look at your encyclopedia)
98 // sneaky NUL bytes are lurking everywhere
100 array( '`xyzzy`', "\0x\0y\0z\0z\0y\0" ),
104 self
::createUnicodeString( '`\u0001a\uFFFFb`' ),
105 self
::createUnicodeString( '\u0001a\uFFFFb' )
108 self
::createUnicodeString( '`\u0001\uFFFF`' ),
109 self
::createUnicodeString( '\u0001\u0000\uFFFF\u0000' )
112 array( '`メインページ`', 'メインページ' ),
113 array( '`Басты_бет`', 'Басты_бет' ),
116 array( '`Alix`', 'Alix' ), # while( ! $recovered ) { sleep(); }
117 array( '`Backtick: ```', 'Backtick: `' ),
118 array( '`This is a test`', 'This is a test' ),
122 private static function createUnicodeString($str) {
123 return json_decode( '"' . $str . '"' );