| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\JobQueue\JobFactory; |
| 4 |
use MediaWiki\Title\Title; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class JobFactoryTest extends MediaWikiIntegrationTestCase { |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
public function testNewJob( $handler, $expectedClass ) { |
| 16 |
$specs = [ |
| 17 |
'testdummy' => $handler |
| 18 |
]; |
| 19 |
|
| 20 |
$factory = new JobFactory( |
| 21 |
$this->getServiceContainer()->getObjectFactory(), |
| 22 |
$specs |
| 23 |
); |
| 24 |
|
| 25 |
$job = $factory->newJob( 'testdummy', Title::newMainPage(), [] ); |
| 26 |
$this->assertInstanceOf( $expectedClass, $job ); |
| 27 |
|
| 28 |
$job2 = $factory->newJob( 'testdummy', [] ); |
| 29 |
$this->assertInstanceOf( $expectedClass, $job2 ); |
| 30 |
$this->assertNotSame( $job, $job2, 'should not reuse instance' ); |
| 31 |
|
| 32 |
$job3 = $factory->newJob( 'testdummy', [ 'namespace' => NS_MAIN, 'title' => 'JobTestTitle' ] ); |
| 33 |
$this->assertInstanceOf( $expectedClass, $job3 ); |
| 34 |
$this->assertNotSame( $job, $job3, 'should not reuse instance' ); |
| 35 |
} |
| 36 |
|
| 37 |
public function provideTestNewJob() { |
| 38 |
return [ |
| 39 |
'class name, no title' => [ 'NullJob', NullJob::class ], |
| 40 |
'class name with title' => [ DeleteLinksJob::class, DeleteLinksJob::class ], |
| 41 |
'closure' => [ static function ( Title $title, array $params ) { |
| 42 |
return new NullJob( $params ); |
| 43 |
}, NullJob::class ], |
| 44 |
'function' => [ [ $this, 'newNullJob' ], NullJob::class ], |
| 45 |
'object spec, no title' => [ [ 'class' => 'NullJob' ], NullJob::class ], |
| 46 |
'object spec with title' => [ [ 'class' => DeleteLinksJob::class ], DeleteLinksJob::class ], |
| 47 |
'object spec with no title and not subclass of GenericParameterJob' => [ |
| 48 |
[ |
| 49 |
'class' => ParsoidCachePrewarmJob::class, |
| 50 |
'services' => [ |
| 51 |
'ParserOutputAccess', |
| 52 |
'PageStore', |
| 53 |
'RevisionLookup', |
| 54 |
'ParsoidSiteConfig', |
| 55 |
], |
| 56 |
'needsPage' => false |
| 57 |
], |
| 58 |
ParsoidCachePrewarmJob::class |
| 59 |
] |
| 60 |
]; |
| 61 |
} |
| 62 |
|
| 63 |
public function newNullJob( Title $title, array $params ) { |
| 64 |
return new NullJob( $params ); |
| 65 |
} |
| 66 |
} |