6 class MergeHistoryTest
extends MediaWikiTestCase
{
9 * Make some pages to work with
11 public function addDBData() {
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 $source string Source page
25 * @param $dest string Destination page
26 * @param $timestamp string|bool Timestamp up to which revisions are merged (or false for all)
27 * @param $error string|bool Expected error for test (or true for no error)
29 public function testIsValidMerge( $source, $dest, $timestamp, $error ) {
30 $this->setMwGlobals( 'wgContentHandlerUseDB', false );
31 $mh = new MergeHistory(
32 Title
::newFromText( $source ),
33 Title
::newFromText( $dest ),
36 $status = $mh->isValidMerge();
37 if ( $error === true ) {
38 $this->assertTrue( $status->isGood() );
40 $this->assertTrue( $status->hasMessage( $error ) );
44 public static function provideIsValidMerge() {
46 // for MergeHistory::isValidMerge
47 array( 'Test', 'Test2', false, true ),
48 // Although this timestamp is after the latest timestamp of both pages,
49 // MergeHistory should select the latest source timestamp up to this which should
50 // still work for the merge.
51 array( 'Test', 'Test2', strtotime( 'tomorrow' ), true ),
52 array( 'Test', 'Test', false, 'mergehistory-fail-self-merge' ),
53 array( 'Nonexistant', 'Test2', false, 'mergehistory-fail-invalid-source' ),
54 array( 'Test', 'Nonexistant', false, 'mergehistory-fail-invalid-dest' ),
58 'This is obviously an invalid timestamp',
59 'mergehistory-fail-bad-timestamp'
65 * Test merge revision limit checking
66 * @covers MergeHistory::isValidMerge
68 public function testIsValidMergeRevisionLimit() {
69 $limit = MergeHistory
::REVISION_LIMIT
;
71 $mh = $this->getMockBuilder( 'MergeHistory' )
72 ->setMethods( array( 'getRevisionCount' ) )
73 ->setConstructorArgs( array(
74 Title
::newFromText( 'Test' ),
75 Title
::newFromText( 'Test2' ),
78 $mh->expects( $this->once() )
79 ->method( 'getRevisionCount' )
80 ->will( $this->returnValue( $limit +
1 ) );
82 $status = $mh->isValidMerge();
83 $this->assertTrue( $status->hasMessage( 'mergehistory-fail-toobig' ) );
84 $errors = $status->getErrorsByType( 'error' );
85 $params = $errors[0]['params'];
86 $this->assertEquals( $params[0], Message
::numParam( $limit ) );
90 * Test user permission checking
91 * @covers MergeHistory::checkPermissions
93 public function testCheckPermissions() {
94 $mh = new MergeHistory(
95 Title
::newFromText( 'Test' ),
96 Title
::newFromText( 'Test2' )
99 // Sysop with mergehistory permission
100 $sysop = User
::newFromName( 'UTSysop' );
101 $status = $mh->checkPermissions( $sysop, '' );
102 $this->assertTrue( $status->isOK() );
105 $notSysop = User
::newFromName( 'UTNotSysop' );
106 $notSysop->addToDatabase();
107 $status = $mh->checkPermissions( $notSysop, '' );
108 $this->assertTrue( $status->hasMessage( 'mergehistory-fail-permission' ) );
112 * Test merged revision count
113 * @covers MergeHistory::getMergedRevisionCount
115 public function testGetMergedRevisionCount() {
116 $mh = new MergeHistory(
117 Title
::newFromText( 'Merge1' ),
118 Title
::newFromText( 'Merge2' )
121 $mh->merge( User
::newFromName( 'UTSysop' ) );
122 $this->assertEquals( $mh->getMergedRevisionCount(), 1 );