2023-01-12 13:17:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use MediaWiki\JobQueue\JobFactory;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-01-12 13:17:43 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Addshore
|
2024-02-16 18:04:47 +00:00
|
|
|
* @covers \MediaWiki\JobQueue\JobFactory
|
2023-01-12 13:17:43 +00:00
|
|
|
*/
|
|
|
|
|
class JobFactoryTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideTestNewJob
|
|
|
|
|
*/
|
|
|
|
|
public function testNewJob( $handler, $expectedClass ) {
|
|
|
|
|
$specs = [
|
|
|
|
|
'testdummy' => $handler
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$factory = new JobFactory(
|
|
|
|
|
$this->getServiceContainer()->getObjectFactory(),
|
|
|
|
|
$specs
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$job = $factory->newJob( 'testdummy', Title::newMainPage(), [] );
|
|
|
|
|
$this->assertInstanceOf( $expectedClass, $job );
|
|
|
|
|
|
|
|
|
|
$job2 = $factory->newJob( 'testdummy', [] );
|
|
|
|
|
$this->assertInstanceOf( $expectedClass, $job2 );
|
|
|
|
|
$this->assertNotSame( $job, $job2, 'should not reuse instance' );
|
|
|
|
|
|
|
|
|
|
$job3 = $factory->newJob( 'testdummy', [ 'namespace' => NS_MAIN, 'title' => 'JobTestTitle' ] );
|
|
|
|
|
$this->assertInstanceOf( $expectedClass, $job3 );
|
|
|
|
|
$this->assertNotSame( $job, $job3, 'should not reuse instance' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideTestNewJob() {
|
|
|
|
|
return [
|
|
|
|
|
'class name, no title' => [ 'NullJob', NullJob::class ],
|
|
|
|
|
'class name with title' => [ DeleteLinksJob::class, DeleteLinksJob::class ],
|
|
|
|
|
'closure' => [ static function ( Title $title, array $params ) {
|
|
|
|
|
return new NullJob( $params );
|
|
|
|
|
}, NullJob::class ],
|
|
|
|
|
'function' => [ [ $this, 'newNullJob' ], NullJob::class ],
|
|
|
|
|
'object spec, no title' => [ [ 'class' => 'NullJob' ], NullJob::class ],
|
|
|
|
|
'object spec with title' => [ [ 'class' => DeleteLinksJob::class ], DeleteLinksJob::class ],
|
|
|
|
|
'object spec with no title and not subclass of GenericParameterJob' => [
|
|
|
|
|
[
|
|
|
|
|
'class' => ParsoidCachePrewarmJob::class,
|
|
|
|
|
'services' => [
|
2024-05-16 20:15:16 +00:00
|
|
|
'ParserOutputAccess',
|
2023-01-12 13:17:43 +00:00
|
|
|
'PageStore',
|
2024-05-22 14:08:45 +00:00
|
|
|
'RevisionLookup',
|
|
|
|
|
'ParsoidSiteConfig',
|
2023-01-12 13:17:43 +00:00
|
|
|
],
|
|
|
|
|
'needsPage' => false
|
|
|
|
|
],
|
|
|
|
|
ParsoidCachePrewarmJob::class
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function newNullJob( Title $title, array $params ) {
|
|
|
|
|
return new NullJob( $params );
|
|
|
|
|
}
|
|
|
|
|
}
|