3 use MediaWiki\Page\DeletePage
;
4 use MediaWiki\Request\WebRequest
;
5 use MediaWiki\Title\Title
;
11 class JobRunnerTest
extends MediaWikiIntegrationTestCase
{
26 private $deletePageJob;
28 protected function setUp(): void
{
31 $str = wfRandomString( 10 );
32 $this->page
= $this->insertPage( $str )['title'];
34 $this->assertTrue( $this->page
->exists(), 'The created page exists' );
36 $this->jobRunner
= $this->getServiceContainer()->getJobRunner();
38 'namespace' => $this->page
->getNamespace(),
39 'title' => $this->page
->getDBkey(),
40 'wikiPageId' => $this->page
->getArticleID(),
41 'requestId' => WebRequest
::getRequestId(),
42 'reason' => 'Testing delete job',
44 'userId' => $this->getTestUser()->getUser()->getId(),
45 'tags' => json_encode( [] ),
46 'logsubtype' => 'delete',
47 'pageRole' => DeletePage
::PAGE_BASE
,
49 $this->deletePageJob
= new DeletePageJob( $jobParams );
53 * @dataProvider provideTestRun
55 public function testRun( $options, $expectedVal ) {
56 $this->getServiceContainer()->getJobQueueGroup()->push( $this->deletePageJob
);
58 $results = $this->jobRunner
->run( $options );
60 $this->assertEquals( $expectedVal, $results['reached'] );
63 public static function provideTestRun() {
66 [ [ 'type' => true ], 'none-possible' ],
67 [ [ 'maxJobs' => 1 ], 'job-limit' ],
68 [ [ 'maxTime' => -1 ], 'time-limit' ],
69 [ [ 'type' => 'deletePage', 'throttle' => false ], 'none-ready' ]
73 public function testExecuteJob() {
74 $results = $this->jobRunner
->executeJob( $this->deletePageJob
);
76 $this->assertIsInt( $results['timeMs'] );
77 $this->assertTrue( $results['status'] );
78 $this->assertIsArray( $results['caught'] );
79 $this->assertNull( $results['error'] );
81 $this->assertTrue( $this->page
->hasDeletedEdits() );