Merge "Use Diffusion for default Git Viewer"
[lhc/web/wiklou.git] / tests / phpunit / includes / jobqueue / JobTest.php
1 <?php
2
3 /**
4 * @author Addshore
5 */
6 class JobTest extends MediaWikiTestCase {
7
8 /**
9 * @dataProvider provideTestToString
10 *
11 * @param Job $job
12 * @param string $expected
13 *
14 * @covers Job::toString
15 */
16 public function testToString( $job, $expected ) {
17 $this->assertEquals( $expected, $job->toString() );
18 }
19
20 public function provideTestToString() {
21 $mockToStringObj = $this->getMock( 'stdClass', [ '__toString' ] );
22 $mockToStringObj->expects( $this->any() )
23 ->method( '__toString' )
24 ->will( $this->returnValue( '{STRING_OBJ_VAL}' ) );
25
26 return [
27 [
28 $this->getMockJob( false ),
29 'someCommand '
30 ],
31 [
32 $this->getMockJob( [ 'key' => 'val' ] ),
33 'someCommand key=val'
34 ],
35 [
36 $this->getMockJob( [ 'key' => [ 'inkey' => 'inval' ] ] ),
37 'someCommand key={"inkey":"inval"}'
38 ],
39 [
40 $this->getMockJob( [ 'val1' ] ),
41 'someCommand 0=val1'
42 ],
43 [
44 $this->getMockJob( [ 'val1', 'val2' ] ),
45 'someCommand 0=val1 1=val2'
46 ],
47 [
48 $this->getMockJob( [ new stdClass() ] ),
49 'someCommand 0=object(stdClass)'
50 ],
51 [
52 $this->getMockJob( [ $mockToStringObj ] ),
53 'someCommand 0={STRING_OBJ_VAL}'
54 ],
55 [
56 $this->getMockJob( [
57 "pages" => [
58 "932737" => [
59 0,
60 "Robert_James_Waller"
61 ]
62 ],
63 "rootJobSignature" => "45868e99bba89064e4483743ebb9b682ef95c1a7",
64 "rootJobTimestamp" => "20160309110158",
65 "masterPos" => [
66 "file" => "db1023-bin.001288",
67 "pos" => "308257743",
68 "asOfTime" => 1457521464.3814
69 ],
70 "triggeredRecursive" => true
71 ] ),
72 'someCommand pages={"932737":[0,"Robert_James_Waller"]} ' .
73 'rootJobSignature=45868e99bba89064e4483743ebb9b682ef95c1a7 ' .
74 'rootJobTimestamp=20160309110158 masterPos=' .
75 '{"file":"db1023-bin.001288","pos":"308257743","asOfTime":1457521464.3814} ' .
76 'triggeredRecursive=1'
77 ],
78 ];
79 }
80
81 public function getMockJob( $params ) {
82 $mock = $this->getMockForAbstractClass(
83 'Job',
84 [ 'someCommand', new Title(), $params ],
85 'SomeJob'
86 );
87 return $mock;
88 }
89
90 }