Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / ShowJobsTest.php
blob49530d8983db542d2f28e4d7ca30c11f5b77c5a5
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use MediaWiki\Http\Telemetry;
6 use NullJob;
7 use ShowJobs;
9 /**
10 * @covers \ShowJobs
11 * @group Database
12 * @author Dreamy Jazz
14 class ShowJobsTest extends MaintenanceBaseTestCase {
15 public function getMaintenanceClass() {
16 return ShowJobs::class;
19 private function commonTestExecute( $options, $expectedOutputRegex ) {
20 foreach ( $options as $name => $value ) {
21 $this->maintenance->setOption( $name, $value );
23 $this->maintenance->execute();
24 // Check that the script returns the right output
25 $this->expectOutputRegex( $expectedOutputRegex );
28 public function testExecuteWithNoOptionsSpecified() {
29 $jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup();
30 $jobQueueGroup->push( new NullJob( [] ) );
31 $jobQueueGroup->push( new NullJob( [] ) );
32 $this->commonTestExecute( [], '/2/' );
35 /** @dataProvider provideJobCount */
36 public function testExecuteWithForListSpecified( int $jobCount ) {
37 $jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup();
38 $expectedRegexOutput = '/';
39 for ( $i = 0; $i < $jobCount; $i++ ) {
40 $jobQueueGroup->push( new NullJob( [] ) );
41 $expectedRegexOutput .= '.*null.*' . Telemetry::getInstance()->getRequestId() . ".*\n";
43 $this->commonTestExecute( [ 'list' => 1 ], $expectedRegexOutput . '/' );
46 public function testExecuteWithForListSpecifiedWithLimit() {
47 $jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup();
48 for ( $i = 0; $i < 5; $i++ ) {
49 $jobQueueGroup->push( new NullJob( [] ) );
51 $expectedRegexOutput = '/';
52 for ( $i = 0; $i < 4; $i++ ) {
53 $expectedRegexOutput .= '.*null.*' . Telemetry::getInstance()->getRequestId() . ".*\n";
55 $this->commonTestExecute( [ 'list' => 1, 'limit' => 4 ], $expectedRegexOutput . '/' );
58 public function testExecuteWithTypeSpecified() {
59 $jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup();
61 for ( $i = 0; $i < 3; $i++ ) {
62 $jobQueueGroup->push( new NullJob( [] ) );
65 $this->commonTestExecute( [ 'list' => 1, 'type' => 'fish' ], '//' );
68 /** @dataProvider provideJobCount */
69 public function testExecuteWithForGroupSpecified( int $jobCount ) {
70 $jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup();
71 for ( $i = 0; $i < $jobCount; $i++ ) {
72 $jobQueueGroup->push( new NullJob( [] ) );
74 $this->commonTestExecute( [ 'group' => 1 ], "/.*null.*$jobCount queued.*\n/" );
77 public static function provideJobCount() {
78 return [
79 '1 job' => [ 1 ],
80 '3 jobs' => [ 3 ],