Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / jobqueue / JobQueueMemoryTest.php
blob6786eb2e2e4eebc3aae2ec1e96807f8e3c48962f
1 <?php
3 use MediaWiki\MediaWikiServices;
4 use MediaWiki\Title\Title;
5 use MediaWiki\WikiMap\WikiMap;
7 /**
8 * @covers \JobQueueMemory
10 * @group JobQueue
12 * @license GPL-2.0-or-later
13 * @author Thiemo Kreuz
15 class JobQueueMemoryTest extends PHPUnit\Framework\TestCase {
17 use MediaWikiCoversValidator;
19 /**
20 * @return JobQueueMemory
22 private function newJobQueue() {
23 $services = MediaWikiServices::getInstance();
25 return JobQueue::factory( [
26 'class' => JobQueueMemory::class,
27 'domain' => WikiMap::getCurrentWikiDbDomain()->getId(),
28 'type' => 'null',
29 'idGenerator' => $services->getGlobalIdGenerator(),
30 ] );
33 private function newJobSpecification() {
34 return new JobSpecification(
35 'null',
36 [ 'customParameter' => null ],
37 [],
38 Title::makeTitle( NS_MAIN, 'Custom title' )
42 public function testGetAllQueuedJobs() {
43 $queue = $this->newJobQueue();
44 $this->assertCount( 0, $queue->getAllQueuedJobs() );
46 $queue->push( $this->newJobSpecification() );
47 $this->assertCount( 1, $queue->getAllQueuedJobs() );
50 public function testGetAllAcquiredJobs() {
51 $queue = $this->newJobQueue();
52 $this->assertCount( 0, $queue->getAllAcquiredJobs() );
54 $queue->push( $this->newJobSpecification() );
55 $this->assertCount( 0, $queue->getAllAcquiredJobs() );
57 $queue->pop();
58 $this->assertCount( 1, $queue->getAllAcquiredJobs() );
61 public function testJobFromSpecInternal() {
62 $queue = $this->newJobQueue();
63 $job = $queue->jobFromSpecInternal( $this->newJobSpecification() );
64 $this->assertInstanceOf( Job::class, $job );
65 $this->assertSame( 'null', $job->getType() );
66 $this->assertArrayHasKey( 'customParameter', $job->getParams() );
67 $this->assertSame( 'Custom title', $job->getTitle()->getText() );