In retrospect, I rushed the previous patch: we really need a way to tell which deletion an ID belong to (and whether it was scheduled). So make both result getters return an array with known keys that can be used programmatically. Right now the class can only delete a single page, and thus there's a single constant and this change is effectively a noop. The deletionWasScheduled() method, introduced in 1.37, was hard-deprecated out of an abundance of caution. There are no known uses on codesearch, so it can probably just be removed in the next release. Also reorder constructor params to DeletePage -- BacklinkCacheFactory is a service injected by the factory, hence it shouldn't be grouped together with value objects injected by the caller. Change-Id: I32679b7cacc638ec3e9dc5b8dfe9bcc794b22ecf
84 lines
2 KiB
PHP
84 lines
2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
use MediaWiki\Page\DeletePage;
|
|
|
|
/**
|
|
* Class JobRunnerTest
|
|
*
|
|
* @group Database
|
|
* @covers JobRunner
|
|
*/
|
|
class JobRunnerTest extends MediaWikiIntegrationTestCase {
|
|
|
|
/**
|
|
* @var Title
|
|
*/
|
|
private $page;
|
|
|
|
/**
|
|
* @var JobRunner
|
|
*/
|
|
private $jobRunner;
|
|
|
|
/**
|
|
* @var DeletePageJob
|
|
*/
|
|
private $deletePageJob;
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
|
|
$str = wfRandomString( 10 );
|
|
$this->page = $this->insertPage( $str )['title'];
|
|
|
|
$this->assertTrue( $this->page->exists(), 'The created page exists' );
|
|
|
|
$this->jobRunner = MediaWikiServices::getInstance()->getJobRunner();
|
|
$jobParams = [
|
|
'namespace' => $this->page->getNamespace(),
|
|
'title' => $this->page->getDBkey(),
|
|
'wikiPageId' => $this->page->getArticleID(),
|
|
'requestId' => WebRequest::getRequestId(),
|
|
'reason' => 'Testing delete job',
|
|
'suppress' => false,
|
|
'userId' => $this->getTestUser()->getUser()->getId(),
|
|
'tags' => json_encode( [] ),
|
|
'logsubtype' => 'delete',
|
|
'pageRole' => DeletePage::PAGE_BASE,
|
|
];
|
|
$this->deletePageJob = new DeletePageJob( $jobParams );
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideTestRun
|
|
*/
|
|
public function testRun( $options, $expectedVal ) {
|
|
JobQueueGroup::singleton()->push( $this->deletePageJob );
|
|
|
|
$results = $this->jobRunner->run( $options );
|
|
|
|
$this->assertEquals( $results['reached'], $expectedVal );
|
|
}
|
|
|
|
public function provideTestRun() {
|
|
return [
|
|
[ [], 'none-ready' ],
|
|
[ [ 'type' => true ], 'none-possible' ],
|
|
[ [ 'maxJobs' => 1 ], 'job-limit' ],
|
|
[ [ 'maxTime' => -1 ], 'time-limit' ],
|
|
[ [ 'type' => 'deletePage', 'throttle' => false ], 'none-ready' ]
|
|
];
|
|
}
|
|
|
|
public function testExecuteJob() {
|
|
$results = $this->jobRunner->executeJob( $this->deletePageJob );
|
|
|
|
$this->assertIsInt( $results['timeMs'] );
|
|
$this->assertTrue( $results['status'] );
|
|
$this->assertIsArray( $results['caught'] );
|
|
$this->assertNull( $results['error'] );
|
|
|
|
$this->assertTrue( $this->page->hasDeletedEdits() );
|
|
}
|
|
}
|