MediaWiki  REL1_31
ArrayDiffFormatterTest.php
Go to the documentation of this file.
1 <?php
2 
9 
16  public function testFormat( $input, $expectedOutput ) {
17  $instance = new ArrayDiffFormatter();
18  $output = $instance->format( $input );
19  $this->assertEquals( $expectedOutput, $output );
20  }
21 
22  private function getMockDiff( $edits ) {
23  $diff = $this->getMockBuilder( Diff::class )
24  ->disableOriginalConstructor()
25  ->getMock();
26  $diff->expects( $this->any() )
27  ->method( 'getEdits' )
28  ->will( $this->returnValue( $edits ) );
29  return $diff;
30  }
31 
32  private function getMockDiffOp( $type = null, $orig = [], $closing = [] ) {
33  $diffOp = $this->getMockBuilder( DiffOp::class )
34  ->disableOriginalConstructor()
35  ->getMock();
36  $diffOp->expects( $this->any() )
37  ->method( 'getType' )
38  ->will( $this->returnValue( $type ) );
39  $diffOp->expects( $this->any() )
40  ->method( 'getOrig' )
41  ->will( $this->returnValue( $orig ) );
42  if ( $type === 'change' ) {
43  $diffOp->expects( $this->any() )
44  ->method( 'getClosing' )
45  ->with( $this->isType( 'integer' ) )
46  ->will( $this->returnCallback( function () {
47  return 'mockLine';
48  } ) );
49  } else {
50  $diffOp->expects( $this->any() )
51  ->method( 'getClosing' )
52  ->will( $this->returnValue( $closing ) );
53  }
54  return $diffOp;
55  }
56 
57  public function provideTestFormat() {
58  $emptyArrayTestCases = [
59  $this->getMockDiff( [] ),
60  $this->getMockDiff( [ $this->getMockDiffOp( 'add' ) ] ),
61  $this->getMockDiff( [ $this->getMockDiffOp( 'delete' ) ] ),
62  $this->getMockDiff( [ $this->getMockDiffOp( 'change' ) ] ),
63  $this->getMockDiff( [ $this->getMockDiffOp( 'copy' ) ] ),
64  $this->getMockDiff( [ $this->getMockDiffOp( 'FOOBARBAZ' ) ] ),
65  $this->getMockDiff( [ $this->getMockDiffOp( 'add', 'line' ) ] ),
66  $this->getMockDiff( [ $this->getMockDiffOp( 'delete', [], [ 'line' ] ) ] ),
67  $this->getMockDiff( [ $this->getMockDiffOp( 'copy', [], [ 'line' ] ) ] ),
68  ];
69 
70  $otherTestCases = [];
71  $otherTestCases[] = [
72  $this->getMockDiff( [ $this->getMockDiffOp( 'add', [], [ 'a1' ] ) ] ),
73  [ [ 'action' => 'add', 'new' => 'a1', 'newline' => 1 ] ],
74  ];
75  $otherTestCases[] = [
76  $this->getMockDiff( [ $this->getMockDiffOp( 'add', [], [ 'a1', 'a2' ] ) ] ),
77  [
78  [ 'action' => 'add', 'new' => 'a1', 'newline' => 1 ],
79  [ 'action' => 'add', 'new' => 'a2', 'newline' => 2 ],
80  ],
81  ];
82  $otherTestCases[] = [
83  $this->getMockDiff( [ $this->getMockDiffOp( 'delete', [ 'd1' ] ) ] ),
84  [ [ 'action' => 'delete', 'old' => 'd1', 'oldline' => 1 ] ],
85  ];
86  $otherTestCases[] = [
87  $this->getMockDiff( [ $this->getMockDiffOp( 'delete', [ 'd1', 'd2' ] ) ] ),
88  [
89  [ 'action' => 'delete', 'old' => 'd1', 'oldline' => 1 ],
90  [ 'action' => 'delete', 'old' => 'd2', 'oldline' => 2 ],
91  ],
92  ];
93  $otherTestCases[] = [
94  $this->getMockDiff( [ $this->getMockDiffOp( 'change', [ 'd1' ], [ 'a1' ] ) ] ),
95  [ [
96  'action' => 'change',
97  'old' => 'd1',
98  'new' => 'mockLine',
99  'newline' => 1, 'oldline' => 1
100  ] ],
101  ];
102  $otherTestCases[] = [
103  $this->getMockDiff( [ $this->getMockDiffOp(
104  'change',
105  [ 'd1', 'd2' ],
106  [ 'a1', 'a2' ]
107  ) ] ),
108  [
109  [
110  'action' => 'change',
111  'old' => 'd1',
112  'new' => 'mockLine',
113  'newline' => 1, 'oldline' => 1
114  ],
115  [
116  'action' => 'change',
117  'old' => 'd2',
118  'new' => 'mockLine',
119  'newline' => 2, 'oldline' => 2
120  ],
121  ],
122  ];
123 
124  $testCases = [];
125  foreach ( $emptyArrayTestCases as $testCase ) {
126  $testCases[] = [ $testCase, [] ];
127  }
128  foreach ( $otherTestCases as $testCase ) {
129  $testCases[] = [ $testCase[0], $testCase[1] ];
130  }
131  return $testCases;
132  }
133 
134 }
$output
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition: hooks.txt:2255
ArrayDiffFormatterTest\getMockDiff
getMockDiff( $edits)
Definition: ArrayDiffFormatterTest.php:22
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
ArrayDiffFormatterTest\provideTestFormat
provideTestFormat()
Definition: ArrayDiffFormatterTest.php:57
$input
if(is_array( $mode)) switch( $mode) $input
Definition: postprocess-phan.php:145
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
ArrayDiffFormatterTest\testFormat
testFormat( $input, $expectedOutput)
Definition: ArrayDiffFormatterTest.php:16
ArrayDiffFormatterTest
Definition: ArrayDiffFormatterTest.php:8
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:22
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56
ArrayDiffFormatter
A pseudo-formatter that just passes along the Diff::$edits array.
Definition: ArrayDiffFormatter.php:31
ArrayDiffFormatterTest\getMockDiffOp
getMockDiffOp( $type=null, $orig=[], $closing=[])
Definition: ArrayDiffFormatterTest.php:32
$type
$type
Definition: testCompression.php:48