MediaWiki  1.23.15
ArrayDiffFormatterTest.php
Go to the documentation of this file.
1 <?php
2 
10 
17  public function testFormat( $input, $expectedOutput ) {
18  $instance = new ArrayDiffFormatter();
19  $output = $instance->format( $input );
20  $this->assertEquals( $expectedOutput, $output );
21  }
22 
23  private function getMockDiff( $edits ) {
24  $diff = $this->getMockBuilder( 'Diff' )
25  ->disableOriginalConstructor()
26  ->getMock();
27  $diff->expects( $this->any() )
28  ->method( 'getEdits' )
29  ->will( $this->returnValue( $edits ) );
30  return $diff;
31  }
32 
33  private function getMockDiffOp( $type = null, $orig = array(), $closing = array() ) {
34  $diffOp = $this->getMockBuilder( 'DiffOp' )
35  ->disableOriginalConstructor()
36  ->getMock();
37  $diffOp->expects( $this->any() )
38  ->method( 'getType' )
39  ->will( $this->returnValue( $type ) );
40  $diffOp->expects( $this->any() )
41  ->method( 'getOrig' )
42  ->will( $this->returnValue( $orig ) );
43  if ( $type === 'change' ) {
44  $diffOp->expects( $this->any() )
45  ->method( 'getClosing' )
46  ->with( $this->isType( 'integer' ) )
47  ->will( $this->returnCallback( function() {
48  return 'mockLine';
49  } ) );
50  } else {
51  $diffOp->expects( $this->any() )
52  ->method( 'getClosing' )
53  ->will( $this->returnValue( $closing ) );
54  }
55  return $diffOp;
56  }
57 
58  public function provideTestFormat() {
59  $emptyArrayTestCases = array(
60  $this->getMockDiff( array() ),
61  $this->getMockDiff( array( $this->getMockDiffOp( 'add' ) ) ),
62  $this->getMockDiff( array( $this->getMockDiffOp( 'delete' ) ) ),
63  $this->getMockDiff( array( $this->getMockDiffOp( 'change' ) ) ),
64  $this->getMockDiff( array( $this->getMockDiffOp( 'copy' ) ) ),
65  $this->getMockDiff( array( $this->getMockDiffOp( 'FOOBARBAZ' ) ) ),
66  $this->getMockDiff( array( $this->getMockDiffOp( 'add', 'line' ) ) ),
67  $this->getMockDiff( array( $this->getMockDiffOp( 'delete', array(), array( 'line' ) ) ) ),
68  $this->getMockDiff( array( $this->getMockDiffOp( 'copy', array(), array( 'line' ) ) ) ),
69  );
70 
71  $otherTestCases = array();
72  $otherTestCases[] = array(
73  $this->getMockDiff( array( $this->getMockDiffOp( 'add', array( ), array( 'a1' ) ) ) ),
74  array( array( 'action' => 'add', 'new' => 'a1', 'newline' => 1 ) ),
75  );
76  $otherTestCases[] = array(
77  $this->getMockDiff( array( $this->getMockDiffOp( 'add', array( ), array( 'a1', 'a2' ) ) ) ),
78  array(
79  array( 'action' => 'add', 'new' => 'a1', 'newline' => 1 ),
80  array( 'action' => 'add', 'new' => 'a2', 'newline' => 2 ),
81  ),
82  );
83  $otherTestCases[] = array(
84  $this->getMockDiff( array( $this->getMockDiffOp( 'delete', array( 'd1' ) ) ) ),
85  array( array( 'action' => 'delete', 'old' => 'd1', 'oldline' => 1 ) ),
86  );
87  $otherTestCases[] = array(
88  $this->getMockDiff( array( $this->getMockDiffOp( 'delete', array( 'd1', 'd2' ) ) ) ),
89  array(
90  array( 'action' => 'delete', 'old' => 'd1', 'oldline' => 1 ),
91  array( 'action' => 'delete', 'old' => 'd2', 'oldline' => 2 ),
92  ),
93  );
94  $otherTestCases[] = array(
95  $this->getMockDiff( array( $this->getMockDiffOp( 'change', array( 'd1' ), array( 'a1' ) ) ) ),
96  array( array( 'action' => 'change', 'old' => 'd1', 'new' => 'mockLine', 'newline' => 1, 'oldline' => 1 ) ),
97  );
98  $otherTestCases[] = array(
99  $this->getMockDiff( array( $this->getMockDiffOp( 'change', array( 'd1', 'd2' ), array( 'a1', 'a2' ) ) ) ),
100  array(
101  array( 'action' => 'change', 'old' => 'd1', 'new' => 'mockLine', 'newline' => 1, 'oldline' => 1 ),
102  array( 'action' => 'change', 'old' => 'd2', 'new' => 'mockLine', 'newline' => 2, 'oldline' => 2 ),
103  ),
104  );
105 
106  $testCases = array();
107  foreach ( $emptyArrayTestCases as $testCase ) {
108  $testCases[] = array( $testCase, array() );
109  }
110  foreach ( $otherTestCases as $testCase ) {
111  $testCases[] = array( $testCase[0], $testCase[1] );
112  }
113  return $testCases;
114  }
115 
116 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ArrayDiffFormatterTest\getMockDiff
getMockDiff( $edits)
Definition: ArrayDiffFormatterTest.php:23
ArrayDiffFormatterTest\provideTestFormat
provideTestFormat()
Definition: ArrayDiffFormatterTest.php:58
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ArrayDiffFormatterTest\getMockDiffOp
getMockDiffOp( $type=null, $orig=array(), $closing=array())
Definition: ArrayDiffFormatterTest.php:33
ArrayDiffFormatterTest\testFormat
testFormat( $input, $expectedOutput)
Definition: ArrayDiffFormatterTest.php:17
ArrayDiffFormatterTest
@licence GNU GPL v2+
Definition: ArrayDiffFormatterTest.php:9
$output
& $output
Definition: hooks.txt:375
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:9
ArrayDiffFormatter
A pseudo-formatter that just passes along the Diff::$edits array.
Definition: ArrayDiffFormatter.php:31
$type
$type
Definition: testCompression.php:46