Merge "docs: Fix typo"
[mediawiki.git] / tests / phpunit / includes / jobqueue / JobRunnerTest.php
blob2d1334fd8319e00012b80be3a52b1e7346196375
1 <?php
3 use MediaWiki\Page\DeletePage;
4 use MediaWiki\Request\WebRequest;
5 use MediaWiki\Title\Title;
7 /**
8 * @group Database
9 * @covers \JobRunner
11 class JobRunnerTest extends MediaWikiIntegrationTestCase {
13 /**
14 * @var Title
16 private $page;
18 /**
19 * @var JobRunner
21 private $jobRunner;
23 /**
24 * @var DeletePageJob
26 private $deletePageJob;
28 protected function setUp(): void {
29 parent::setUp();
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();
37 $jobParams = [
38 'namespace' => $this->page->getNamespace(),
39 'title' => $this->page->getDBkey(),
40 'wikiPageId' => $this->page->getArticleID(),
41 'requestId' => WebRequest::getRequestId(),
42 'reason' => 'Testing delete job',
43 'suppress' => false,
44 'userId' => $this->getTestUser()->getUser()->getId(),
45 'tags' => json_encode( [] ),
46 'logsubtype' => 'delete',
47 'pageRole' => DeletePage::PAGE_BASE,
49 $this->deletePageJob = new DeletePageJob( $jobParams );
52 /**
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() {
64 return [
65 [ [], 'none-ready' ],
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() );