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(
19 array( 'sysop' => array( 'deleterevision' => true ) )
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
);
31 public function testHidingRevisions() {
32 $user = self
::$users['sysop']->getUser();
33 $revid = array_shift( $this->revs
);
34 $out = $this->doApiRequest( array(
35 'action' => 'revisiondelete',
37 'target' => self
::$page,
39 'hide' => 'content|user|comment',
40 'token' => $user->getEditToken(),
43 $out = $out[0]['revisiondelete'];
44 $this->assertEquals( $out['status'], 'Success' );
45 $this->assertArrayHasKey( 'items', $out );
46 $item = $out['items'][0];
47 $this->assertArrayHasKey( 'userhidden', $item );
48 $this->assertArrayHasKey( 'commenthidden', $item );
49 $this->assertArrayHasKey( 'texthidden', $item );
50 $this->assertEquals( $item['id'], $revid );
52 // Now check that that revision was actually hidden
53 $rev = Revision
::newFromId( $revid );
54 $this->assertEquals( $rev->getContent( Revision
::FOR_PUBLIC
), null );
55 $this->assertEquals( $rev->getComment( Revision
::FOR_PUBLIC
), '' );
56 $this->assertEquals( $rev->getUser( Revision
::FOR_PUBLIC
), 0 );
59 $out2 = $this->doApiRequest( array(
60 'action' => 'revisiondelete',
62 'target' => self
::$page,
64 'show' => 'content|user|comment',
65 'token' => $user->getEditToken(),
69 $out2 = $out2[0]['revisiondelete'];
70 $this->assertEquals( $out2['status'], 'Success' );
71 $this->assertArrayHasKey( 'items', $out2 );
72 $item = $out2['items'][0];
74 $this->assertArrayNotHasKey( 'userhidden', $item );
75 $this->assertArrayNotHasKey( 'commenthidden', $item );
76 $this->assertArrayNotHasKey( 'texthidden', $item );
78 $this->assertEquals( $item['id'], $revid );
80 $rev = Revision
::newFromId( $revid );
81 $this->assertNotEquals( $rev->getContent( Revision
::FOR_PUBLIC
), null );
82 $this->assertNotEquals( $rev->getComment( Revision
::FOR_PUBLIC
), '' );
83 $this->assertNotEquals( $rev->getUser( Revision
::FOR_PUBLIC
), 0 );
86 public function testUnhidingOutput() {
87 $user = self
::$users['sysop']->getUser();
88 $revid = array_shift( $this->revs
);
90 $this->doApiRequest( array(
91 'action' => 'revisiondelete',
93 'target' => self
::$page,
95 'hide' => 'content|user|comment',
96 'token' => $user->getEditToken(),
99 $out = $this->doApiRequest( array(
100 'action' => 'revisiondelete',
101 'type' => 'revision',
102 'target' => self
::$page,
105 'token' => $user->getEditToken(),
107 $out = $out[0]['revisiondelete'];
108 $this->assertEquals( $out['status'], 'Success' );
109 $this->assertArrayHasKey( 'items', $out );
110 $item = $out['items'][0];
111 // Check it has userhidden & texthidden keys
112 // but no commenthidden key
113 $this->assertArrayHasKey( 'userhidden', $item );
114 $this->assertArrayNotHasKey( 'commenthidden', $item );
115 $this->assertArrayHasKey( 'texthidden', $item );
116 $this->assertEquals( $item['id'], $revid );