MediaWiki  REL1_31
ApiRevisionDeleteTest.php
Go to the documentation of this file.
1 <?php
2 
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
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  public function testHidingRevisions() {
31  $user = self::$users['sysop']->getUser();
32  $revid = array_shift( $this->revs );
33  $out = $this->doApiRequest( [
34  'action' => 'revisiondelete',
35  'type' => 'revision',
36  'target' => self::$page,
37  'ids' => $revid,
38  'hide' => 'content|user|comment',
39  'token' => $user->getEditToken(),
40  ] );
41  // Check the output
42  $out = $out[0]['revisiondelete'];
43  $this->assertEquals( $out['status'], 'Success' );
44  $this->assertArrayHasKey( 'items', $out );
45  $item = $out['items'][0];
46  $this->assertTrue( $item['userhidden'], 'userhidden' );
47  $this->assertTrue( $item['commenthidden'], 'commenthidden' );
48  $this->assertTrue( $item['texthidden'], 'texthidden' );
49  $this->assertEquals( $item['id'], $revid );
50 
51  // Now check that that revision was actually hidden
52  $rev = Revision::newFromId( $revid );
53  $this->assertEquals( $rev->getContent( Revision::FOR_PUBLIC ), null );
54  $this->assertEquals( $rev->getComment( Revision::FOR_PUBLIC ), '' );
55  $this->assertEquals( $rev->getUser( Revision::FOR_PUBLIC ), 0 );
56 
57  // Now test unhiding!
58  $out2 = $this->doApiRequest( [
59  'action' => 'revisiondelete',
60  'type' => 'revision',
61  'target' => self::$page,
62  'ids' => $revid,
63  'show' => 'content|user|comment',
64  'token' => $user->getEditToken(),
65  ] );
66 
67  // Check the output
68  $out2 = $out2[0]['revisiondelete'];
69  $this->assertEquals( $out2['status'], 'Success' );
70  $this->assertArrayHasKey( 'items', $out2 );
71  $item = $out2['items'][0];
72 
73  $this->assertFalse( $item['userhidden'], 'userhidden' );
74  $this->assertFalse( $item['commenthidden'], 'commenthidden' );
75  $this->assertFalse( $item['texthidden'], 'texthidden' );
76 
77  $this->assertEquals( $item['id'], $revid );
78 
79  $rev = Revision::newFromId( $revid );
80  $this->assertNotEquals( $rev->getContent( Revision::FOR_PUBLIC ), null );
81  $this->assertNotEquals( $rev->getComment( Revision::FOR_PUBLIC ), '' );
82  $this->assertNotEquals( $rev->getUser( Revision::FOR_PUBLIC ), 0 );
83  }
84 
85  public function testUnhidingOutput() {
86  $user = self::$users['sysop']->getUser();
87  $revid = array_shift( $this->revs );
88  // Hide revisions
89  $this->doApiRequest( [
90  'action' => 'revisiondelete',
91  'type' => 'revision',
92  'target' => self::$page,
93  'ids' => $revid,
94  'hide' => 'content|user|comment',
95  'token' => $user->getEditToken(),
96  ] );
97 
98  $out = $this->doApiRequest( [
99  'action' => 'revisiondelete',
100  'type' => 'revision',
101  'target' => self::$page,
102  'ids' => $revid,
103  'show' => 'comment',
104  'token' => $user->getEditToken(),
105  ] );
106  $out = $out[0]['revisiondelete'];
107  $this->assertEquals( $out['status'], 'Success' );
108  $this->assertArrayHasKey( 'items', $out );
109  $item = $out['items'][0];
110  // Check it has userhidden & texthidden
111  // but not commenthidden
112  $this->assertTrue( $item['userhidden'], 'userhidden' );
113  $this->assertFalse( $item['commenthidden'], 'commenthidden' );
114  $this->assertTrue( $item['texthidden'], 'texthidden' );
115  $this->assertEquals( $item['id'], $revid );
116  }
117 }
Revision\FOR_PUBLIC
const FOR_PUBLIC
Definition: Revision.php:55
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:247
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:273
Revision\newFromId
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:114
MediaWikiTestCase\mergeMwGlobalArrayValue
mergeMwGlobalArrayValue( $name, $values)
Merges the given values into a MW global array variable.
Definition: MediaWikiTestCase.php:813
ApiRevisionDeleteTest\testHidingRevisions
testHidingRevisions()
Definition: ApiRevisionDeleteTest.php:30
ApiRevisionDeleteTest
Tests for action=revisiondelete APIRevisionDelete API medium Database.
Definition: ApiRevisionDeleteTest.php:10
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:864
ApiRevisionDeleteTest\$revs
$revs
Definition: ApiRevisionDeleteTest.php:13
MWCryptRand\generateHex
static generateHex( $chars, $forceStrong=false)
Generate a run of (ideally) cryptographically random data and return it in hexadecimal string format.
Definition: MWCryptRand.php:76
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
ApiRevisionDeleteTest\setUp
setUp()
Definition: ApiRevisionDeleteTest.php:15
ApiTestCase\doApiRequest
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
Definition: ApiTestCase.php:100
ApiTestCase
Definition: ApiTestCase.php:5
ApiTestCase\editPage
editPage( $pageName, $text, $summary='', $defaultNs=NS_MAIN)
Edits or creates a page/revision.
Definition: ApiTestCase.php:52
ApiRevisionDeleteTest\$page
static $page
Definition: ApiRevisionDeleteTest.php:12
Title\GAID_FOR_UPDATE
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define.
Definition: Title.php:54
$rev
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1777
ApiRevisionDeleteTest\testUnhidingOutput
testUnhidingOutput()
Definition: ApiRevisionDeleteTest.php:85