MediaWiki
REL1_24
|
00001 <?php 00002 00010 class ApiRevisionDeleteTest extends ApiTestCase { 00011 00012 public static $page = 'Help:ApiRevDel_test'; 00013 public $revs = array(); 00014 00015 protected function setUp() { 00016 // Needs to be before setup since this gets cached 00017 $this->mergeMwGlobalArrayValue( 'wgGroupPermissions', array( 'sysop' => array( 'deleterevision' => true ) ) ); 00018 parent::setUp(); 00019 // Make a few edits for us to play with 00020 for ( $i = 1; $i <= 5; $i++ ) { 00021 self::editPage( self::$page, MWCryptRand::generateHex( 10 ), 'summary' ); 00022 $this->revs[] = Title::newFromText( self::$page )->getLatestRevID( Title::GAID_FOR_UPDATE ); 00023 } 00024 00025 } 00026 00027 public function testHidingRevisions() { 00028 $user = self::$users['sysop']->user; 00029 $revid = array_shift( $this->revs ); 00030 $out = $this->doApiRequest( array( 00031 'action' => 'revisiondelete', 00032 'type' => 'revision', 00033 'target' => self::$page, 00034 'ids' => $revid, 00035 'hide' => 'content|user|comment', 00036 'token' => $user->getEditToken(), 00037 ) ); 00038 // Check the output 00039 $out = $out[0]['revisiondelete']; 00040 $this->assertEquals( $out['status'], 'Success' ); 00041 $this->assertArrayHasKey( 'items', $out ); 00042 $item = $out['items'][0]; 00043 $this->assertArrayHasKey( 'userhidden', $item ); 00044 $this->assertArrayHasKey( 'commenthidden', $item ); 00045 $this->assertArrayHasKey( 'texthidden', $item ); 00046 $this->assertEquals( $item['id'], $revid ); 00047 00048 // Now check that that revision was actually hidden 00049 $rev = Revision::newFromId( $revid ); 00050 $this->assertEquals( $rev->getContent( Revision::FOR_PUBLIC ), null ); 00051 $this->assertEquals( $rev->getComment( Revision::FOR_PUBLIC ), '' ); 00052 $this->assertEquals( $rev->getUser( Revision::FOR_PUBLIC ), 0 ); 00053 00054 // Now test unhiding! 00055 $out2 = $this->doApiRequest( array( 00056 'action' => 'revisiondelete', 00057 'type' => 'revision', 00058 'target' => self::$page, 00059 'ids' => $revid, 00060 'show' => 'content|user|comment', 00061 'token' => $user->getEditToken(), 00062 ) ); 00063 00064 // Check the output 00065 $out2 = $out2[0]['revisiondelete']; 00066 $this->assertEquals( $out2['status'], 'Success' ); 00067 $this->assertArrayHasKey( 'items', $out2 ); 00068 $item = $out2['items'][0]; 00069 00070 $this->assertArrayNotHasKey( 'userhidden', $item ); 00071 $this->assertArrayNotHasKey( 'commenthidden', $item ); 00072 $this->assertArrayNotHasKey( 'texthidden', $item ); 00073 00074 $this->assertEquals( $item['id'], $revid ); 00075 00076 $rev = Revision::newFromId( $revid ); 00077 $this->assertNotEquals( $rev->getContent( Revision::FOR_PUBLIC ), null ); 00078 $this->assertNotEquals( $rev->getComment( Revision::FOR_PUBLIC ), '' ); 00079 $this->assertNotEquals( $rev->getUser( Revision::FOR_PUBLIC ), 0 ); 00080 } 00081 00082 public function testUnhidingOutput() { 00083 $user = self::$users['sysop']->user; 00084 $revid = array_shift( $this->revs ); 00085 // Hide revisions 00086 $this->doApiRequest( array( 00087 'action' => 'revisiondelete', 00088 'type' => 'revision', 00089 'target' => self::$page, 00090 'ids' => $revid, 00091 'hide' => 'content|user|comment', 00092 'token' => $user->getEditToken(), 00093 ) ); 00094 00095 $out = $this->doApiRequest( array( 00096 'action' => 'revisiondelete', 00097 'type' => 'revision', 00098 'target' => self::$page, 00099 'ids' => $revid, 00100 'show' => 'comment', 00101 'token' => $user->getEditToken(), 00102 ) ); 00103 $out = $out[0]['revisiondelete']; 00104 $this->assertEquals( $out['status'], 'Success' ); 00105 $this->assertArrayHasKey( 'items', $out ); 00106 $item = $out['items'][0]; 00107 // Check it has userhidden & texthidden keys 00108 // but no commenthidden key 00109 $this->assertArrayHasKey( 'userhidden', $item ); 00110 $this->assertArrayNotHasKey( 'commenthidden', $item ); 00111 $this->assertArrayHasKey( 'texthidden', $item ); 00112 $this->assertEquals( $item['id'], $revid ); 00113 } 00114 }