Just methods where adding "static" to the declaration was enough, I didn't do anything with providers that used $this. Initially by search and replace. There were many mistakes which I found mostly by running the PHPStorm inspection which searches for $this usage in a static method. Later I used the PHPStorm "make static" action which avoids the more obvious mistakes. Bug: T332865 Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
84 lines
2 KiB
PHP
84 lines
2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Page\DeletePage;
|
|
use MediaWiki\Title\Title;
|
|
|
|
/**
|
|
* 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 = $this->getServiceContainer()->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 ) {
|
|
$this->getServiceContainer()->getJobQueueGroup()->push( $this->deletePageJob );
|
|
|
|
$results = $this->jobRunner->run( $options );
|
|
|
|
$this->assertEquals( $expectedVal, $results['reached'] );
|
|
}
|
|
|
|
public static 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() );
|
|
}
|
|
}
|