6 class MergeHistoryTest
extends MediaWikiTestCase
{
9 * Make some pages to work with
11 public function addDBDataOnce() {
12 // Pages that won't actually be merged
13 $this->insertPage( 'Test' );
14 $this->insertPage( 'Test2' );
16 // Pages that will be merged
17 $this->insertPage( 'Merge1' );
18 $this->insertPage( 'Merge2' );
22 * @dataProvider provideIsValidMerge
23 * @covers MergeHistory::isValidMerge
24 * @param string $source Source page
25 * @param string $dest Destination page
26 * @param string|bool $timestamp Timestamp up to which revisions are merged (or false for all)
27 * @param string|bool $error Expected error for test (or true for no error)
29 public function testIsValidMerge( $source, $dest, $timestamp, $error ) {
30 $this->setMwGlobals( 'wgContentHandlerUseDB', false );
31 if ( $timestamp === true ) {
32 // Although this timestamp is after the latest timestamp of both pages,
33 // MergeHistory should select the latest source timestamp up to this which should
34 // still work for the merge.
35 $timestamp = time() +
( 24 * 3600 );
37 $mh = new MergeHistory(
38 Title
::newFromText( $source ),
39 Title
::newFromText( $dest ),
42 $status = $mh->isValidMerge();
43 if ( $error === true ) {
44 $this->assertTrue( $status->isGood() );
46 $this->assertTrue( $status->hasMessage( $error ) );
50 public static function provideIsValidMerge() {
52 // for MergeHistory::isValidMerge
53 [ 'Test', 'Test2', false, true ],
54 // Timestamp of `true` is a placeholder for "in the future""
55 [ 'Test', 'Test2', true, true ],
56 [ 'Test', 'Test', false, 'mergehistory-fail-self-merge' ],
57 [ 'Nonexistant', 'Test2', false, 'mergehistory-fail-invalid-source' ],
58 [ 'Test', 'Nonexistant', false, 'mergehistory-fail-invalid-dest' ],
62 'This is obviously an invalid timestamp',
63 'mergehistory-fail-bad-timestamp'
69 * Test merge revision limit checking
70 * @covers MergeHistory::isValidMerge
72 public function testIsValidMergeRevisionLimit() {
73 $limit = MergeHistory
::REVISION_LIMIT
;
75 $mh = $this->getMockBuilder( MergeHistory
::class )
76 ->setMethods( [ 'getRevisionCount' ] )
77 ->setConstructorArgs( [
78 Title
::newFromText( 'Test' ),
79 Title
::newFromText( 'Test2' ),
82 $mh->expects( $this->once() )
83 ->method( 'getRevisionCount' )
84 ->will( $this->returnValue( $limit +
1 ) );
86 $status = $mh->isValidMerge();
87 $this->assertTrue( $status->hasMessage( 'mergehistory-fail-toobig' ) );
88 $errors = $status->getErrorsByType( 'error' );
89 $params = $errors[0]['params'];
90 $this->assertEquals( $params[0], Message
::numParam( $limit ) );
94 * Test user permission checking
95 * @covers MergeHistory::checkPermissions
97 public function testCheckPermissions() {
98 $mh = new MergeHistory(
99 Title
::newFromText( 'Test' ),
100 Title
::newFromText( 'Test2' )
103 // Sysop with mergehistory permission
104 $sysop = static::getTestSysop()->getUser();
105 $status = $mh->checkPermissions( $sysop, '' );
106 $this->assertTrue( $status->isOK() );
109 $notSysop = static::getTestUser()->getUser();
110 $status = $mh->checkPermissions( $notSysop, '' );
111 $this->assertTrue( $status->hasMessage( 'mergehistory-fail-permission' ) );
115 * Test merged revision count
116 * @covers MergeHistory::getMergedRevisionCount
118 public function testGetMergedRevisionCount() {
119 $mh = new MergeHistory(
120 Title
::newFromText( 'Merge1' ),
121 Title
::newFromText( 'Merge2' )
124 $sysop = static::getTestSysop()->getUser();
125 $mh->merge( $sysop );
126 $this->assertEquals( $mh->getMergedRevisionCount(), 1 );