]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - tests/phpunit/includes/jobqueue/JobQueueMemoryTest.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.git] / tests / phpunit / includes / jobqueue / JobQueueMemoryTest.php
1 <?php
2
3 /**
4  * @covers JobQueueMemory
5  *
6  * @group JobQueue
7  *
8  * @licence GNU GPL v2+
9  * @author Thiemo Mättig
10  */
11 class JobQueueMemoryTest extends PHPUnit_Framework_TestCase {
12
13         /**
14          * @return JobQueueMemory
15          */
16         private function newJobQueue() {
17                 return JobQueue::factory( [
18                         'class' => 'JobQueueMemory',
19                         'wiki' => wfWikiID(),
20                         'type' => 'null',
21                 ] );
22         }
23
24         private function newJobSpecification() {
25                 return new JobSpecification(
26                         'null',
27                         [ 'customParameter' => null ],
28                         [],
29                         Title::newFromText( 'Custom title' )
30                 );
31         }
32
33         public function testGetAllQueuedJobs() {
34                 $queue = $this->newJobQueue();
35                 $this->assertCount( 0, $queue->getAllQueuedJobs() );
36
37                 $queue->push( $this->newJobSpecification() );
38                 $this->assertCount( 1, $queue->getAllQueuedJobs() );
39         }
40
41         public function testGetAllAcquiredJobs() {
42                 $queue = $this->newJobQueue();
43                 $this->assertCount( 0, $queue->getAllAcquiredJobs() );
44
45                 $queue->push( $this->newJobSpecification() );
46                 $this->assertCount( 0, $queue->getAllAcquiredJobs() );
47
48                 $queue->pop();
49                 $this->assertCount( 1, $queue->getAllAcquiredJobs() );
50         }
51
52         public function testJobFromSpecInternal() {
53                 $queue = $this->newJobQueue();
54                 $job = $queue->jobFromSpecInternal( $this->newJobSpecification() );
55                 $this->assertInstanceOf( 'Job', $job );
56                 $this->assertSame( 'null', $job->getType() );
57                 $this->assertArrayHasKey( 'customParameter', $job->getParams() );
58                 $this->assertSame( 'Custom title', $job->getTitle()->getText() );
59         }
60
61 }