MediaWiki  1.27.1
MediaWikiTestCase.php
Go to the documentation of this file.
1 <?php
6 
10 abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
23  private $called = [];
24 
29  public static $users;
30 
37  protected $db;
38 
43  protected $tablesUsed = []; // tables with data
44 
45  private static $useTemporaryTables = true;
46  private static $reuseDB = false;
47  private static $dbSetup = false;
48  private static $oldTablePrefix = false;
49 
55  private $phpErrorLevel;
56 
63  private $tmpFiles = [];
64 
71  private $mwGlobals = [];
72 
77  private $loggers = [];
78 
82  const DB_PREFIX = 'unittest_';
83  const ORA_DB_PREFIX = 'ut_';
84 
89  protected $supportedDBs = [
90  'mysql',
91  'sqlite',
92  'postgres',
93  'oracle'
94  ];
95 
96  public function __construct( $name = null, array $data = [], $dataName = '' ) {
97  parent::__construct( $name, $data, $dataName );
98 
99  $this->backupGlobals = false;
100  $this->backupStaticAttributes = false;
101  }
102 
103  public function __destruct() {
104  // Complain if self::setUp() was called, but not self::tearDown()
105  // $this->called['setUp'] will be checked by self::testMediaWikiTestCaseParentSetupCalled()
106  if ( isset( $this->called['setUp'] ) && !isset( $this->called['tearDown'] ) ) {
107  throw new MWException( static::class . "::tearDown() must call parent::tearDown()" );
108  }
109  }
110 
111  public function run( PHPUnit_Framework_TestResult $result = null ) {
112  /* Some functions require some kind of caching, and will end up using the db,
113  * which we can't allow, as that would open a new connection for mysql.
114  * Replace with a HashBag. They would not be going to persist anyway.
115  */
117 
118  // Sandbox APC by replacing with in-process hash instead.
119  // Ensures values are removed between tests.
120  ObjectCache::$instances['apc'] =
121  ObjectCache::$instances['xcache'] =
122  ObjectCache::$instances['wincache'] = new HashBagOStuff;
123 
124  $needsResetDB = false;
125 
126  if ( $this->needsDB() ) {
127  // set up a DB connection for this test to use
128 
129  self::$useTemporaryTables = !$this->getCliArg( 'use-normal-tables' );
130  self::$reuseDB = $this->getCliArg( 'reuse-db' );
131 
132  $this->db = wfGetDB( DB_MASTER );
133 
134  $this->checkDbIsSupported();
135 
136  if ( !self::$dbSetup ) {
137  $this->setupAllTestDBs();
138  $this->addCoreDBData();
139 
140  if ( ( $this->db->getType() == 'oracle' || !self::$useTemporaryTables ) && self::$reuseDB ) {
141  $this->resetDB( $this->db, $this->tablesUsed );
142  }
143  }
144 
145  // TODO: the DB setup should be done in setUpBeforeClass(), so the test DB
146  // is available in subclass's setUpBeforeClass() and setUp() methods.
147  // This would also remove the need for the HACK that is oncePerClass().
148  if ( $this->oncePerClass() ) {
149  $this->addDBDataOnce();
150  }
151 
152  $this->addDBData();
153  $needsResetDB = true;
154  }
155 
156  parent::run( $result );
157 
158  if ( $needsResetDB ) {
159  $this->resetDB( $this->db, $this->tablesUsed );
160  }
161  }
162 
166  private function oncePerClass() {
167  // Remember current test class in the database connection,
168  // so we know when we need to run addData.
169 
170  $class = static::class;
171 
172  $first = !isset( $this->db->_hasDataForTestClass )
173  || $this->db->_hasDataForTestClass !== $class;
174 
175  $this->db->_hasDataForTestClass = $class;
176  return $first;
177  }
178 
184  public function usesTemporaryTables() {
185  return self::$useTemporaryTables;
186  }
187 
197  protected function getNewTempFile() {
198  $fileName = tempnam( wfTempDir(), 'MW_PHPUnit_' . get_class( $this ) . '_' );
199  $this->tmpFiles[] = $fileName;
200 
201  return $fileName;
202  }
203 
214  protected function getNewTempDirectory() {
215  // Starting of with a temporary /file/.
216  $fileName = $this->getNewTempFile();
217 
218  // Converting the temporary /file/ to a /directory/
219  // The following is not atomic, but at least we now have a single place,
220  // where temporary directory creation is bundled and can be improved
221  unlink( $fileName );
222  $this->assertTrue( wfMkdirParents( $fileName ) );
223 
224  return $fileName;
225  }
226 
227  protected function setUp() {
228  parent::setUp();
229  $this->called['setUp'] = true;
230 
231  $this->phpErrorLevel = intval( ini_get( 'error_reporting' ) );
232 
233  // Cleaning up temporary files
234  foreach ( $this->tmpFiles as $fileName ) {
235  if ( is_file( $fileName ) || ( is_link( $fileName ) ) ) {
236  unlink( $fileName );
237  } elseif ( is_dir( $fileName ) ) {
238  wfRecursiveRemoveDir( $fileName );
239  }
240  }
241 
242  if ( $this->needsDB() && $this->db ) {
243  // Clean up open transactions
244  while ( $this->db->trxLevel() > 0 ) {
245  $this->db->rollback( __METHOD__, 'flush' );
246  }
247  }
248 
250  ObjectCache::getMainWANInstance()->clearProcessCache();
251 
252  ob_start( 'MediaWikiTestCase::wfResetOutputBuffersBarrier' );
253  }
254 
255  protected function addTmpFiles( $files ) {
256  $this->tmpFiles = array_merge( $this->tmpFiles, (array)$files );
257  }
258 
259  protected function tearDown() {
261 
262  $status = ob_get_status();
263  if ( isset( $status['name'] ) &&
264  $status['name'] === 'MediaWikiTestCase::wfResetOutputBuffersBarrier'
265  ) {
266  ob_end_flush();
267  }
268 
269  $this->called['tearDown'] = true;
270  // Cleaning up temporary files
271  foreach ( $this->tmpFiles as $fileName ) {
272  if ( is_file( $fileName ) || ( is_link( $fileName ) ) ) {
273  unlink( $fileName );
274  } elseif ( is_dir( $fileName ) ) {
275  wfRecursiveRemoveDir( $fileName );
276  }
277  }
278 
279  if ( $this->needsDB() && $this->db ) {
280  // Clean up open transactions
281  while ( $this->db->trxLevel() > 0 ) {
282  $this->db->rollback( __METHOD__, 'flush' );
283  }
284  }
285 
286  // Restore mw globals
287  foreach ( $this->mwGlobals as $key => $value ) {
288  $GLOBALS[$key] = $value;
289  }
290  $this->mwGlobals = [];
291  $this->restoreLoggers();
294  if ( session_id() !== '' ) {
295  session_write_close();
296  session_id( '' );
297  }
298  $wgRequest = new FauxRequest();
301 
302  $phpErrorLevel = intval( ini_get( 'error_reporting' ) );
303 
304  if ( $phpErrorLevel !== $this->phpErrorLevel ) {
305  ini_set( 'error_reporting', $this->phpErrorLevel );
306 
307  $oldHex = strtoupper( dechex( $this->phpErrorLevel ) );
308  $newHex = strtoupper( dechex( $phpErrorLevel ) );
309  $message = "PHP error_reporting setting was left dirty: "
310  . "was 0x$oldHex before test, 0x$newHex after test!";
311 
312  $this->fail( $message );
313  }
314 
315  parent::tearDown();
316  }
317 
322  final public function testMediaWikiTestCaseParentSetupCalled() {
323  $this->assertArrayHasKey( 'setUp', $this->called,
324  static::class . '::setUp() must call parent::setUp()'
325  );
326  }
327 
360  protected function setMwGlobals( $pairs, $value = null ) {
361  if ( is_string( $pairs ) ) {
362  $pairs = [ $pairs => $value ];
363  }
364 
365  $this->stashMwGlobals( array_keys( $pairs ) );
366 
367  foreach ( $pairs as $key => $value ) {
368  $GLOBALS[$key] = $value;
369  }
370  }
371 
387  protected function stashMwGlobals( $globalKeys ) {
388  if ( is_string( $globalKeys ) ) {
389  $globalKeys = [ $globalKeys ];
390  }
391 
392  foreach ( $globalKeys as $globalKey ) {
393  // NOTE: make sure we only save the global once or a second call to
394  // setMwGlobals() on the same global would override the original
395  // value.
396  if ( !array_key_exists( $globalKey, $this->mwGlobals ) ) {
397  if ( !array_key_exists( $globalKey, $GLOBALS ) ) {
398  throw new Exception( "Global with key {$globalKey} doesn't exist and cant be stashed" );
399  }
400  // NOTE: we serialize then unserialize the value in case it is an object
401  // this stops any objects being passed by reference. We could use clone
402  // and if is_object but this does account for objects within objects!
403  try {
404  $this->mwGlobals[$globalKey] = unserialize( serialize( $GLOBALS[$globalKey] ) );
405  }
406  // NOTE; some things such as Closures are not serializable
407  // in this case just set the value!
408  catch ( Exception $e ) {
409  $this->mwGlobals[$globalKey] = $GLOBALS[$globalKey];
410  }
411  }
412  }
413  }
414 
427  protected function mergeMwGlobalArrayValue( $name, $values ) {
428  if ( !isset( $GLOBALS[$name] ) ) {
429  $merged = $values;
430  } else {
431  if ( !is_array( $GLOBALS[$name] ) ) {
432  throw new MWException( "MW global $name is not an array." );
433  }
434 
435  // NOTE: do not use array_merge, it screws up for numeric keys.
436  $merged = $GLOBALS[$name];
437  foreach ( $values as $k => $v ) {
438  $merged[$k] = $v;
439  }
440  }
441 
442  $this->setMwGlobals( $name, $merged );
443  }
444 
449  public function setUserLang( $lang ) {
450  RequestContext::getMain()->setLanguage( $lang );
451  $this->setMwGlobals( 'wgLang', RequestContext::getMain()->getLanguage() );
452  }
453 
458  public function setContentLang( $lang ) {
459  if ( $lang instanceof Language ) {
460  $langCode = $lang->getCode();
461  $langObj = $lang;
462  } else {
463  $langCode = $lang;
464  $langObj = Language::factory( $langCode );
465  }
466  $this->setMwGlobals( [
467  'wgLanguageCode' => $langCode,
468  'wgContLang' => $langObj,
469  ] );
470  }
471 
478  protected function setLogger( $channel, LoggerInterface $logger ) {
479  $provider = LoggerFactory::getProvider();
480  $wrappedProvider = TestingAccessWrapper::newFromObject( $provider );
481  $singletons = $wrappedProvider->singletons;
482  if ( $provider instanceof MonologSpi ) {
483  if ( !isset( $this->loggers[$channel] ) ) {
484  $this->loggers[$channel] = isset( $singletons['loggers'][$channel] )
485  ? $singletons['loggers'][$channel] : null;
486  }
487  $singletons['loggers'][$channel] = $logger;
488  } elseif ( $provider instanceof LegacySpi ) {
489  if ( !isset( $this->loggers[$channel] ) ) {
490  $this->loggers[$channel] = isset( $singletons[$channel] ) ? $singletons[$channel] : null;
491  }
492  $singletons[$channel] = $logger;
493  } else {
494  throw new LogicException( __METHOD__ . ': setting a logger for ' . get_class( $provider )
495  . ' is not implemented' );
496  }
497  $wrappedProvider->singletons = $singletons;
498  }
499 
504  private function restoreLoggers() {
505  $provider = LoggerFactory::getProvider();
506  $wrappedProvider = TestingAccessWrapper::newFromObject( $provider );
507  $singletons = $wrappedProvider->singletons;
508  foreach ( $this->loggers as $channel => $logger ) {
509  if ( $provider instanceof MonologSpi ) {
510  if ( $logger === null ) {
511  unset( $singletons['loggers'][$channel] );
512  } else {
513  $singletons['loggers'][$channel] = $logger;
514  }
515  } elseif ( $provider instanceof LegacySpi ) {
516  if ( $logger === null ) {
517  unset( $singletons[$channel] );
518  } else {
519  $singletons[$channel] = $logger;
520  }
521  }
522  }
523  $wrappedProvider->singletons = $singletons;
524  $this->loggers = [];
525  }
526 
531  public function dbPrefix() {
532  return $this->db->getType() == 'oracle' ? self::ORA_DB_PREFIX : self::DB_PREFIX;
533  }
534 
539  public function needsDB() {
540  # if the test says it uses database tables, it needs the database
541  if ( $this->tablesUsed ) {
542  return true;
543  }
544 
545  # if the test says it belongs to the Database group, it needs the database
546  $rc = new ReflectionClass( $this );
547  if ( preg_match( '/@group +Database/im', $rc->getDocComment() ) ) {
548  return true;
549  }
550 
551  return false;
552  }
553 
564  protected function insertPage( $pageName, $text = 'Sample page for unit test.' ) {
565  $title = Title::newFromText( $pageName, 0 );
566 
567  $user = User::newFromName( 'UTSysop' );
568  $comment = __METHOD__ . ': Sample page for unit test.';
569 
571  $page->doEditContent( ContentHandler::makeContent( $text, $title ), $comment, 0, false, $user );
572 
573  return [
574  'title' => $title,
575  'id' => $page->getId(),
576  ];
577  }
578 
594  public function addDBDataOnce() {
595  }
596 
606  public function addDBData() {
607  }
608 
609  private function addCoreDBData() {
610  if ( $this->db->getType() == 'oracle' ) {
611 
612  # Insert 0 user to prevent FK violations
613  # Anonymous user
614  $this->db->insert( 'user', [
615  'user_id' => 0,
616  'user_name' => 'Anonymous' ], __METHOD__, [ 'IGNORE' ] );
617 
618  # Insert 0 page to prevent FK violations
619  # Blank page
620  $this->db->insert( 'page', [
621  'page_id' => 0,
622  'page_namespace' => 0,
623  'page_title' => ' ',
624  'page_restrictions' => null,
625  'page_is_redirect' => 0,
626  'page_is_new' => 0,
627  'page_random' => 0,
628  'page_touched' => $this->db->timestamp(),
629  'page_latest' => 0,
630  'page_len' => 0 ], __METHOD__, [ 'IGNORE' ] );
631  }
632 
634 
635  // Make sysop user
636  $user = User::newFromName( 'UTSysop' );
637 
638  if ( $user->idForName() == 0 ) {
639  $user->addToDatabase();
640  TestUser::setPasswordForUser( $user, 'UTSysopPassword' );
641  $user->addGroup( 'sysop' );
642  $user->addGroup( 'bureaucrat' );
643  }
644 
645  // Make 1 page with 1 revision
646  $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
647  if ( $page->getId() == 0 ) {
648  $page->doEditContent(
649  new WikitextContent( 'UTContent' ),
650  'UTPageSummary',
651  EDIT_NEW,
652  false,
653  $user
654  );
655 
656  // doEditContent() probably started the session via
657  // User::loadFromSession(). Close it now.
658  if ( session_id() !== '' ) {
659  session_write_close();
660  session_id( '' );
661  }
662  }
663  }
664 
672  public static function teardownTestDB() {
673  global $wgJobClasses;
674 
675  if ( !self::$dbSetup ) {
676  return;
677  }
678 
679  foreach ( $wgJobClasses as $type => $class ) {
680  // Delete any jobs under the clone DB (or old prefix in other stores)
681  JobQueueGroup::singleton()->get( $type )->delete();
682  }
683 
684  CloneDatabase::changePrefix( self::$oldTablePrefix );
685 
686  self::$oldTablePrefix = false;
687  self::$dbSetup = false;
688  }
689 
703  protected static function setupDatabaseWithTestPrefix( DatabaseBase $db, $prefix ) {
704  $tablesCloned = self::listTables( $db );
705  $dbClone = new CloneDatabase( $db, $tablesCloned, $prefix );
706  $dbClone->useTemporaryTables( self::$useTemporaryTables );
707 
708  if ( ( $db->getType() == 'oracle' || !self::$useTemporaryTables ) && self::$reuseDB ) {
709  CloneDatabase::changePrefix( $prefix );
710 
711  return false;
712  } else {
713  $dbClone->cloneTableStructure();
714  return true;
715  }
716  }
717 
721  public function setupAllTestDBs() {
723 
724  self::$oldTablePrefix = $wgDBprefix;
725 
726  $testPrefix = $this->dbPrefix();
727 
728  // switch to a temporary clone of the database
729  self::setupTestDB( $this->db, $testPrefix );
730 
731  if ( self::isUsingExternalStoreDB() ) {
732  self::setupExternalStoreTestDBs( $testPrefix );
733  }
734  }
735 
757  public static function setupTestDB( DatabaseBase $db, $prefix ) {
758  if ( $db->tablePrefix() === $prefix ) {
759  throw new MWException(
760  'Cannot run unit tests, the database prefix is already "' . $prefix . '"' );
761  }
762 
763  if ( self::$dbSetup ) {
764  return;
765  }
766 
767  self::$dbSetup = true;
768 
769  if ( !self::setupDatabaseWithTestPrefix( $db, $prefix ) ) {
770  return;
771  }
772 
773  // Assuming this isn't needed for External Store database, and not sure if the procedure
774  // would be available there.
775  if ( $db->getType() == 'oracle' ) {
776  $db->query( 'BEGIN FILL_WIKI_INFO; END;' );
777  }
778  }
779 
785  protected static function setupExternalStoreTestDBs( $testPrefix ) {
786  $connections = self::getExternalStoreDatabaseConnections();
787  foreach ( $connections as $dbw ) {
788  // Hack: cloneTableStructure sets $wgDBprefix to the unit test
789  // prefix,. Even though listTables now uses tablePrefix, that
790  // itself is populated from $wgDBprefix by default.
791 
792  // We have to set it back, or we won't find the original 'blobs'
793  // table to copy.
794 
795  $dbw->tablePrefix( self::$oldTablePrefix );
796  self::setupDatabaseWithTestPrefix( $dbw, $testPrefix );
797  }
798  }
799 
807  protected static function getExternalStoreDatabaseConnections() {
809 
810  $externalStoreDB = ExternalStore::getStoreObject( 'DB' );
811  $defaultArray = (array) $wgDefaultExternalStore;
812  $dbws = [];
813  foreach ( $defaultArray as $url ) {
814  if ( strpos( $url, 'DB://' ) === 0 ) {
815  list( $proto, $cluster ) = explode( '://', $url, 2 );
816  $dbw = $externalStoreDB->getMaster( $cluster );
817  $dbws[] = $dbw;
818  }
819  }
820 
821  return $dbws;
822  }
823 
829  protected static function isUsingExternalStoreDB() {
831  if ( !$wgDefaultExternalStore ) {
832  return false;
833  }
834 
835  $defaultArray = (array) $wgDefaultExternalStore;
836  foreach ( $defaultArray as $url ) {
837  if ( strpos( $url, 'DB://' ) === 0 ) {
838  return true;
839  }
840  }
841 
842  return false;
843  }
844 
851  private function resetDB( $db, $tablesUsed ) {
852  if ( $db ) {
853  $userTables = [ 'user', 'user_groups', 'user_properties' ];
854  $coreDBDataTables = array_merge( $userTables, [ 'page', 'revision' ] );
855 
856  // If any of the user tables were marked as used, we should clear all of them.
857  if ( array_intersect( $tablesUsed, $userTables ) ) {
858  $tablesUsed = array_unique( array_merge( $tablesUsed, $userTables ) );
859 
860  // Totally clear User class in-process cache to avoid CAS errors
862  ->getInProcessCache()
863  ->clear();
864  }
865 
866  $truncate = in_array( $db->getType(), [ 'oracle', 'mysql' ] );
867  foreach ( $tablesUsed as $tbl ) {
868  // TODO: reset interwiki table to its original content.
869  if ( $tbl == 'interwiki' ) {
870  continue;
871  }
872 
873  if ( $truncate ) {
874  $db->query( 'TRUNCATE TABLE ' . $db->tableName( $tbl ), __METHOD__ );
875  } else {
876  $db->delete( $tbl, '*', __METHOD__ );
877  }
878 
879  if ( $tbl === 'page' ) {
880  // Forget about the pages since they don't
881  // exist in the DB.
882  LinkCache::singleton()->clear();
883  }
884  }
885 
886  if ( array_intersect( $tablesUsed, $coreDBDataTables ) ) {
887  // Re-add core DB data that was deleted
888  $this->addCoreDBData();
889  }
890  }
891  }
892 
902  public function __call( $func, $args ) {
903  static $compatibility = [
904  'assertEmpty' => 'assertEmpty2', // assertEmpty was added in phpunit 3.7.32
905  ];
906 
907  if ( isset( $compatibility[$func] ) ) {
908  return call_user_func_array( [ $this, $compatibility[$func] ], $args );
909  } else {
910  throw new MWException( "Called non-existent $func method on "
911  . get_class( $this ) );
912  }
913  }
914 
920  private function assertEmpty2( $value, $msg ) {
921  $this->assertTrue( $value == '', $msg );
922  }
923 
924  private static function unprefixTable( &$tableName, $ind, $prefix ) {
925  $tableName = substr( $tableName, strlen( $prefix ) );
926  }
927 
928  private static function isNotUnittest( $table ) {
929  return strpos( $table, 'unittest_' ) !== 0;
930  }
931 
939  public static function listTables( $db ) {
940  $prefix = $db->tablePrefix();
941  $tables = $db->listTables( $prefix, __METHOD__ );
942 
943  if ( $db->getType() === 'mysql' ) {
944  # bug 43571: cannot clone VIEWs under MySQL
945  $views = $db->listViews( $prefix, __METHOD__ );
946  $tables = array_diff( $tables, $views );
947  }
948  array_walk( $tables, [ __CLASS__, 'unprefixTable' ], $prefix );
949 
950  // Don't duplicate test tables from the previous fataled run
951  $tables = array_filter( $tables, [ __CLASS__, 'isNotUnittest' ] );
952 
953  if ( $db->getType() == 'sqlite' ) {
954  $tables = array_flip( $tables );
955  // these are subtables of searchindex and don't need to be duped/dropped separately
956  unset( $tables['searchindex_content'] );
957  unset( $tables['searchindex_segdir'] );
958  unset( $tables['searchindex_segments'] );
959  $tables = array_flip( $tables );
960  }
961 
962  return $tables;
963  }
964 
969  protected function checkDbIsSupported() {
970  if ( !in_array( $this->db->getType(), $this->supportedDBs ) ) {
971  throw new MWException( $this->db->getType() . " is not currently supported for unit testing." );
972  }
973  }
974 
980  public function getCliArg( $offset ) {
981  if ( isset( PHPUnitMaintClass::$additionalOptions[$offset] ) ) {
983  }
984  }
985 
991  public function setCliArg( $offset, $value ) {
993  }
994 
1002  public function hideDeprecated( $function ) {
1003  MediaWiki\suppressWarnings();
1004  wfDeprecated( $function );
1005  MediaWiki\restoreWarnings();
1006  }
1007 
1026  protected function assertSelect( $table, $fields, $condition, array $expectedRows ) {
1027  if ( !$this->needsDB() ) {
1028  throw new MWException( 'When testing database state, the test cases\'s needDB()' .
1029  ' method should return true. Use @group Database or $this->tablesUsed.' );
1030  }
1031 
1032  $db = wfGetDB( DB_SLAVE );
1033 
1034  $res = $db->select( $table, $fields, $condition, wfGetCaller(), [ 'ORDER BY' => $fields ] );
1035  $this->assertNotEmpty( $res, "query failed: " . $db->lastError() );
1036 
1037  $i = 0;
1038 
1039  foreach ( $expectedRows as $expected ) {
1040  $r = $res->fetchRow();
1041  self::stripStringKeys( $r );
1042 
1043  $i += 1;
1044  $this->assertNotEmpty( $r, "row #$i missing" );
1045 
1046  $this->assertEquals( $expected, $r, "row #$i mismatches" );
1047  }
1048 
1049  $r = $res->fetchRow();
1050  self::stripStringKeys( $r );
1051 
1052  $this->assertFalse( $r, "found extra row (after #$i)" );
1053  }
1054 
1066  protected function arrayWrap( array $elements ) {
1067  return array_map(
1068  function ( $element ) {
1069  return [ $element ];
1070  },
1071  $elements
1072  );
1073  }
1074 
1087  protected function assertArrayEquals( array $expected, array $actual,
1088  $ordered = false, $named = false
1089  ) {
1090  if ( !$ordered ) {
1091  $this->objectAssociativeSort( $expected );
1092  $this->objectAssociativeSort( $actual );
1093  }
1094 
1095  if ( !$named ) {
1096  $expected = array_values( $expected );
1097  $actual = array_values( $actual );
1098  }
1099 
1100  call_user_func_array(
1101  [ $this, 'assertEquals' ],
1102  array_merge( [ $expected, $actual ], array_slice( func_get_args(), 4 ) )
1103  );
1104  }
1105 
1118  protected function assertHTMLEquals( $expected, $actual, $msg = '' ) {
1119  $expected = str_replace( '>', ">\n", $expected );
1120  $actual = str_replace( '>', ">\n", $actual );
1121 
1122  $this->assertEquals( $expected, $actual, $msg );
1123  }
1124 
1132  protected function objectAssociativeSort( array &$array ) {
1133  uasort(
1134  $array,
1135  function ( $a, $b ) {
1136  return serialize( $a ) > serialize( $b ) ? 1 : -1;
1137  }
1138  );
1139  }
1140 
1150  protected static function stripStringKeys( &$r ) {
1151  if ( !is_array( $r ) ) {
1152  return;
1153  }
1154 
1155  foreach ( $r as $k => $v ) {
1156  if ( is_string( $k ) ) {
1157  unset( $r[$k] );
1158  }
1159  }
1160  }
1161 
1175  protected function assertTypeOrValue( $type, $actual, $value = false, $message = '' ) {
1176  if ( $actual === $value ) {
1177  $this->assertTrue( true, $message );
1178  } else {
1179  $this->assertType( $type, $actual, $message );
1180  }
1181  }
1182 
1194  protected function assertType( $type, $actual, $message = '' ) {
1195  if ( class_exists( $type ) || interface_exists( $type ) ) {
1196  $this->assertInstanceOf( $type, $actual, $message );
1197  } else {
1198  $this->assertInternalType( $type, $actual, $message );
1199  }
1200  }
1201 
1211  protected function isWikitextNS( $ns ) {
1212  global $wgNamespaceContentModels;
1213 
1214  if ( isset( $wgNamespaceContentModels[$ns] ) ) {
1215  return $wgNamespaceContentModels[$ns] === CONTENT_MODEL_WIKITEXT;
1216  }
1217 
1218  return true;
1219  }
1220 
1228  protected function getDefaultWikitextNS() {
1229  global $wgNamespaceContentModels;
1230 
1231  static $wikitextNS = null; // this is not going to change
1232  if ( $wikitextNS !== null ) {
1233  return $wikitextNS;
1234  }
1235 
1236  // quickly short out on most common case:
1237  if ( !isset( $wgNamespaceContentModels[NS_MAIN] ) ) {
1238  return NS_MAIN;
1239  }
1240 
1241  // NOTE: prefer content namespaces
1242  $namespaces = array_unique( array_merge(
1244  [ NS_MAIN, NS_HELP, NS_PROJECT ], // prefer these
1246  ) );
1247 
1248  $namespaces = array_diff( $namespaces, [
1249  NS_FILE, NS_CATEGORY, NS_MEDIAWIKI, NS_USER // don't mess with magic namespaces
1250  ] );
1251 
1252  $talk = array_filter( $namespaces, function ( $ns ) {
1253  return MWNamespace::isTalk( $ns );
1254  } );
1255 
1256  // prefer non-talk pages
1257  $namespaces = array_diff( $namespaces, $talk );
1258  $namespaces = array_merge( $namespaces, $talk );
1259 
1260  // check default content model of each namespace
1261  foreach ( $namespaces as $ns ) {
1262  if ( !isset( $wgNamespaceContentModels[$ns] ) ||
1263  $wgNamespaceContentModels[$ns] === CONTENT_MODEL_WIKITEXT
1264  ) {
1265 
1266  $wikitextNS = $ns;
1267 
1268  return $wikitextNS;
1269  }
1270  }
1271 
1272  // give up
1273  // @todo Inside a test, we could skip the test as incomplete.
1274  // But frequently, this is used in fixture setup.
1275  throw new MWException( "No namespace defaults to wikitext!" );
1276  }
1277 
1284  protected function markTestSkippedIfNoDiff3() {
1285  global $wgDiff3;
1286 
1287  # This check may also protect against code injection in
1288  # case of broken installations.
1289  MediaWiki\suppressWarnings();
1290  $haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 );
1291  MediaWiki\restoreWarnings();
1292 
1293  if ( !$haveDiff3 ) {
1294  $this->markTestSkipped( "Skip test, since diff3 is not configured" );
1295  }
1296  }
1297 
1308  protected function checkHasGzip() {
1309  static $haveGzip;
1310 
1311  if ( $haveGzip === null ) {
1312  $retval = null;
1313  wfShellExec( 'gzip -V', $retval );
1314  $haveGzip = ( $retval === 0 );
1315  }
1316 
1317  if ( !$haveGzip ) {
1318  $this->markTestSkipped( "Skip test, requires the gzip utility in PATH" );
1319  }
1320 
1321  return $haveGzip;
1322  }
1323 
1332  protected function checkPHPExtension( $extName ) {
1333  $loaded = extension_loaded( $extName );
1334  if ( !$loaded ) {
1335  $this->markTestSkipped( "PHP extension '$extName' is not loaded, skipping." );
1336  }
1337 
1338  return $loaded;
1339  }
1340 
1355  protected function assertValidHtmlSnippet( $html ) {
1356  $html = '<!DOCTYPE html><html><head><title>test</title></head><body>' . $html . '</body></html>';
1357  $this->assertValidHtmlDocument( $html );
1358  }
1359 
1371  protected function assertValidHtmlDocument( $html ) {
1372  // Note: we only validate if the tidy PHP extension is available.
1373  // In case wgTidyInternal is false, MWTidy would fall back to the command line version
1374  // of tidy. In that case however, we can not reliably detect whether a failing validation
1375  // is due to malformed HTML, or caused by tidy not being installed as a command line tool.
1376  // That would cause all HTML assertions to fail on a system that has no tidy installed.
1377  if ( !$GLOBALS['wgTidyInternal'] || !MWTidy::isEnabled() ) {
1378  $this->markTestSkipped( 'Tidy extension not installed' );
1379  }
1380 
1381  $errorBuffer = '';
1382  MWTidy::checkErrors( $html, $errorBuffer );
1383  $allErrors = preg_split( '/[\r\n]+/', $errorBuffer );
1384 
1385  // Filter Tidy warnings which aren't useful for us.
1386  // Tidy eg. often cries about parameters missing which have actually
1387  // been deprecated since HTML4, thus we should not care about them.
1388  $errors = preg_grep(
1389  '/^(.*Warning: (trimming empty|.* lacks ".*?" attribute).*|\s*)$/m',
1390  $allErrors, PREG_GREP_INVERT
1391  );
1392 
1393  $this->assertEmpty( $errors, implode( "\n", $errors ) );
1394  }
1395 
1403  private static function tagMatch( $matcher, $actual, $isHtml = true ) {
1404  $dom = PHPUnit_Util_XML::load( $actual, $isHtml );
1405  $tags = PHPUnit_Util_XML::findNodes( $dom, $matcher, $isHtml );
1406  return count( $tags ) > 0 && $tags[0] instanceof DOMNode;
1407  }
1408 
1420  public static function assertTag( $matcher, $actual, $message = '', $isHtml = true ) {
1421  // trigger_error(__METHOD__ . ' is deprecated', E_USER_DEPRECATED);
1422 
1423  self::assertTrue( self::tagMatch( $matcher, $actual, $isHtml ), $message );
1424  }
1425 
1435  public static function assertNotTag( $matcher, $actual, $message = '', $isHtml = true ) {
1436  // trigger_error(__METHOD__ . ' is deprecated', E_USER_DEPRECATED);
1437 
1438  self::assertFalse( self::tagMatch( $matcher, $actual, $isHtml ), $message );
1439  }
1440 
1445  public static function wfResetOutputBuffersBarrier( $buffer ) {
1446  return $buffer;
1447  }
1448 
1449 }
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
Definition: User.php:568
select($table, $vars, $conds= '', $fname=__METHOD__, $options=[], $join_conds=[])
Execute a SELECT query constructed using the various parameters provided.
Definition: Database.php:1230
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:99
mergeMwGlobalArrayValue($name, $values)
Merges the given values into a MW global array variable.
const DB_PREFIX
Table name prefixes.
checkPHPExtension($extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded...
static $additionalOptions
Definition: phpunit.php:20
static getMainWANInstance()
Get the main WAN cache object.
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:1798
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
LoggerInterface[] $loggers
Holds original loggers which have been replaced by setLogger()
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
static clearPendingUpdates()
Clear all pending updates without performing them.
static wfResetOutputBuffersBarrier($buffer)
Used as a marker to prevent wfResetOutputBuffers from breaking PHPUnit.
the array() calling protocol came about after MediaWiki 1.4rc1.
static assertNotTag($matcher, $actual, $message= '', $isHtml=true)
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:277
array $wgDefaultExternalStore
The place to put new revisions, false to put them in the local text table.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
Definition: hooks.txt:2321
const NS_MAIN
Definition: Defines.php:69
$called
$called tracks whether the setUp and tearDown method has been called.
tableName($name, $format= 'quoted')
Format a table name ready for use in constructing an SQL query.
Definition: Database.php:1681
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfMkdirParents($dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
Definition: hooks.txt:1932
static isEnabled()
Definition: MWTidy.php:92
assertValidHtmlDocument($html)
Asserts that the given string is valid HTML document.
if(!isset($args[0])) $lang
static isTalk($index)
Is the given namespace a talk namespace?
Definition: MWNamespace.php:97
$comment
listViews($prefix=null, $fname=__METHOD__)
Lists all the VIEWs in the database.
Definition: Database.php:2793
MediaWiki has optional support for a high distributed memory object caching system For general information on but for a larger site with heavy load
Definition: memcached.txt:1
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
run(PHPUnit_Framework_TestResult $result=null)
insertPage($pageName, $text= 'Sample page for unit test.')
Insert a new page.
static checkErrors($text, &$errorStr=null)
Check HTML for errors, used if $wgValidateAllHtml = true.
Definition: MWTidy.php:79
$value
static changePrefix($prefix)
Change the table prefix on all open DB connections/.
$files
assertType($type, $actual, $message= '')
Asserts the type of the provided value.
lastError()
Get a description of the last error.
__construct($name=null, array $data=[], $dataName= '')
static resetIdByNameCache()
Reset the cache used in idFromName().
Definition: User.php:810
wfShellExec($cmd, &$retval=null, $environ=[], $limits=[], $options=[])
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:277
static resetCache()
Resets all static caches.
static newFromClass($className)
Allow access to non-public static methods and properties of the class.
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
LoggerFactory service provider that creates loggers implemented by Monolog.
Definition: MonologSpi.php:116
getNewTempFile()
Obtains a new temporary file name.
listTables($prefix=null, $fname=__METHOD__)
List all tables on the database.
Definition: Database.php:2769
getType()
Get the type of the DBMS, as it appears in $wgDBtype.
arrayWrap(array $elements)
Utility method taking an array of elements and wrapping each element in its own array.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition: hooks.txt:965
tablePrefix($prefix=null)
Get/set the table prefix.
Definition: Database.php:235
static tagMatch($matcher, $actual, $isHtml=true)
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.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. '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 '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 '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 '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. '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 IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() '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 Sanitizer::validateEmail(), 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. '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) '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 '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. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. '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:1796
if($line===false) $args
Definition: cdb.php:64
restoreLoggers()
Restores loggers replaced by setLogger().
static BagOStuff[] $instances
Map of (id => BagOStuff)
Definition: ObjectCache.php:82
getDefaultWikitextNS()
Returns the ID of a namespace that defaults to Wikitext.
setupAllTestDBs()
Set up all test DBs.
const NS_PROJECT
Definition: Defines.php:73
static resetCache()
Reset the internal caching for unit testing.
static setPasswordForUser(User $user, $password)
Set the password on a testing user.
Definition: TestUser.php:127
wfTempDir()
Tries to get the system directory for temporary files.
static resetCache()
Reset the internal caching for unit testing.
setCliArg($offset, $value)
static getMain()
Static methods.
static singleton()
Get an instance of this class.
Definition: LinkCache.php:61
unserialize($serialized)
Definition: ApiMessage.php:102
$GLOBALS['IP']
static assertTag($matcher, $actual, $message= '', $isHtml=true)
Note: we are overriding this method to remove the deprecated error.
checkHasGzip()
Check whether we have the 'gzip' commandline utility, will skip the test whenever "gzip -V" fails...
static isNotUnittest($table)
static getStoreObject($proto, array $params=[])
Get an external store object of the given type, with the given parameters.
static teardownTestDB()
Restores MediaWiki to using the table set (table prefix) it was using before setupTestDB() was called...
static setupExternalStoreTestDBs($testPrefix)
Clones the External Store database(s) for testing.
$res
Definition: database.txt:21
objectAssociativeSort(array &$array)
Does an associative sort that works for objects.
static getExternalStoreDatabaseConnections()
Gets master database connections for all of the ExternalStoreDB stores configured in $wgDefaultExtern...
static setupTestDB(DatabaseBase $db, $prefix)
Creates an empty skeleton of the wiki database by cloning its structure to equivalent tables using th...
MediaWiki Logger MonologSpi
Definition: logger.txt:58
assertSelect($table, $fields, $condition, array $expectedRows)
Asserts that the given database query yields the rows given by $expectedRows.
const NS_CATEGORY
Definition: Defines.php:83
static resetMain()
Resets singleton returned by getMain().
wfDeprecated($function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
static getContentNamespaces()
Get a list of all namespace indices which are considered to contain content.
const DB_SLAVE
Definition: Defines.php:46
LoggerFactory service provider that creates LegacyLogger instances.
Definition: LegacySpi.php:38
$buffer
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
hideDeprecated($function)
Don't throw a warning if $function is deprecated and called later.
const NS_FILE
Definition: Defines.php:75
static makeContent($text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Content object for wiki text pages.
namespace and then decline to actually register it & $namespaces
Definition: hooks.txt:912
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
static isUsingExternalStoreDB()
Check whether ExternalStoreDB is being used.
const NS_MEDIAWIKI
Definition: Defines.php:77
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 local account $user
Definition: hooks.txt:242
array $mwGlobals
Holds original values of MediaWiki configuration settings to be restored in tearDown().
static TestUser[] $users
assertTypeOrValue($type, $actual, $value=false, $message= '')
Asserts that the provided variable is of the specified internal type or equals the $value argument...
static singleton($wiki=false)
Database abstraction object.
Definition: Database.php:32
int $phpErrorLevel
Original value of PHP's error_reporting setting.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
or there are no hooks to run
Definition: hooks.txt:223
MediaWiki Logger LegacySpi
Definition: logger.txt:53
const NS_HELP
Definition: Defines.php:81
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
const EDIT_NEW
Definition: Defines.php:179
markTestSkippedIfNoDiff3()
Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped, if not ready.
DatabaseBase $db
Primary database.
$wgDBprefix
Table name prefix.
isWikitextNS($ns)
Returns true if the given namespace defaults to Wikitext according to $wgNamespaceContentModels.
query($sql, $fname=__METHOD__, $tempIgnore=false)
Run an SQL query and return the result.
Definition: Database.php:780
wfRecursiveRemoveDir($dir)
Remove a directory and all its content.
static unprefixTable(&$tableName, $ind, $prefix)
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1004
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method.MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances.The"Spi"in MediaWiki\Logger\Spi stands for"service provider interface".An SPI is an API intended to be implemented or extended by a third party.This software design pattern is intended to enable framework extension and replaceable components.It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki.The service provider interface allows the backend logging library to be implemented in multiple ways.The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime.This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance.Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
Definition: logger.txt:5
getNewTempDirectory()
obtains a new temporary directory
const DB_MASTER
Definition: Defines.php:47
array $tmpFiles
Holds the paths of temporary files/directories created through getNewTempFile, and getNewTempDirector...
serialize()
Definition: ApiMessage.php:94
static newFromObject($object)
Return the same object, without access restrictions.
static factory($code)
Get a cached or new language object for a given language code.
Definition: Language.php:179
setMwGlobals($pairs, $value=null)
static getValidNamespaces()
Returns an array of the namespaces (by integer id) that exist on the wiki.
delete($table, $conds, $fname=__METHOD__)
DELETE query wrapper.
Definition: Database.php:2241
setLogger($channel, LoggerInterface $logger)
Sets the logger for a specified channel, for the duration of the test.
static setupDatabaseWithTestPrefix(DatabaseBase $db, $prefix)
Setups a database with the given prefix.
assertEmpty2($value, $msg)
Used as a compatibility method for phpunit < 3.7.32.
assertHTMLEquals($expected, $actual, $msg= '')
Put each HTML element on its own line and then equals() the results.
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 local account incomplete not yet checked for validity & $retval
Definition: hooks.txt:242
if(is_null($wgLocalTZoffset)) if(!$wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:657
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2338
static stripStringKeys(&$r)
Utility function for eliminating all string keys from an array.
stashMwGlobals($globalKeys)
Stashes the global, will be restored in tearDown()
wfGetCaller($level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...
resetDB($db, $tablesUsed)
Empty all tables so they can be repopulated for tests.
const CACHE_DB
Definition: Defines.php:103
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2338
testMediaWikiTestCaseParentSetupCalled()
Make sure MediaWikiTestCase extending classes have called their parent setUp method.
assertValidHtmlSnippet($html)
Asserts that the given string is a valid HTML snippet.
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:310