MediaWiki  1.23.8
DatabaseMysqlBaseTest.php
Go to the documentation of this file.
1 <?php
33  // From DatabaseBase
34  function __construct() {}
35  protected function closeConnection() {}
36  protected function doQuery( $sql ) {}
37 
38  // From DatabaseMysql
39  protected function mysqlConnect( $realServer ) {}
40  protected function mysqlSetCharset( $charset ) {}
41  protected function mysqlFreeResult( $res ) {}
42  protected function mysqlFetchObject( $res ) {}
43  protected function mysqlFetchArray( $res ) {}
44  protected function mysqlNumRows( $res ) {}
45  protected function mysqlNumFields( $res ) {}
46  protected function mysqlFieldName( $res, $n ) {}
47  protected function mysqlFieldType( $res, $n ) {}
48  protected function mysqlDataSeek( $res, $row ) {}
49  protected function mysqlError( $conn = null ) {}
50  protected function mysqlFetchField( $res, $n ) {}
51  protected function mysqlPing() {}
52 
53  // From interface DatabaseType
54  function insertId() {}
55  function lastErrno() {}
56  function affectedRows() {}
57  function getServerVersion() {}
58 }
59 
61 
66  public function testAddIdentifierQuotes( $expected, $in ) {
67  $db = new FakeDatabaseMysqlBase();
68  $quoted = $db->addIdentifierQuotes( $in );
69  $this->assertEquals( $expected, $quoted );
70  }
71 
77  function provideDiapers() {
78  return array(
79  // Format: expected, input
80  array( '``', '' ),
81 
82  // Yeah I really hate loosely typed PHP idiocies nowadays
83  array( '``', null ),
84 
85  // Dear codereviewer, guess what addIdentifierQuotes()
86  // will return with thoses:
87  array( '``', false ),
88  array( '`1`', true ),
89 
90  // We never know what could happen
91  array( '`0`', 0 ),
92  array( '`1`', 1 ),
93 
94  // Whatchout! Should probably use something more meaningful
95  array( "`'`", "'" ), # single quote
96  array( '`"`', '"' ), # double quote
97  array( '````', '`' ), # backtick
98  array( '`’`', '’' ), # apostrophe (look at your encyclopedia)
99 
100  // sneaky NUL bytes are lurking everywhere
101  array( '``', "\0" ),
102  array( '`xyzzy`', "\0x\0y\0z\0z\0y\0" ),
103 
104  // unicode chars
105  array(
106  self::createUnicodeString( '`\u0001a\uFFFFb`' ),
107  self::createUnicodeString( '\u0001a\uFFFFb' )
108  ),
109  array(
110  self::createUnicodeString( '`\u0001\uFFFF`' ),
111  self::createUnicodeString( '\u0001\u0000\uFFFF\u0000' )
112  ),
113  array( '`☃`', '☃' ),
114  array( '`メインページ`', 'メインページ' ),
115  array( '`Басты_бет`', 'Басты_бет' ),
116 
117  // Real world:
118  array( '`Alix`', 'Alix' ), # while( ! $recovered ) { sleep(); }
119  array( '`Backtick: ```', 'Backtick: `' ),
120  array( '`This is a test`', 'This is a test' ),
121  );
122  }
123 
124  private static function createUnicodeString( $str ) {
125  return json_decode( '"' . $str . '"' );
126  }
127 
128  function getMockForViews() {
129  $db = $this->getMockBuilder( 'DatabaseMysql' )
130  ->disableOriginalConstructor()
131  ->setMethods( array( 'fetchRow', 'query' ) )
132  ->getMock();
133 
134  $db->expects( $this->any() )
135  ->method( 'query' )
136  ->with( $this->anything() )
137  ->will(
138  $this->returnValue( null )
139  );
140 
141  $db->expects( $this->any() )
142  ->method( 'fetchRow' )
143  ->with( $this->anything() )
144  ->will( $this->onConsecutiveCalls(
145  array( 'Tables_in_' => 'view1' ),
146  array( 'Tables_in_' => 'view2' ),
147  array( 'Tables_in_' => 'myview' ),
148  false # no more rows
149  ));
150  return $db;
151  }
155  function testListviews() {
156  $db = $this->getMockForViews();
157 
158  // The first call populate an internal cache of views
159  $this->assertEquals( array( 'view1', 'view2', 'myview' ),
160  $db->listViews() );
161  $this->assertEquals( array( 'view1', 'view2', 'myview' ),
162  $db->listViews() );
163 
164  // Prefix filtering
165  $this->assertEquals( array( 'view1', 'view2' ),
166  $db->listViews( 'view' ) );
167  $this->assertEquals( array( 'myview' ),
168  $db->listViews( 'my' ) );
169  $this->assertEquals( array(),
170  $db->listViews( 'UNUSED_PREFIX' ) );
171  $this->assertEquals( array( 'view1', 'view2', 'myview' ),
172  $db->listViews( '' ) );
173  }
174 
179  function testIsView( $isView, $viewName ) {
180  $db = $this->getMockForViews();
181 
182  switch ( $isView ) {
183  case true:
184  $this->assertTrue( $db->isView( $viewName ),
185  "$viewName should be considered a view" );
186  break;
187 
188  case false:
189  $this->assertFalse( $db->isView( $viewName ),
190  "$viewName has not been defined as a view" );
191  break;
192  }
193 
194  }
195 
197  return array(
198  // format: whether it is a view, view name
199  array( true, 'view1' ),
200  array( true, 'view2' ),
201  array( true, 'myview' ),
202 
203  array( false, 'user' ),
204 
205  array( false, 'view10' ),
206  array( false, 'my' ),
207  array( false, 'OH_MY_GOD' ), # they killed kenny!
208  );
209  }
210 
211 }
FakeDatabaseMysqlBase\mysqlDataSeek
mysqlDataSeek( $res, $row)
Move internal result pointer.
Definition: DatabaseMysqlBaseTest.php:48
DatabaseMysqlBase
Database abstraction object for MySQL.
Definition: DatabaseMysqlBase.php:32
FakeDatabaseMysqlBase\closeConnection
closeConnection()
Closes underlying database connection.
Definition: DatabaseMysqlBaseTest.php:35
DatabaseMysqlBaseTest\getMockForViews
getMockForViews()
Definition: DatabaseMysqlBaseTest.php:128
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
FakeDatabaseMysqlBase\mysqlFetchObject
mysqlFetchObject( $res)
Fetch a result row as an object.
Definition: DatabaseMysqlBaseTest.php:42
FakeDatabaseMysqlBase\__construct
__construct()
Definition: DatabaseMysqlBaseTest.php:34
DatabaseMysqlBaseTest\provideDiapers
provideDiapers()
Feeds testAddIdentifierQuotes.
Definition: DatabaseMysqlBaseTest.php:77
$n
$n
Definition: RandomTest.php:76
FakeDatabaseMysqlBase\affectedRows
affectedRows()
Get the number of rows affected by the last write query.
Definition: DatabaseMysqlBaseTest.php:56
anything
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same so they can t rely on Unix and must forbid reads to even standard directories like tmp lest users read each others files We cannot assume that the user has the ability to install or run any programs not written as web accessible PHP scripts Since anything that works on cheap shared hosting will work if you have shell or root access MediaWiki s design is based around catering to the lowest common denominator Although we support higher end setups as the way many things work by default is tailored toward shared hosting These defaults are unconventional from the point of view of and they certainly aren t ideal for someone who s installing MediaWiki as MediaWiki does not conform to normal Unix filesystem layout Hopefully we ll offer direct support for standard layouts in the but for now *any change to the location of files is unsupported *Moving things and leaving symlinks will *probably *not break anything
Definition: distributors.txt:39
FakeDatabaseMysqlBase\mysqlFetchField
mysqlFetchField( $res, $n)
Get column information from a result.
Definition: DatabaseMysqlBaseTest.php:50
DatabaseMysqlBaseTest
Definition: DatabaseMysqlBaseTest.php:60
$in
$in
Definition: Utf8Test.php:42
FakeDatabaseMysqlBase\mysqlFieldType
mysqlFieldType( $res, $n)
Get the type of the specified field in a result.
Definition: DatabaseMysqlBaseTest.php:47
FakeDatabaseMysqlBase\mysqlConnect
mysqlConnect( $realServer)
Open a connection to a MySQL server.
Definition: DatabaseMysqlBaseTest.php:39
FakeDatabaseMysqlBase\mysqlNumFields
mysqlNumFields( $res)
Get number of fields in result.
Definition: DatabaseMysqlBaseTest.php:45
DatabaseBase\isView
isView( $name)
Differentiates between a TABLE and a VIEW.
Definition: Database.php:3592
FakeDatabaseMysqlBase\mysqlError
mysqlError( $conn=null)
Returns the text of the error message from previous MySQL operation.
Definition: DatabaseMysqlBaseTest.php:49
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
FakeDatabaseMysqlBase\getServerVersion
getServerVersion()
A string describing the current software version, like from mysql_get_server_info().
Definition: DatabaseMysqlBaseTest.php:57
FakeDatabaseMysqlBase
Fake class around abstract class so we can call concrete methods.
Definition: DatabaseMysqlBaseTest.php:32
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
FakeDatabaseMysqlBase\mysqlFieldName
mysqlFieldName( $res, $n)
Get the name of the specified field in a result.
Definition: DatabaseMysqlBaseTest.php:46
MediaWikiTestCase\$db
DatabaseBase $db
Definition: MediaWikiTestCase.php:31
DatabaseMysqlBaseTest\provideViewExistanceChecks
provideViewExistanceChecks()
Definition: DatabaseMysqlBaseTest.php:196
FakeDatabaseMysqlBase\mysqlNumRows
mysqlNumRows( $res)
Get number of rows in result.
Definition: DatabaseMysqlBaseTest.php:44
FakeDatabaseMysqlBase\lastErrno
lastErrno()
Get the last error number.
Definition: DatabaseMysqlBaseTest.php:55
DatabaseBase\addIdentifierQuotes
addIdentifierQuotes( $s)
Quotes an identifier using backticks or "double quotes" depending on the database type.
Definition: Database.php:2498
DatabaseMysqlBaseTest\testIsView
testIsView( $isView, $viewName)
@covers DatabaseMysqlBase::isView @dataProvider provideViewExistanceChecks
Definition: DatabaseMysqlBaseTest.php:179
DatabaseBase\listViews
listViews( $prefix=null, $fname=__METHOD__)
Lists all the VIEWs in the database.
Definition: Database.php:3581
FakeDatabaseMysqlBase\mysqlFreeResult
mysqlFreeResult( $res)
Free result memory.
Definition: DatabaseMysqlBaseTest.php:41
FakeDatabaseMysqlBase\insertId
insertId()
Get the inserted value of an auto-increment row.
Definition: DatabaseMysqlBaseTest.php:54
DatabaseMysqlBaseTest\createUnicodeString
static createUnicodeString( $str)
Definition: DatabaseMysqlBaseTest.php:124
FakeDatabaseMysqlBase\mysqlPing
mysqlPing()
Ping a server connection or reconnect if there is no connection.
Definition: DatabaseMysqlBaseTest.php:51
FakeDatabaseMysqlBase\mysqlSetCharset
mysqlSetCharset( $charset)
Set the character set of the MySQL link.
Definition: DatabaseMysqlBaseTest.php:40
$res
$res
Definition: database.txt:21
DatabaseMysqlBaseTest\testListviews
testListviews()
@covers DatabaseMysqlBase::listViews
Definition: DatabaseMysqlBaseTest.php:155
FakeDatabaseMysqlBase\doQuery
doQuery( $sql)
The DBMS-dependent part of query()
Definition: DatabaseMysqlBaseTest.php:36
DatabaseMysqlBaseTest\testAddIdentifierQuotes
testAddIdentifierQuotes( $expected, $in)
@dataProvider provideDiapers @covers DatabaseMysqlBase::addIdentifierQuotes
Definition: DatabaseMysqlBaseTest.php:66
FakeDatabaseMysqlBase\mysqlFetchArray
mysqlFetchArray( $res)
Fetch a result row as an associative and numeric array.
Definition: DatabaseMysqlBaseTest.php:43