MediaWiki  1.23.8
MediaWikiTestCase.php
Go to the documentation of this file.
1 <?php
2 
6 abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
7 
20  private $called = array();
21 
26  public static $users;
27 
32  protected $db;
33 
38  protected $tablesUsed = array(); // tables with data
39 
40  private static $useTemporaryTables = true;
41  private static $reuseDB = false;
42  private static $dbSetup = false;
43  private static $oldTablePrefix = false;
44 
50  private $phpErrorLevel;
51 
58  private $tmpFiles = array();
59 
66  private $mwGlobals = array();
67 
71  const DB_PREFIX = 'unittest_';
72  const ORA_DB_PREFIX = 'ut_';
73 
78  protected $supportedDBs = array(
79  'mysql',
80  'sqlite',
81  'postgres',
82  'oracle'
83  );
84 
85  public function __construct( $name = null, array $data = array(), $dataName = '' ) {
86  parent::__construct( $name, $data, $dataName );
87 
88  $this->backupGlobals = false;
89  $this->backupStaticAttributes = false;
90  }
91 
92  public function run( PHPUnit_Framework_TestResult $result = null ) {
93  /* Some functions require some kind of caching, and will end up using the db,
94  * which we can't allow, as that would open a new connection for mysql.
95  * Replace with a HashBag. They would not be going to persist anyway.
96  */
98 
99  $needsResetDB = false;
100  $logName = get_class( $this ) . '::' . $this->getName( false );
101 
102  if ( $this->needsDB() ) {
103  // set up a DB connection for this test to use
104 
105  self::$useTemporaryTables = !$this->getCliArg( 'use-normal-tables' );
106  self::$reuseDB = $this->getCliArg( 'reuse-db' );
107 
108  $this->db = wfGetDB( DB_MASTER );
109 
110  $this->checkDbIsSupported();
111 
112  if ( !self::$dbSetup ) {
113  wfProfileIn( $logName . ' (clone-db)' );
114 
115  // switch to a temporary clone of the database
116  self::setupTestDB( $this->db, $this->dbPrefix() );
117 
118  if ( ( $this->db->getType() == 'oracle' || !self::$useTemporaryTables ) && self::$reuseDB ) {
119  $this->resetDB();
120  }
121 
122  wfProfileOut( $logName . ' (clone-db)' );
123  }
124 
125  wfProfileIn( $logName . ' (prepare-db)' );
126  $this->addCoreDBData();
127  $this->addDBData();
128  wfProfileOut( $logName . ' (prepare-db)' );
129 
130  $needsResetDB = true;
131  }
132 
133  wfProfileIn( $logName );
134  parent::run( $result );
135  wfProfileOut( $logName );
136 
137  if ( $needsResetDB ) {
138  wfProfileIn( $logName . ' (reset-db)' );
139  $this->resetDB();
140  wfProfileOut( $logName . ' (reset-db)' );
141  }
142  }
143 
149  public function usesTemporaryTables() {
151  }
152 
162  protected function getNewTempFile() {
163  $fileName = tempnam( wfTempDir(), 'MW_PHPUnit_' . get_class( $this ) . '_' );
164  $this->tmpFiles[] = $fileName;
165 
166  return $fileName;
167  }
168 
179  protected function getNewTempDirectory() {
180  // Starting of with a temporary /file/.
181  $fileName = $this->getNewTempFile();
182 
183  // Converting the temporary /file/ to a /directory/
184  //
185  // The following is not atomic, but at least we now have a single place,
186  // where temporary directory creation is bundled and can be improved
187  unlink( $fileName );
188  $this->assertTrue( wfMkdirParents( $fileName ) );
189 
190  return $fileName;
191  }
192 
193  protected function setUp() {
194  wfProfileIn( __METHOD__ );
195  parent::setUp();
196  $this->called['setUp'] = 1;
197 
198  $this->phpErrorLevel = intval( ini_get( 'error_reporting' ) );
199 
200  // Cleaning up temporary files
201  foreach ( $this->tmpFiles as $fileName ) {
202  if ( is_file( $fileName ) || ( is_link( $fileName ) ) ) {
203  unlink( $fileName );
204  } elseif ( is_dir( $fileName ) ) {
205  wfRecursiveRemoveDir( $fileName );
206  }
207  }
208 
209  if ( $this->needsDB() && $this->db ) {
210  // Clean up open transactions
211  while ( $this->db->trxLevel() > 0 ) {
212  $this->db->rollback();
213  }
214 
215  // don't ignore DB errors
216  $this->db->ignoreErrors( false );
217  }
218 
219  wfProfileOut( __METHOD__ );
220  }
221 
222  protected function tearDown() {
223  wfProfileIn( __METHOD__ );
224 
225  // Cleaning up temporary files
226  foreach ( $this->tmpFiles as $fileName ) {
227  if ( is_file( $fileName ) || ( is_link( $fileName ) ) ) {
228  unlink( $fileName );
229  } elseif ( is_dir( $fileName ) ) {
230  wfRecursiveRemoveDir( $fileName );
231  }
232  }
233 
234  if ( $this->needsDB() && $this->db ) {
235  // Clean up open transactions
236  while ( $this->db->trxLevel() > 0 ) {
237  $this->db->rollback();
238  }
239 
240  // don't ignore DB errors
241  $this->db->ignoreErrors( false );
242  }
243 
244  // Restore mw globals
245  foreach ( $this->mwGlobals as $key => $value ) {
246  $GLOBALS[$key] = $value;
247  }
248  $this->mwGlobals = array();
249 
250  $phpErrorLevel = intval( ini_get( 'error_reporting' ) );
251 
252  if ( $phpErrorLevel !== $this->phpErrorLevel ) {
253  ini_set( 'error_reporting', $this->phpErrorLevel );
254 
255  $oldHex = strtoupper( dechex( $this->phpErrorLevel ) );
256  $newHex = strtoupper( dechex( $phpErrorLevel ) );
257  $message = "PHP error_reporting setting was left dirty: was 0x$oldHex before test, 0x$newHex after test!";
258 
259  $this->fail( $message );
260  }
261 
262  parent::tearDown();
263  wfProfileOut( __METHOD__ );
264  }
265 
270  final public function testMediaWikiTestCaseParentSetupCalled() {
271  $this->assertArrayHasKey( 'setUp', $this->called,
272  get_called_class() . "::setUp() must call parent::setUp()"
273  );
274  }
275 
308  protected function setMwGlobals( $pairs, $value = null ) {
309  if ( is_string( $pairs ) ) {
310  $pairs = array( $pairs => $value );
311  }
312 
313  $this->stashMwGlobals( array_keys( $pairs ) );
314 
315  foreach ( $pairs as $key => $value ) {
316  $GLOBALS[$key] = $value;
317  }
318  }
319 
335  protected function stashMwGlobals( $globalKeys ) {
336  if ( is_string( $globalKeys ) ) {
337  $globalKeys = array( $globalKeys );
338  }
339 
340  foreach ( $globalKeys as $globalKey ) {
341  // NOTE: make sure we only save the global once or a second call to
342  // setMwGlobals() on the same global would override the original
343  // value.
344  if ( !array_key_exists( $globalKey, $this->mwGlobals ) ) {
345  if ( !array_key_exists( $globalKey, $GLOBALS ) ) {
346  throw new Exception( "Global with key {$globalKey} doesn't exist and cant be stashed" );
347  }
348  // NOTE: we serialize then unserialize the value in case it is an object
349  // this stops any objects being passed by reference. We could use clone
350  // and if is_object but this does account for objects within objects!
351  try {
352  $this->mwGlobals[$globalKey] = unserialize( serialize( $GLOBALS[$globalKey] ) );
353  }
354  // NOTE; some things such as Closures are not serializable
355  // in this case just set the value!
356  catch ( Exception $e ) {
357  $this->mwGlobals[$globalKey] = $GLOBALS[$globalKey];
358  }
359  }
360  }
361  }
362 
375  protected function mergeMwGlobalArrayValue( $name, $values ) {
376  if ( !isset( $GLOBALS[$name] ) ) {
377  $merged = $values;
378  } else {
379  if ( !is_array( $GLOBALS[$name] ) ) {
380  throw new MWException( "MW global $name is not an array." );
381  }
382 
383  // NOTE: do not use array_merge, it screws up for numeric keys.
384  $merged = $GLOBALS[$name];
385  foreach ( $values as $k => $v ) {
386  $merged[$k] = $v;
387  }
388  }
389 
390  $this->setMwGlobals( $name, $merged );
391  }
392 
397  public function dbPrefix() {
398  return $this->db->getType() == 'oracle' ? self::ORA_DB_PREFIX : self::DB_PREFIX;
399  }
400 
405  public function needsDB() {
406  # if the test says it uses database tables, it needs the database
407  if ( $this->tablesUsed ) {
408  return true;
409  }
410 
411  # if the test says it belongs to the Database group, it needs the database
412  $rc = new ReflectionClass( $this );
413  if ( preg_match( '/@group +Database/im', $rc->getDocComment() ) ) {
414  return true;
415  }
416 
417  return false;
418  }
419 
426  public function addDBData() {
427  }
428 
429  private function addCoreDBData() {
430  if ( $this->db->getType() == 'oracle' ) {
431 
432  # Insert 0 user to prevent FK violations
433  # Anonymous user
434  $this->db->insert( 'user', array(
435  'user_id' => 0,
436  'user_name' => 'Anonymous' ), __METHOD__, array( 'IGNORE' ) );
437 
438  # Insert 0 page to prevent FK violations
439  # Blank page
440  $this->db->insert( 'page', array(
441  'page_id' => 0,
442  'page_namespace' => 0,
443  'page_title' => ' ',
444  'page_restrictions' => null,
445  'page_counter' => 0,
446  'page_is_redirect' => 0,
447  'page_is_new' => 0,
448  'page_random' => 0,
449  'page_touched' => $this->db->timestamp(),
450  'page_latest' => 0,
451  'page_len' => 0 ), __METHOD__, array( 'IGNORE' ) );
452  }
453 
455 
456  //Make sysop user
457  $user = User::newFromName( 'UTSysop' );
458 
459  if ( $user->idForName() == 0 ) {
460  $user->addToDatabase();
461  $user->setPassword( 'UTSysopPassword' );
462 
463  $user->addGroup( 'sysop' );
464  $user->addGroup( 'bureaucrat' );
465  $user->saveSettings();
466  }
467 
468  //Make 1 page with 1 revision
469  $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
470  if ( !$page->getId() == 0 ) {
471  $page->doEditContent(
472  new WikitextContent( 'UTContent' ),
473  'UTPageSummary',
474  EDIT_NEW,
475  false,
476  User::newFromName( 'UTSysop' ) );
477  }
478  }
479 
487  public static function teardownTestDB() {
488  if ( !self::$dbSetup ) {
489  return;
490  }
491 
492  CloneDatabase::changePrefix( self::$oldTablePrefix );
493 
494  self::$oldTablePrefix = false;
495  self::$dbSetup = false;
496  }
497 
519  public static function setupTestDB( DatabaseBase $db, $prefix ) {
520  global $wgDBprefix;
521  if ( $wgDBprefix === $prefix ) {
522  throw new MWException(
523  'Cannot run unit tests, the database prefix is already "' . $prefix . '"' );
524  }
525 
526  if ( self::$dbSetup ) {
527  return;
528  }
529 
530  $tablesCloned = self::listTables( $db );
531  $dbClone = new CloneDatabase( $db, $tablesCloned, $prefix );
532  $dbClone->useTemporaryTables( self::$useTemporaryTables );
533 
534  self::$dbSetup = true;
535  self::$oldTablePrefix = $wgDBprefix;
536 
537  if ( ( $db->getType() == 'oracle' || !self::$useTemporaryTables ) && self::$reuseDB ) {
538  CloneDatabase::changePrefix( $prefix );
539 
540  return;
541  } else {
542  $dbClone->cloneTableStructure();
543  }
544 
545  if ( $db->getType() == 'oracle' ) {
546  $db->query( 'BEGIN FILL_WIKI_INFO; END;' );
547  }
548  }
549 
553  private function resetDB() {
554  if ( $this->db ) {
555  if ( $this->db->getType() == 'oracle' ) {
556  if ( self::$useTemporaryTables ) {
557  wfGetLB()->closeAll();
558  $this->db = wfGetDB( DB_MASTER );
559  } else {
560  foreach ( $this->tablesUsed as $tbl ) {
561  if ( $tbl == 'interwiki' ) {
562  continue;
563  }
564  $this->db->query( 'TRUNCATE TABLE ' . $this->db->tableName( $tbl ), __METHOD__ );
565  }
566  }
567  } else {
568  foreach ( $this->tablesUsed as $tbl ) {
569  if ( $tbl == 'interwiki' || $tbl == 'user' ) {
570  continue;
571  }
572  $this->db->delete( $tbl, '*', __METHOD__ );
573  }
574  }
575  }
576  }
577 
587  public function __call( $func, $args ) {
588  static $compatibility = array(
589  'assertEmpty' => 'assertEmpty2', // assertEmpty was added in phpunit 3.7.32
590  );
591 
592  if ( isset( $compatibility[$func] ) ) {
593  return call_user_func_array( array( $this, $compatibility[$func] ), $args );
594  } else {
595  throw new MWException( "Called non-existant $func method on "
596  . get_class( $this ) );
597  }
598  }
599 
603  private function assertEmpty2( $value, $msg ) {
604  return $this->assertTrue( $value == '', $msg );
605  }
606 
607  private static function unprefixTable( $tableName ) {
608  global $wgDBprefix;
609 
610  return substr( $tableName, strlen( $wgDBprefix ) );
611  }
612 
613  private static function isNotUnittest( $table ) {
614  return strpos( $table, 'unittest_' ) !== 0;
615  }
616 
624  public static function listTables( $db ) {
625  global $wgDBprefix;
626 
627  $tables = $db->listTables( $wgDBprefix, __METHOD__ );
628 
629  if ( $db->getType() === 'mysql' ) {
630  # bug 43571: cannot clone VIEWs under MySQL
631  $views = $db->listViews( $wgDBprefix, __METHOD__ );
632  $tables = array_diff( $tables, $views );
633  }
634  $tables = array_map( array( __CLASS__, 'unprefixTable' ), $tables );
635 
636  // Don't duplicate test tables from the previous fataled run
637  $tables = array_filter( $tables, array( __CLASS__, 'isNotUnittest' ) );
638 
639  if ( $db->getType() == 'sqlite' ) {
640  $tables = array_flip( $tables );
641  // these are subtables of searchindex and don't need to be duped/dropped separately
642  unset( $tables['searchindex_content'] );
643  unset( $tables['searchindex_segdir'] );
644  unset( $tables['searchindex_segments'] );
645  $tables = array_flip( $tables );
646  }
647 
648  return $tables;
649  }
650 
655  protected function checkDbIsSupported() {
656  if ( !in_array( $this->db->getType(), $this->supportedDBs ) ) {
657  throw new MWException( $this->db->getType() . " is not currently supported for unit testing." );
658  }
659  }
660 
664  public function getCliArg( $offset ) {
665  if ( isset( MediaWikiPHPUnitCommand::$additionalOptions[$offset] ) ) {
667  }
668  }
669 
673  public function setCliArg( $offset, $value ) {
675  }
676 
685  public function hideDeprecated( $function ) {
687  wfDeprecated( $function );
689  }
690 
709  protected function assertSelect( $table, $fields, $condition, array $expectedRows ) {
710  if ( !$this->needsDB() ) {
711  throw new MWException( 'When testing database state, the test cases\'s needDB()' .
712  ' method should return true. Use @group Database or $this->tablesUsed.' );
713  }
714 
715  $db = wfGetDB( DB_SLAVE );
716 
717  $res = $db->select( $table, $fields, $condition, wfGetCaller(), array( 'ORDER BY' => $fields ) );
718  $this->assertNotEmpty( $res, "query failed: " . $db->lastError() );
719 
720  $i = 0;
721 
722  foreach ( $expectedRows as $expected ) {
723  $r = $res->fetchRow();
724  self::stripStringKeys( $r );
725 
726  $i += 1;
727  $this->assertNotEmpty( $r, "row #$i missing" );
728 
729  $this->assertEquals( $expected, $r, "row #$i mismatches" );
730  }
731 
732  $r = $res->fetchRow();
733  self::stripStringKeys( $r );
734 
735  $this->assertFalse( $r, "found extra row (after #$i)" );
736  }
737 
749  protected function arrayWrap( array $elements ) {
750  return array_map(
751  function ( $element ) {
752  return array( $element );
753  },
754  $elements
755  );
756  }
757 
770  protected function assertArrayEquals( array $expected, array $actual, $ordered = false, $named = false ) {
771  if ( !$ordered ) {
772  $this->objectAssociativeSort( $expected );
773  $this->objectAssociativeSort( $actual );
774  }
775 
776  if ( !$named ) {
777  $expected = array_values( $expected );
778  $actual = array_values( $actual );
779  }
780 
781  call_user_func_array(
782  array( $this, 'assertEquals' ),
783  array_merge( array( $expected, $actual ), array_slice( func_get_args(), 4 ) )
784  );
785  }
786 
799  protected function assertHTMLEquals( $expected, $actual, $msg = '' ) {
800  $expected = str_replace( '>', ">\n", $expected );
801  $actual = str_replace( '>', ">\n", $actual );
802 
803  $this->assertEquals( $expected, $actual, $msg );
804  }
805 
813  protected function objectAssociativeSort( array &$array ) {
814  uasort(
815  $array,
816  function ( $a, $b ) {
817  return serialize( $a ) > serialize( $b ) ? 1 : -1;
818  }
819  );
820  }
821 
831  protected static function stripStringKeys( &$r ) {
832  if ( !is_array( $r ) ) {
833  return;
834  }
835 
836  foreach ( $r as $k => $v ) {
837  if ( is_string( $k ) ) {
838  unset( $r[$k] );
839  }
840  }
841  }
842 
856  protected function assertTypeOrValue( $type, $actual, $value = false, $message = '' ) {
857  if ( $actual === $value ) {
858  $this->assertTrue( true, $message );
859  } else {
860  $this->assertType( $type, $actual, $message );
861  }
862  }
863 
875  protected function assertType( $type, $actual, $message = '' ) {
876  if ( class_exists( $type ) || interface_exists( $type ) ) {
877  $this->assertInstanceOf( $type, $actual, $message );
878  } else {
879  $this->assertInternalType( $type, $actual, $message );
880  }
881  }
882 
892  protected function isWikitextNS( $ns ) {
893  global $wgNamespaceContentModels;
894 
895  if ( isset( $wgNamespaceContentModels[$ns] ) ) {
896  return $wgNamespaceContentModels[$ns] === CONTENT_MODEL_WIKITEXT;
897  }
898 
899  return true;
900  }
901 
909  protected function getDefaultWikitextNS() {
910  global $wgNamespaceContentModels;
911 
912  static $wikitextNS = null; // this is not going to change
913  if ( $wikitextNS !== null ) {
914  return $wikitextNS;
915  }
916 
917  // quickly short out on most common case:
918  if ( !isset( $wgNamespaceContentModels[NS_MAIN] ) ) {
919  return NS_MAIN;
920  }
921 
922  // NOTE: prefer content namespaces
923  $namespaces = array_unique( array_merge(
925  array( NS_MAIN, NS_HELP, NS_PROJECT ), // prefer these
927  ) );
928 
929  $namespaces = array_diff( $namespaces, array(
930  NS_FILE, NS_CATEGORY, NS_MEDIAWIKI, NS_USER // don't mess with magic namespaces
931  ) );
932 
933  $talk = array_filter( $namespaces, function ( $ns ) {
934  return MWNamespace::isTalk( $ns );
935  } );
936 
937  // prefer non-talk pages
938  $namespaces = array_diff( $namespaces, $talk );
939  $namespaces = array_merge( $namespaces, $talk );
940 
941  // check default content model of each namespace
942  foreach ( $namespaces as $ns ) {
943  if ( !isset( $wgNamespaceContentModels[$ns] ) ||
944  $wgNamespaceContentModels[$ns] === CONTENT_MODEL_WIKITEXT
945  ) {
946 
947  $wikitextNS = $ns;
948 
949  return $wikitextNS;
950  }
951  }
952 
953  // give up
954  // @todo Inside a test, we could skip the test as incomplete.
955  // But frequently, this is used in fixture setup.
956  throw new MWException( "No namespace defaults to wikitext!" );
957  }
958 
965  protected function checkHasDiff3() {
966  global $wgDiff3;
967 
968  # This check may also protect against code injection in
969  # case of broken installations.
971  $haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 );
973 
974  if ( !$haveDiff3 ) {
975  $this->markTestSkipped( "Skip test, since diff3 is not configured" );
976  }
977  }
978 
989  protected function checkHasGzip() {
990  static $haveGzip;
991 
992  if ( $haveGzip === null ) {
993  $retval = null;
994  wfShellExec( 'gzip -V', $retval );
995  $haveGzip = ( $retval === 0 );
996  }
997 
998  if ( !$haveGzip ) {
999  $this->markTestSkipped( "Skip test, requires the gzip utility in PATH" );
1000  }
1001 
1002  return $haveGzip;
1003  }
1004 
1011  protected function checkPHPExtension( $extName ) {
1012  $loaded = extension_loaded( $extName );
1013  if ( !$loaded ) {
1014  $this->markTestSkipped( "PHP extension '$extName' is not loaded, skipping." );
1015  }
1016 
1017  return $loaded;
1018  }
1019 
1031  protected function assertException( $code, $expected = 'Exception', $message = '' ) {
1032  $pokemons = null;
1033 
1034  try {
1035  call_user_func( $code );
1036  } catch ( Exception $pokemons ) {
1037  // Gotta Catch 'Em All!
1038  }
1039 
1040  if ( $message === '' ) {
1041  $message = 'An exception of type "' . $expected . '" should have been thrown';
1042  }
1043 
1044  $this->assertInstanceOf( $expected, $pokemons, $message );
1045  }
1046 
1061  protected function assertValidHtmlSnippet( $html ) {
1062  $html = '<!DOCTYPE html><html><head><title>test</title></head><body>' . $html . '</body></html>';
1063  $this->assertValidHtmlDocument( $html );
1064  }
1065 
1077  protected function assertValidHtmlDocument( $html ) {
1078  // Note: we only validate if the tidy PHP extension is available.
1079  // In case wgTidyInternal is false, MWTidy would fall back to the command line version
1080  // of tidy. In that case however, we can not reliably detect whether a failing validation
1081  // is due to malformed HTML, or caused by tidy not being installed as a command line tool.
1082  // That would cause all HTML assertions to fail on a system that has no tidy installed.
1083  if ( !$GLOBALS['wgTidyInternal'] ) {
1084  $this->markTestSkipped( 'Tidy extension not installed' );
1085  }
1086 
1087  $errorBuffer = '';
1088  MWTidy::checkErrors( $html, $errorBuffer );
1089  $allErrors = preg_split( '/[\r\n]+/', $errorBuffer );
1090 
1091  // Filter Tidy warnings which aren't useful for us.
1092  // Tidy eg. often cries about parameters missing which have actually
1093  // been deprecated since HTML4, thus we should not care about them.
1094  $errors = preg_grep(
1095  '/^(.*Warning: (trimming empty|.* lacks ".*?" attribute).*|\s*)$/m',
1096  $allErrors, PREG_GREP_INVERT
1097  );
1098 
1099  $this->assertEmpty( $errors, implode( "\n", $errors ) );
1100  }
1101 
1102 }
MediaWikiTestCase\unprefixTable
static unprefixTable( $tableName)
Definition: MediaWikiTestCase.php:601
MediaWikiTestCase\$reuseDB
static $reuseDB
Definition: MediaWikiTestCase.php:39
MediaWikiTestCase\assertValidHtmlDocument
assertValidHtmlDocument( $html)
Asserts that the given string is valid HTML document.
Definition: MediaWikiTestCase.php:1071
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:764
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
wfShellExec
wfShellExec( $cmd, &$retval=null, $environ=array(), $limits=array(), $options=array())
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...
Definition: GlobalFunctions.php:2804
MediaWikiTestCase\stashMwGlobals
stashMwGlobals( $globalKeys)
Stashes the global, will be restored in tearDown()
Definition: MediaWikiTestCase.php:329
NS_HELP
const NS_HELP
Definition: Defines.php:91
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
MWNamespace\getValidNamespaces
static getValidNamespaces()
Returns an array of the namespaces (by integer id) that exist on the wiki.
Definition: Namespace.php:273
MWNamespace\isTalk
static isTalk( $index)
Is the given namespace a talk namespace?
Definition: Namespace.php:107
MediaWikiTestCase\mergeMwGlobalArrayValue
mergeMwGlobalArrayValue( $name, $values)
Merges the given values into a MW global array variable.
Definition: MediaWikiTestCase.php:369
HashBagOStuff
This is a test of the interface, mainly.
Definition: HashBagOStuff.php:30
$html
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1530
$tables
namespace and then decline to actually register it RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition: hooks.txt:815
MediaWikiTestCase\stripStringKeys
static stripStringKeys(&$r)
Utility function for eliminating all string keys from an array.
Definition: MediaWikiTestCase.php:825
wfMkdirParents
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
Definition: GlobalFunctions.php:2590
MediaWikiTestCase\$tmpFiles
array $tmpFiles
Holds the paths of temporary files/directories created through getNewTempFile, and getNewTempDirector...
Definition: MediaWikiTestCase.php:54
wfGetLB
wfGetLB( $wiki=false)
Get a load balancer object.
Definition: GlobalFunctions.php:3669
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3659
MediaWikiTestCase\isWikitextNS
isWikitextNS( $ns)
Returns true if the given namespace defaults to Wikitext according to $wgNamespaceContentModels.
Definition: MediaWikiTestCase.php:886
DatabaseBase\query
query( $sql, $fname=__METHOD__, $tempIgnore=false)
Run an SQL query and return the result.
Definition: Database.php:1001
MediaWikiTestCase\needsDB
needsDB()
Definition: MediaWikiTestCase.php:399
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
wfSuppressWarnings
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
Definition: GlobalFunctions.php:2387
MediaWikiTestCase\$useTemporaryTables
static $useTemporaryTables
Definition: MediaWikiTestCase.php:38
NS_FILE
const NS_FILE
Definition: Defines.php:85
MediaWikiTestCase\checkDbIsSupported
checkDbIsSupported()
Definition: MediaWikiTestCase.php:649
MediaWikiTestCase\getCliArg
getCliArg( $offset)
Definition: MediaWikiTestCase.php:658
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:389
MediaWikiTestCase\testMediaWikiTestCaseParentSetupCalled
testMediaWikiTestCaseParentSetupCalled()
Make sure MediaWikiTestCase extending classes have called their parent setUp method.
Definition: MediaWikiTestCase.php:264
fail
as a message key or array as accepted by ApiBase::dieUsageMsg after processing request parameters Return false to let the request fail
Definition: hooks.txt:375
MediaWikiTestCase\assertValidHtmlSnippet
assertValidHtmlSnippet( $html)
Asserts that the given string is a valid HTML snippet.
Definition: MediaWikiTestCase.php:1055
MediaWikiTestCase\isNotUnittest
static isNotUnittest( $table)
Definition: MediaWikiTestCase.php:607
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:283
MediaWikiTestCase\__construct
__construct( $name=null, array $data=array(), $dataName='')
Definition: MediaWikiTestCase.php:79
MWNamespace\getContentNamespaces
static getContentNamespaces()
Get a list of all namespace indices which are considered to contain content.
Definition: Namespace.php:334
MediaWikiTestCase\teardownTestDB
static teardownTestDB()
Restores MediaWiki to using the table set (table prefix) it was using before setupTestDB() was called...
Definition: MediaWikiTestCase.php:481
MediaWikiTestCase\$users
static $users
Definition: MediaWikiTestCase.php:26
MediaWikiTestCase\__call
__call( $func, $args)
Definition: MediaWikiTestCase.php:581
MediaWikiTestCase\$called
$called
$called tracks whether the setUp and tearDown method has been called.
Definition: MediaWikiTestCase.php:20
NS_MAIN
const NS_MAIN
Definition: Defines.php:79
MediaWikiTestCase\checkHasDiff3
checkHasDiff3()
Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped,...
Definition: MediaWikiTestCase.php:959
MediaWikiTestCase\resetDB
resetDB()
Empty all tables so they can be repopulated for tests.
Definition: MediaWikiTestCase.php:547
MWException
MediaWiki exception.
Definition: MWException.php:26
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:103
NS_PROJECT
const NS_PROJECT
Definition: Defines.php:83
MediaWikiPHPUnitCommand\$additionalOptions
static $additionalOptions
Definition: MediaWikiPHPUnitCommand.php:5
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1127
MediaWikiTestCase\$phpErrorLevel
int $phpErrorLevel
Original value of PHP's error_reporting setting.
Definition: MediaWikiTestCase.php:47
DatabaseBase\select
select( $table, $vars, $conds='', $fname=__METHOD__, $options=array(), $join_conds=array())
Execute a SELECT query constructed using the various parameters provided.
Definition: Database.php:1575
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2417
MediaWikiTestCase\assertSelect
assertSelect( $table, $fields, $condition, array $expectedRows)
Asserts that the given database query yields the rows given by $expectedRows.
Definition: MediaWikiTestCase.php:703
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
MediaWikiTestCase\getNewTempFile
getNewTempFile()
Obtains a new temporary file name.
Definition: MediaWikiTestCase.php:156
MediaWikiTestCase\addCoreDBData
addCoreDBData()
Definition: MediaWikiTestCase.php:423
MediaWikiTestCase\run
run(PHPUnit_Framework_TestResult $result=null)
Definition: MediaWikiTestCase.php:86
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
MediaWikiTestCase\$oldTablePrefix
static $oldTablePrefix
Definition: MediaWikiTestCase.php:41
ObjectCache\$instances
static $instances
Definition: ObjectCache.php:30
MediaWikiTestCase\hideDeprecated
hideDeprecated( $function)
Don't throw a warning if $function is deprecated and called later.
Definition: MediaWikiTestCase.php:679
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
DatabaseBase\listTables
listTables( $prefix=null, $fname=__METHOD__)
List all tables on the database.
Definition: Database.php:3558
MediaWikiTestCase\assertException
assertException( $code, $expected='Exception', $message='')
Asserts that an exception of the specified type occurs when running the provided code.
Definition: MediaWikiTestCase.php:1025
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
MediaWikiTestCase\assertEmpty2
assertEmpty2( $value, $msg)
Used as a compatibility method for phpunit < 3.7.32.
Definition: MediaWikiTestCase.php:597
MediaWikiTestCase\getDefaultWikitextNS
getDefaultWikitextNS()
Returns the ID of a namespace that defaults to Wikitext.
Definition: MediaWikiTestCase.php:903
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:93
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:33
MediaWikiTestCase\arrayWrap
arrayWrap(array $elements)
Utility method taking an array of elements and wrapping each element in it's own array.
Definition: MediaWikiTestCase.php:743
DatabaseType\getType
getType()
Get the type of the DBMS, as it appears in $wgDBtype.
MediaWikiTestCase\checkHasGzip
checkHasGzip()
Check whether we have the 'gzip' commandline utility, will skip the test whenever "gzip -V" fails.
Definition: MediaWikiTestCase.php:983
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
MediaWikiTestCase\assertHTMLEquals
assertHTMLEquals( $expected, $actual, $msg='')
Put each HTML element on its own line and then equals() the results.
Definition: MediaWikiTestCase.php:793
$value
$value
Definition: styleTest.css.php:45
MediaWikiTestCase\assertTypeOrValue
assertTypeOrValue( $type, $actual, $value=false, $message='')
Asserts that the provided variable is of the specified internal type or equals the $value argument.
Definition: MediaWikiTestCase.php:850
MediaWikiTestCase\$db
DatabaseBase $db
Definition: MediaWikiTestCase.php:31
MediaWikiTestCase\dbPrefix
dbPrefix()
Definition: MediaWikiTestCase.php:391
DatabaseBase
Database abstraction object.
Definition: Database.php:219
MediaWikiTestCase\setupTestDB
static setupTestDB(DatabaseBase $db, $prefix)
Creates an empty skeleton of the wiki database by cloning its structure to equivalent tables using th...
Definition: MediaWikiTestCase.php:513
MediaWikiTestCase\listTables
static listTables( $db)
Definition: MediaWikiTestCase.php:618
DatabaseType\lastError
lastError()
Get a description of the last error.
MediaWikiTestCase\addDBData
addDBData()
Stub.
Definition: MediaWikiTestCase.php:420
$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
MediaWikiTestCase\setUp
setUp()
Definition: MediaWikiTestCase.php:187
MediaWikiTestCase\objectAssociativeSort
objectAssociativeSort(array &$array)
Does an associative sort that works for objects.
Definition: MediaWikiTestCase.php:807
EDIT_NEW
const EDIT_NEW
Definition: Defines.php:189
MediaWikiTestCase\DB_PREFIX
const DB_PREFIX
Table name prefixes.
Definition: MediaWikiTestCase.php:66
$args
if( $line===false) $args
Definition: cdb.php:62
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
$namespaces
namespace and then decline to actually register it & $namespaces
Definition: hooks.txt:815
wfTempDir
wfTempDir()
Tries to get the system directory for temporary files.
Definition: GlobalFunctions.php:2564
MediaWikiTestCase\$supportedDBs
array $supportedDBs
Definition: MediaWikiTestCase.php:72
CloneDatabase
Definition: CloneDatabase.php:27
DatabaseBase\listViews
listViews( $prefix=null, $fname=__METHOD__)
Lists all the VIEWs in the database.
Definition: Database.php:3581
MediaWikiTestCase\ORA_DB_PREFIX
const ORA_DB_PREFIX
Definition: MediaWikiTestCase.php:67
CloneDatabase\changePrefix
static changePrefix( $prefix)
Change the table prefix on all open DB connections/.
Definition: CloneDatabase.php:114
User\resetIdByNameCache
static resetIdByNameCache()
Reset the cache used in idFromName().
Definition: User.php:535
wfRecursiveRemoveDir
wfRecursiveRemoveDir( $dir)
Remove a directory and all its content.
Definition: GlobalFunctions.php:2632
MediaWikiTestCase\$tablesUsed
array $tablesUsed
Definition: MediaWikiTestCase.php:36
as
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 as
Definition: distributors.txt:9
NS_USER
const NS_USER
Definition: Defines.php:81
MediaWikiTestCase\checkPHPExtension
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
Definition: MediaWikiTestCase.php:1005
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:87
MediaWikiTestCase\$mwGlobals
array $mwGlobals
Holds original values of MediaWiki configuration settings to be restored in tearDown().
Definition: MediaWikiTestCase.php:61
MWTidy\checkErrors
static checkErrors( $text, &$errorStr=null)
Check HTML for errors, used if $wgValidateAllHtml = true.
Definition: Tidy.php:159
MediaWikiTestCase\usesTemporaryTables
usesTemporaryTables()
Definition: MediaWikiTestCase.php:143
$e
if( $useReadline) $e
Definition: eval.php:66
MediaWikiTestCase\assertType
assertType( $type, $actual, $message='')
Asserts the type of the provided value.
Definition: MediaWikiTestCase.php:869
MediaWikiTestCase\setCliArg
setCliArg( $offset, $value)
Definition: MediaWikiTestCase.php:667
$res
$res
Definition: database.txt:21
$retval
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 incomplete not yet checked for validity & $retval
Definition: hooks.txt:237
wfGetCaller
wfGetCaller( $level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...
Definition: GlobalFunctions.php:1941
$GLOBALS
$GLOBALS['IP']
Definition: ComposerHookHandler.php:6
CACHE_DB
const CACHE_DB
Definition: Defines.php:113
MediaWikiTestCase\tearDown
tearDown()
Definition: MediaWikiTestCase.php:216
MediaWikiTestCase\$dbSetup
static $dbSetup
Definition: MediaWikiTestCase.php:40
$type
$type
Definition: testCompression.php:46
MediaWikiTestCase\getNewTempDirectory
getNewTempDirectory()
obtains a new temporary directory
Definition: MediaWikiTestCase.php:173