Move DatabaseDomain to Rdbms namespace
[mediawiki.git] / tests / phpunit / includes / api / ApiRevisionDeleteTest.php
bloba4ca8a10a135df689966784d7b2fe188c605fb28
1 <?php
3 /**
4 * Tests for action=revisiondelete
5 * @covers APIRevisionDelete
6 * @group API
7 * @group medium
8 * @group Database
9 */
10 class ApiRevisionDeleteTest extends ApiTestCase {
12 public static $page = 'Help:ApiRevDel_test';
13 public $revs = [];
15 protected function setUp() {
16 // Needs to be before setup since this gets cached
17 $this->mergeMwGlobalArrayValue(
18 'wgGroupPermissions',
19 [ 'sysop' => [ 'deleterevision' => true ] ]
21 parent::setUp();
22 // Make a few edits for us to play with
23 for ( $i = 1; $i <= 5; $i++ ) {
24 self::editPage( self::$page, MWCryptRand::generateHex( 10 ), 'summary' );
25 $this->revs[] = Title::newFromText( self::$page )
26 ->getLatestRevID( Title::GAID_FOR_UPDATE );
30 public function testHidingRevisions() {
31 $user = self::$users['sysop']->getUser();
32 $revid = array_shift( $this->revs );
33 $out = $this->doApiRequest( [
34 'action' => 'revisiondelete',
35 'type' => 'revision',
36 'target' => self::$page,
37 'ids' => $revid,
38 'hide' => 'content|user|comment',
39 'token' => $user->getEditToken(),
40 ] );
41 // Check the output
42 $out = $out[0]['revisiondelete'];
43 $this->assertEquals( $out['status'], 'Success' );
44 $this->assertArrayHasKey( 'items', $out );
45 $item = $out['items'][0];
46 $this->assertTrue( $item['userhidden'], 'userhidden' );
47 $this->assertTrue( $item['commenthidden'], 'commenthidden' );
48 $this->assertTrue( $item['texthidden'], 'texthidden' );
49 $this->assertEquals( $item['id'], $revid );
51 // Now check that that revision was actually hidden
52 $rev = Revision::newFromId( $revid );
53 $this->assertEquals( $rev->getContent( Revision::FOR_PUBLIC ), null );
54 $this->assertEquals( $rev->getComment( Revision::FOR_PUBLIC ), '' );
55 $this->assertEquals( $rev->getUser( Revision::FOR_PUBLIC ), 0 );
57 // Now test unhiding!
58 $out2 = $this->doApiRequest( [
59 'action' => 'revisiondelete',
60 'type' => 'revision',
61 'target' => self::$page,
62 'ids' => $revid,
63 'show' => 'content|user|comment',
64 'token' => $user->getEditToken(),
65 ] );
67 // Check the output
68 $out2 = $out2[0]['revisiondelete'];
69 $this->assertEquals( $out2['status'], 'Success' );
70 $this->assertArrayHasKey( 'items', $out2 );
71 $item = $out2['items'][0];
73 $this->assertFalse( $item['userhidden'], 'userhidden' );
74 $this->assertFalse( $item['commenthidden'], 'commenthidden' );
75 $this->assertFalse( $item['texthidden'], 'texthidden' );
77 $this->assertEquals( $item['id'], $revid );
79 $rev = Revision::newFromId( $revid );
80 $this->assertNotEquals( $rev->getContent( Revision::FOR_PUBLIC ), null );
81 $this->assertNotEquals( $rev->getComment( Revision::FOR_PUBLIC ), '' );
82 $this->assertNotEquals( $rev->getUser( Revision::FOR_PUBLIC ), 0 );
85 public function testUnhidingOutput() {
86 $user = self::$users['sysop']->getUser();
87 $revid = array_shift( $this->revs );
88 // Hide revisions
89 $this->doApiRequest( [
90 'action' => 'revisiondelete',
91 'type' => 'revision',
92 'target' => self::$page,
93 'ids' => $revid,
94 'hide' => 'content|user|comment',
95 'token' => $user->getEditToken(),
96 ] );
98 $out = $this->doApiRequest( [
99 'action' => 'revisiondelete',
100 'type' => 'revision',
101 'target' => self::$page,
102 'ids' => $revid,
103 'show' => 'comment',
104 'token' => $user->getEditToken(),
105 ] );
106 $out = $out[0]['revisiondelete'];
107 $this->assertEquals( $out['status'], 'Success' );
108 $this->assertArrayHasKey( 'items', $out );
109 $item = $out['items'][0];
110 // Check it has userhidden & texthidden
111 // but not commenthidden
112 $this->assertTrue( $item['userhidden'], 'userhidden' );
113 $this->assertFalse( $item['commenthidden'], 'commenthidden' );
114 $this->assertTrue( $item['texthidden'], 'texthidden' );
115 $this->assertEquals( $item['id'], $revid );