Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / api / ApiRevisionDeleteTest.php
blobb03836eb2b7c9d3d112db949a24158c3cd60e43a
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 = array();
15 protected function setUp() {
16 // Needs to be before setup since this gets cached
17 $this->mergeMwGlobalArrayValue( 'wgGroupPermissions', array( 'sysop' => array( 'deleterevision' => true ) ) );
18 parent::setUp();
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',
32 'type' => 'revision',
33 'target' => self::$page,
34 'ids' => $revid,
35 'hide' => 'content|user|comment',
36 'token' => $user->getEditToken(),
37 ) );
38 // Check the output
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 );
54 // Now test unhiding!
55 $out2 = $this->doApiRequest( array(
56 'action' => 'revisiondelete',
57 'type' => 'revision',
58 'target' => self::$page,
59 'ids' => $revid,
60 'show' => 'content|user|comment',
61 'token' => $user->getEditToken(),
62 ) );
64 // Check the output
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 );
85 // Hide revisions
86 $this->doApiRequest( array(
87 'action' => 'revisiondelete',
88 'type' => 'revision',
89 'target' => self::$page,
90 'ids' => $revid,
91 'hide' => 'content|user|comment',
92 'token' => $user->getEditToken(),
93 ) );
95 $out = $this->doApiRequest( array(
96 'action' => 'revisiondelete',
97 'type' => 'revision',
98 'target' => self::$page,
99 'ids' => $revid,
100 'show' => 'comment',
101 'token' => $user->getEditToken(),
102 ) );
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 );