Merge "Get timestamp from WikiPage, instead of Article"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiRevisionDeleteTest.php
1 <?php
2
3 /**
4 * Tests for action=revisiondelete
5 * @covers APIRevisionDelete
6 * @group API
7 * @group medium
8 * @group Database
9 */
10 class ApiRevisionDeleteTest extends ApiTestCase {
11
12 public static $page = 'Help:ApiRevDel_test';
13 public $revs = [];
14
15 protected function setUp() {
16 // Needs to be before setup since this gets cached
17 $this->mergeMwGlobalArrayValue(
18 'wgGroupPermissions',
19 [ 'sysop' => [ 'deleterevision' => true ] ]
20 );
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 );
27 }
28
29 }
30
31 public function testHidingRevisions() {
32 $user = self::$users['sysop']->getUser();
33 $revid = array_shift( $this->revs );
34 $out = $this->doApiRequest( [
35 'action' => 'revisiondelete',
36 'type' => 'revision',
37 'target' => self::$page,
38 'ids' => $revid,
39 'hide' => 'content|user|comment',
40 'token' => $user->getEditToken(),
41 ] );
42 // Check the output
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 );
51
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 );
57
58 // Now test unhiding!
59 $out2 = $this->doApiRequest( [
60 'action' => 'revisiondelete',
61 'type' => 'revision',
62 'target' => self::$page,
63 'ids' => $revid,
64 'show' => 'content|user|comment',
65 'token' => $user->getEditToken(),
66 ] );
67
68 // Check the output
69 $out2 = $out2[0]['revisiondelete'];
70 $this->assertEquals( $out2['status'], 'Success' );
71 $this->assertArrayHasKey( 'items', $out2 );
72 $item = $out2['items'][0];
73
74 $this->assertArrayNotHasKey( 'userhidden', $item );
75 $this->assertArrayNotHasKey( 'commenthidden', $item );
76 $this->assertArrayNotHasKey( 'texthidden', $item );
77
78 $this->assertEquals( $item['id'], $revid );
79
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 );
84 }
85
86 public function testUnhidingOutput() {
87 $user = self::$users['sysop']->getUser();
88 $revid = array_shift( $this->revs );
89 // Hide revisions
90 $this->doApiRequest( [
91 'action' => 'revisiondelete',
92 'type' => 'revision',
93 'target' => self::$page,
94 'ids' => $revid,
95 'hide' => 'content|user|comment',
96 'token' => $user->getEditToken(),
97 ] );
98
99 $out = $this->doApiRequest( [
100 'action' => 'revisiondelete',
101 'type' => 'revision',
102 'target' => self::$page,
103 'ids' => $revid,
104 'show' => 'comment',
105 'token' => $user->getEditToken(),
106 ] );
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 );
117 }
118 }