MediaWiki  1.23.2
DatabaseTestHelper.php
Go to the documentation of this file.
1 <?php
2 
8 
13  protected $testName = array();
14 
20  protected $lastSqls = array();
21 
26  protected $tablesExists;
27 
28  public function __construct( $testName ) {
29  $this->testName = $testName;
30  }
31 
36  public function getLastSqls() {
37  $lastSqls = implode( '; ', $this->lastSqls );
38  $this->lastSqls = array();
39 
40  return $lastSqls;
41  }
42 
43  public function setExistingTables( $tablesExists ) {
44  $this->tablesExists = (array)$tablesExists;
45  }
46 
47  protected function addSql( $sql ) {
48  // clean up spaces before and after some words and the whole string
49  $this->lastSqls[] = trim( preg_replace(
50  '/\s{2,}(?=FROM|WHERE|GROUP BY|ORDER BY|LIMIT)|(?<=SELECT|INSERT|UPDATE)\s{2,}/',
51  ' ', $sql
52  ) );
53  }
54 
55  protected function checkFunctionName( $fname ) {
56  if ( substr( $fname, 0, strlen( $this->testName ) ) !== $this->testName ) {
57  throw new MWException( 'function name does not start with test class. ' .
58  $fname . ' vs. ' . $this->testName . '. ' .
59  'Please provide __METHOD__ to database methods.' );
60  }
61  }
62 
63  function strencode( $s ) {
64  // Choose apos to avoid handling of escaping double quotes in quoted text
65  return str_replace( "'", "\'", $s );
66  }
67 
68  public function addIdentifierQuotes( $s ) {
69  // no escaping to avoid handling of double quotes in quoted text
70  return $s;
71  }
72 
73  public function query( $sql, $fname = '', $tempIgnore = false ) {
74  $this->checkFunctionName( $fname );
75  $this->addSql( $sql );
76 
77  return parent::query( $sql, $fname, $tempIgnore );
78  }
79 
80  public function tableExists( $table, $fname = __METHOD__ ) {
81  $this->checkFunctionName( $fname );
82 
83  return in_array( $table, (array)$this->tablesExists );
84  }
85 
86  // Redeclare parent method to make it public
87  public function nativeReplace( $table, $rows, $fname ) {
88  return parent::nativeReplace( $table, $rows, $fname );
89  }
90 
91  function getType() {
92  return 'test';
93  }
94 
95  function open( $server, $user, $password, $dbName ) {
96  return false;
97  }
98 
99  function fetchObject( $res ) {
100  return false;
101  }
102 
103  function fetchRow( $res ) {
104  return false;
105  }
106 
107  function numRows( $res ) {
108  return -1;
109  }
110 
111  function numFields( $res ) {
112  return -1;
113  }
114 
115  function fieldName( $res, $n ) {
116  return 'test';
117  }
118 
119  function insertId() {
120  return -1;
121  }
122 
123  function dataSeek( $res, $row ) {
124  /* nop */
125  }
126 
127  function lastErrno() {
128  return -1;
129  }
130 
131  function lastError() {
132  return 'test';
133  }
134 
135  function fieldInfo( $table, $field ) {
136  return false;
137  }
138 
139  function indexInfo( $table, $index, $fname = 'Database::indexInfo' ) {
140  return false;
141  }
142 
143  function affectedRows() {
144  return -1;
145  }
146 
147  function getSoftwareLink() {
148  return 'test';
149  }
150 
151  function getServerVersion() {
152  return 'test';
153  }
154 
155  function getServerInfo() {
156  return 'test';
157  }
158 
159  protected function closeConnection() {
160  return false;
161  }
162 
163  protected function doQuery( $sql ) {
164  return array();
165  }
166 }
DatabaseTestHelper\$testName
$testName
CLASS of the test suite, used to determine, if the function name is passed every time to query()
Definition: DatabaseTestHelper.php:13
DatabaseTestHelper\getType
getType()
Get the type of the DBMS, as it appears in $wgDBtype.
Definition: DatabaseTestHelper.php:91
query
For a write query
Definition: database.txt:26
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
DatabaseTestHelper\numFields
numFields( $res)
Get the number of fields in a result object.
Definition: DatabaseTestHelper.php:111
DatabaseTestHelper\fieldInfo
fieldInfo( $table, $field)
mysql_fetch_field() wrapper Returns false if the field doesn't exist
Definition: DatabaseTestHelper.php:135
DatabaseTestHelper\getLastSqls
getLastSqls()
Returns SQL queries grouped by '; ' Clear the list of queries that have been done so far.
Definition: DatabaseTestHelper.php:36
$n
$n
Definition: RandomTest.php:76
$fname
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition: Setup.php:35
$s
$s
Definition: mergeMessageFileList.php:156
DatabaseTestHelper\doQuery
doQuery( $sql)
The DBMS-dependent part of query()
Definition: DatabaseTestHelper.php:163
DatabaseTestHelper\__construct
__construct( $testName)
Constructor.
Definition: DatabaseTestHelper.php:28
DatabaseTestHelper\nativeReplace
nativeReplace( $table, $rows, $fname)
REPLACE query wrapper for MySQL and SQLite, which have a native REPLACE statement.
Definition: DatabaseTestHelper.php:87
DatabaseTestHelper\fetchRow
fetchRow( $res)
Fetch the next row from the given result object, in associative array form.
Definition: DatabaseTestHelper.php:103
DatabaseTestHelper\tableExists
tableExists( $table, $fname=__METHOD__)
Query whether a given table exists.
Definition: DatabaseTestHelper.php:80
DatabaseTestHelper\getSoftwareLink
getSoftwareLink()
Returns a wikitext link to the DB's website, e.g., return "[http://www.mysql.com/ MySQL]"; Should at ...
Definition: DatabaseTestHelper.php:147
MWException
MediaWiki exception.
Definition: MWException.php:26
DatabaseTestHelper\strencode
strencode( $s)
Wrapper for addslashes()
Definition: DatabaseTestHelper.php:63
DatabaseTestHelper\lastError
lastError()
Get a description of the last error.
Definition: DatabaseTestHelper.php:131
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
DatabaseTestHelper\$tablesExists
$tablesExists
Array of tables to be considered as existing by tableExist() Use setExistingTables() to alter.
Definition: DatabaseTestHelper.php:26
DatabaseTestHelper\setExistingTables
setExistingTables( $tablesExists)
Definition: DatabaseTestHelper.php:43
DatabaseTestHelper\query
query( $sql, $fname='', $tempIgnore=false)
Run an SQL query and return the result.
Definition: DatabaseTestHelper.php:73
DatabaseTestHelper\numRows
numRows( $res)
Get the number of rows in a result object.
Definition: DatabaseTestHelper.php:107
DatabaseTestHelper\getServerInfo
getServerInfo()
A string describing the current software version, and possibly other details in a user-friendly way.
Definition: DatabaseTestHelper.php:155
DatabaseTestHelper\getServerVersion
getServerVersion()
A string describing the current software version, like from mysql_get_server_info().
Definition: DatabaseTestHelper.php:151
DatabaseTestHelper\addIdentifierQuotes
addIdentifierQuotes( $s)
Quotes an identifier using backticks or "double quotes" depending on the database type.
Definition: DatabaseTestHelper.php:68
DatabaseBase
Database abstraction object.
Definition: Database.php:219
DatabaseTestHelper\insertId
insertId()
Get the inserted value of an auto-increment row.
Definition: DatabaseTestHelper.php:119
DatabaseTestHelper\checkFunctionName
checkFunctionName( $fname)
Definition: DatabaseTestHelper.php:55
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
DatabaseTestHelper\dataSeek
dataSeek( $res, $row)
Change the position of the cursor in a result object.
Definition: DatabaseTestHelper.php:123
$password
return false to override stock group addition can be modified try getUserPermissionsErrors userCan checks are continued by internal code can override on output return false to not delete it return false to override the default password checks this Boolean value will be checked to determine if the password was valid return false to implement your own hashing method & $password
Definition: hooks.txt:2697
DatabaseTestHelper
Helper for testing the methods from the DatabaseBase class.
Definition: DatabaseTestHelper.php:7
DatabaseTestHelper\fieldName
fieldName( $res, $n)
Get a field name in a result object.
Definition: DatabaseTestHelper.php:115
DatabaseTestHelper\addSql
addSql( $sql)
Definition: DatabaseTestHelper.php:47
DatabaseTestHelper\indexInfo
indexInfo( $table, $index, $fname='Database::indexInfo')
Get information about an index into an object.
Definition: DatabaseTestHelper.php:139
DatabaseTestHelper\$lastSqls
$lastSqls
Array of lastSqls passed to query(), This is an array since some methods in DatabaseBase can do more ...
Definition: DatabaseTestHelper.php:20
DatabaseTestHelper\open
open( $server, $user, $password, $dbName)
Open a connection to the database.
Definition: DatabaseTestHelper.php:95
DatabaseTestHelper\closeConnection
closeConnection()
Closes underlying database connection.
Definition: DatabaseTestHelper.php:159
DatabaseTestHelper\affectedRows
affectedRows()
Get the number of rows affected by the last write query.
Definition: DatabaseTestHelper.php:143
DatabaseTestHelper\fetchObject
fetchObject( $res)
Fetch the next row from the given result object, in object form.
Definition: DatabaseTestHelper.php:99
$res
$res
Definition: database.txt:21
DatabaseTestHelper\lastErrno
lastErrno()
Get the last error number.
Definition: DatabaseTestHelper.php:127