4 * Tests for action=revisiondelete
5 * @covers APIRevisionDelete
10 class ApiRevisionDeleteTest
extends ApiTestCase
{
12 public static $page = 'Help:ApiRevDel_test';
13 public $revs = array();
15 protected function setUp() {
16 // Needs to be before setup since this gets cached
17 $this->mergeMwGlobalArrayValue( 'wgGroupPermissions', array( 'sysop' => array( 'deleterevision' => true ) ) );
19 // Make a few edits for us to play with
20 for ( $i = 1; $i <= 5; $i++
) {
21 self
::editPage( self
::$page, MWCryptRand
::generateHex( 10 ), 'summary' );
22 $this->revs
[] = Title
::newFromText( self
::$page )->getLatestRevID( Title
::GAID_FOR_UPDATE
);
27 public function testHidingRevisions() {
28 $user = self
::$users['sysop']->user
;
29 $revid = array_shift( $this->revs
);
30 $out = $this->doApiRequest( array(
31 'action' => 'revisiondelete',
33 'target' => self
::$page,
35 'hide' => 'content|user|comment',
36 'token' => $user->getEditToken(),
39 $out = $out[0]['revisiondelete'];
40 $this->assertEquals( $out['status'], 'Success' );
41 $this->assertArrayHasKey( 'items', $out );
42 $item = $out['items'][0];
43 $this->assertArrayHasKey( 'userhidden', $item );
44 $this->assertArrayHasKey( 'commenthidden', $item );
45 $this->assertArrayHasKey( 'texthidden', $item );
46 $this->assertEquals( $item['id'], $revid );
48 // Now check that that revision was actually hidden
49 $rev = Revision
::newFromId( $revid );
50 $this->assertEquals( $rev->getContent( Revision
::FOR_PUBLIC
), null );
51 $this->assertEquals( $rev->getComment( Revision
::FOR_PUBLIC
), '' );
52 $this->assertEquals( $rev->getUser( Revision
::FOR_PUBLIC
), 0 );
55 $out2 = $this->doApiRequest( array(
56 'action' => 'revisiondelete',
58 'target' => self
::$page,
60 'show' => 'content|user|comment',
61 'token' => $user->getEditToken(),
65 $out2 = $out2[0]['revisiondelete'];
66 $this->assertEquals( $out2['status'], 'Success' );
67 $this->assertArrayHasKey( 'items', $out2 );
68 $item = $out2['items'][0];
70 $this->assertArrayNotHasKey( 'userhidden', $item );
71 $this->assertArrayNotHasKey( 'commenthidden', $item );
72 $this->assertArrayNotHasKey( 'texthidden', $item );
74 $this->assertEquals( $item['id'], $revid );
76 $rev = Revision
::newFromId( $revid );
77 $this->assertNotEquals( $rev->getContent( Revision
::FOR_PUBLIC
), null );
78 $this->assertNotEquals( $rev->getComment( Revision
::FOR_PUBLIC
), '' );
79 $this->assertNotEquals( $rev->getUser( Revision
::FOR_PUBLIC
), 0 );
82 public function testUnhidingOutput() {
83 $user = self
::$users['sysop']->user
;
84 $revid = array_shift( $this->revs
);
86 $this->doApiRequest( array(
87 'action' => 'revisiondelete',
89 'target' => self
::$page,
91 'hide' => 'content|user|comment',
92 'token' => $user->getEditToken(),
95 $out = $this->doApiRequest( array(
96 'action' => 'revisiondelete',
98 'target' => self
::$page,
101 'token' => $user->getEditToken(),
103 $out = $out[0]['revisiondelete'];
104 $this->assertEquals( $out['status'], 'Success' );
105 $this->assertArrayHasKey( 'items', $out );
106 $item = $out['items'][0];
107 // Check it has userhidden & texthidden keys
108 // but no commenthidden key
109 $this->assertArrayHasKey( 'userhidden', $item );
110 $this->assertArrayNotHasKey( 'commenthidden', $item );
111 $this->assertArrayHasKey( 'texthidden', $item );
112 $this->assertEquals( $item['id'], $revid );