Merge "SECURITY: Do not allow users to undelete a page they can't edit or create"
[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 $requestId = 'requestId=' . WebRequest::getRequestId();
27
28 return [
29 [
30 $this->getMockJob( false ),
31 'someCommand ' . $requestId
32 ],
33 [
34 $this->getMockJob( [ 'key' => 'val' ] ),
35 'someCommand key=val ' . $requestId
36 ],
37 [
38 $this->getMockJob( [ 'key' => [ 'inkey' => 'inval' ] ] ),
39 'someCommand key={"inkey":"inval"} ' . $requestId
40 ],
41 [
42 $this->getMockJob( [ 'val1' ] ),
43 'someCommand 0=val1 ' . $requestId
44 ],
45 [
46 $this->getMockJob( [ 'val1', 'val2' ] ),
47 'someCommand 0=val1 1=val2 ' . $requestId
48 ],
49 [
50 $this->getMockJob( [ new stdClass() ] ),
51 'someCommand 0=object(stdClass) ' . $requestId
52 ],
53 [
54 $this->getMockJob( [ $mockToStringObj ] ),
55 'someCommand 0={STRING_OBJ_VAL} ' . $requestId
56 ],
57 [
58 $this->getMockJob( [
59 "pages" => [
60 "932737" => [
61 0,
62 "Robert_James_Waller"
63 ]
64 ],
65 "rootJobSignature" => "45868e99bba89064e4483743ebb9b682ef95c1a7",
66 "rootJobTimestamp" => "20160309110158",
67 "masterPos" => [
68 "file" => "db1023-bin.001288",
69 "pos" => "308257743",
70 "asOfTime" => 1457521464.3814
71 ],
72 "triggeredRecursive" => true
73 ] ),
74 'someCommand pages={"932737":[0,"Robert_James_Waller"]} ' .
75 'rootJobSignature=45868e99bba89064e4483743ebb9b682ef95c1a7 ' .
76 'rootJobTimestamp=20160309110158 masterPos=' .
77 '{"file":"db1023-bin.001288","pos":"308257743","asOfTime":1457521464.3814} ' .
78 'triggeredRecursive=1 ' .
79 $requestId
80 ],
81 ];
82 }
83
84 public function getMockJob( $params ) {
85 $mock = $this->getMockForAbstractClass(
86 'Job',
87 [ 'someCommand', new Title(), $params ],
88 'SomeJob'
89 );
90 return $mock;
91 }
92
93 }