Move DatabaseDomain to Rdbms namespace
[mediawiki.git] / tests / phpunit / includes / MergeHistoryTest.php
blobf44ae322727e61555c3d277ff066485055ad24aa
1 <?php
3 /**
4 * @group Database
5 */
6 class MergeHistoryTest extends MediaWikiTestCase {
8 /**
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' );
21 /**
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 $mh = new MergeHistory(
32 Title::newFromText( $source ),
33 Title::newFromText( $dest ),
34 $timestamp
36 $status = $mh->isValidMerge();
37 if ( $error === true ) {
38 $this->assertTrue( $status->isGood() );
39 } else {
40 $this->assertTrue( $status->hasMessage( $error ) );
44 public static function provideIsValidMerge() {
45 return [
46 // for MergeHistory::isValidMerge
47 [ '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 [ 'Test', 'Test2', strtotime( 'tomorrow' ), true ],
52 [ 'Test', 'Test', false, 'mergehistory-fail-self-merge' ],
53 [ 'Nonexistant', 'Test2', false, 'mergehistory-fail-invalid-source' ],
54 [ 'Test', 'Nonexistant', false, 'mergehistory-fail-invalid-dest' ],
56 'Test',
57 'Test2',
58 'This is obviously an invalid timestamp',
59 'mergehistory-fail-bad-timestamp'
64 /**
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( [ 'getRevisionCount' ] )
73 ->setConstructorArgs( [
74 Title::newFromText( 'Test' ),
75 Title::newFromText( 'Test2' ),
76 ] )
77 ->getMock();
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 ) );
89 /**
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 = static::getTestSysop()->getUser();
101 $status = $mh->checkPermissions( $sysop, '' );
102 $this->assertTrue( $status->isOK() );
104 // Normal user
105 $notSysop = static::getTestUser()->getUser();
106 $status = $mh->checkPermissions( $notSysop, '' );
107 $this->assertTrue( $status->hasMessage( 'mergehistory-fail-permission' ) );
111 * Test merged revision count
112 * @covers MergeHistory::getMergedRevisionCount
114 public function testGetMergedRevisionCount() {
115 $mh = new MergeHistory(
116 Title::newFromText( 'Merge1' ),
117 Title::newFromText( 'Merge2' )
120 $sysop = static::getTestSysop()->getUser();
121 $mh->merge( $sysop );
122 $this->assertEquals( $mh->getMergedRevisionCount(), 1 );