2016-01-14 11:59:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
2019-05-31 23:24:56 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-02-23 20:44:38 +00:00
|
|
|
use MediaWiki\WikiMap\WikiMap;
|
2019-05-31 23:24:56 +00:00
|
|
|
|
2016-01-14 11:59:23 +00:00
|
|
|
/**
|
2024-02-16 18:04:47 +00:00
|
|
|
* @covers \JobQueueMemory
|
2016-01-14 11:59:23 +00:00
|
|
|
*
|
|
|
|
|
* @group JobQueue
|
|
|
|
|
*
|
2018-05-23 23:23:42 +00:00
|
|
|
* @license GPL-2.0-or-later
|
2017-11-14 12:59:15 +00:00
|
|
|
* @author Thiemo Kreuz
|
2016-01-14 11:59:23 +00:00
|
|
|
*/
|
2018-02-17 12:29:13 +00:00
|
|
|
class JobQueueMemoryTest extends PHPUnit\Framework\TestCase {
|
2016-01-14 11:59:23 +00:00
|
|
|
|
2017-12-29 23:22:37 +00:00
|
|
|
use MediaWikiCoversValidator;
|
|
|
|
|
|
2016-01-15 09:28:30 +00:00
|
|
|
/**
|
|
|
|
|
* @return JobQueueMemory
|
|
|
|
|
*/
|
|
|
|
|
private function newJobQueue() {
|
2019-05-31 23:24:56 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return JobQueue::factory( [
|
2018-01-13 00:02:09 +00:00
|
|
|
'class' => JobQueueMemory::class,
|
2019-03-28 22:37:52 +00:00
|
|
|
'domain' => WikiMap::getCurrentWikiDbDomain()->getId(),
|
2016-01-15 09:28:30 +00:00
|
|
|
'type' => 'null',
|
2019-05-31 23:24:56 +00:00
|
|
|
'idGenerator' => $services->getGlobalIdGenerator(),
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2016-01-14 11:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-15 09:28:30 +00:00
|
|
|
private function newJobSpecification() {
|
|
|
|
|
return new JobSpecification(
|
|
|
|
|
'null',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'customParameter' => null ],
|
|
|
|
|
[],
|
2022-07-05 22:21:30 +00:00
|
|
|
Title::makeTitle( NS_MAIN, 'Custom title' )
|
2016-01-15 09:28:30 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetAllQueuedJobs() {
|
|
|
|
|
$queue = $this->newJobQueue();
|
|
|
|
|
$this->assertCount( 0, $queue->getAllQueuedJobs() );
|
2016-01-14 11:59:23 +00:00
|
|
|
|
2016-01-15 09:28:30 +00:00
|
|
|
$queue->push( $this->newJobSpecification() );
|
|
|
|
|
$this->assertCount( 1, $queue->getAllQueuedJobs() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetAllAcquiredJobs() {
|
|
|
|
|
$queue = $this->newJobQueue();
|
|
|
|
|
$this->assertCount( 0, $queue->getAllAcquiredJobs() );
|
|
|
|
|
|
|
|
|
|
$queue->push( $this->newJobSpecification() );
|
|
|
|
|
$this->assertCount( 0, $queue->getAllAcquiredJobs() );
|
|
|
|
|
|
|
|
|
|
$queue->pop();
|
|
|
|
|
$this->assertCount( 1, $queue->getAllAcquiredJobs() );
|
|
|
|
|
}
|
2016-01-14 11:59:23 +00:00
|
|
|
|
2016-01-15 09:28:30 +00:00
|
|
|
public function testJobFromSpecInternal() {
|
|
|
|
|
$queue = $this->newJobQueue();
|
|
|
|
|
$job = $queue->jobFromSpecInternal( $this->newJobSpecification() );
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->assertInstanceOf( Job::class, $job );
|
2016-01-15 09:28:30 +00:00
|
|
|
$this->assertSame( 'null', $job->getType() );
|
|
|
|
|
$this->assertArrayHasKey( 'customParameter', $job->getParams() );
|
|
|
|
|
$this->assertSame( 'Custom title', $job->getTitle()->getText() );
|
2016-01-14 11:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|