MediaWiki  1.27.1
CategoryMembershipChangeTest.php
Go to the documentation of this file.
1 <?php
2 
11 
15  private static $lastNotifyArgs;
16 
20  private static $notifyCallCounter = 0;
21 
25  private static $mockRecentChange;
26 
30  private static $pageRev = null;
31 
35  private static $pageName = 'CategoryMembershipChangeTestPage';
36 
37  public static function newForCategorizationCallback() {
38  self::$lastNotifyArgs = func_get_args();
39  self::$notifyCallCounter += 1;
40  return self::$mockRecentChange;
41  }
42 
43  public function setUp() {
44  parent::setUp();
45  self::$notifyCallCounter = 0;
46  self::$mockRecentChange = self::getMock( 'RecentChange' );
47 
48  $this->setContentLang( 'qqx' );
49  }
50 
51  public function addDBDataOnce() {
52  $info = $this->insertPage( self::$pageName );
53  $title = $info['title'];
54 
56  self::$pageRev = $page->getRevision();
57  }
58 
59  private function newChange( Revision $revision = null ) {
60  $change = new CategoryMembershipChange( Title::newFromText( self::$pageName ), $revision );
61  $change->overrideNewForCategorizationCallback(
62  'CategoryMembershipChangeTest::newForCategorizationCallback'
63  );
64 
65  return $change;
66  }
67 
68  public function testChangeAddedNoRev() {
69  $change = $this->newChange();
70  $change->triggerCategoryAddedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
71 
72  $this->assertEquals( 1, self::$notifyCallCounter );
73 
74  $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
75  $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
76  $this->assertEquals( '(autochange-username)', self::$lastNotifyArgs[2]->getName() );
77  $this->assertEquals( '(recentchanges-page-added-to-category: ' . self::$pageName . ')',
78  self::$lastNotifyArgs[3] );
79  $this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() );
80  $this->assertEquals( 0, self::$lastNotifyArgs[5] );
81  $this->assertEquals( 0, self::$lastNotifyArgs[6] );
82  $this->assertEquals( null, self::$lastNotifyArgs[7] );
83  $this->assertEquals( 1, self::$lastNotifyArgs[8] );
84  $this->assertEquals( null, self::$lastNotifyArgs[9] );
85  $this->assertEquals( 0, self::$lastNotifyArgs[10] );
86  }
87 
88  public function testChangeRemovedNoRev() {
89  $change = $this->newChange();
90  $change->triggerCategoryRemovedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
91 
92  $this->assertEquals( 1, self::$notifyCallCounter );
93 
94  $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
95  $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
96  $this->assertEquals( '(autochange-username)', self::$lastNotifyArgs[2]->getName() );
97  $this->assertEquals( '(recentchanges-page-removed-from-category: ' . self::$pageName . ')',
98  self::$lastNotifyArgs[3] );
99  $this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() );
100  $this->assertEquals( 0, self::$lastNotifyArgs[5] );
101  $this->assertEquals( 0, self::$lastNotifyArgs[6] );
102  $this->assertEquals( null, self::$lastNotifyArgs[7] );
103  $this->assertEquals( 1, self::$lastNotifyArgs[8] );
104  $this->assertEquals( null, self::$lastNotifyArgs[9] );
105  $this->assertEquals( 0, self::$lastNotifyArgs[10] );
106  }
107 
108  public function testChangeAddedWithRev() {
109  $revision = Revision::newFromId( Title::newFromText( self::$pageName )->getLatestRevID() );
110  $change = $this->newChange( $revision );
111  $change->triggerCategoryAddedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
112 
113  $this->assertEquals( 1, self::$notifyCallCounter );
114 
115  $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
116  $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
117  $this->assertEquals( 'UTSysop', self::$lastNotifyArgs[2]->getName() );
118  $this->assertEquals( '(recentchanges-page-added-to-category: ' . self::$pageName . ')',
119  self::$lastNotifyArgs[3] );
120  $this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() );
121  $this->assertEquals( self::$pageRev->getParentId(), self::$lastNotifyArgs[5] );
122  $this->assertEquals( $revision->getId(), self::$lastNotifyArgs[6] );
123  $this->assertEquals( null, self::$lastNotifyArgs[7] );
124  $this->assertEquals( 0, self::$lastNotifyArgs[8] );
125  $this->assertEquals( '127.0.0.1', self::$lastNotifyArgs[9] );
126  $this->assertEquals( 0, self::$lastNotifyArgs[10] );
127  }
128 
129  public function testChangeRemovedWithRev() {
130  $revision = Revision::newFromId( Title::newFromText( self::$pageName )->getLatestRevID() );
131  $change = $this->newChange( $revision );
132  $change->triggerCategoryRemovedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
133 
134  $this->assertEquals( 1, self::$notifyCallCounter );
135 
136  $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
137  $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
138  $this->assertEquals( 'UTSysop', self::$lastNotifyArgs[2]->getName() );
139  $this->assertEquals( '(recentchanges-page-removed-from-category: ' . self::$pageName . ')',
140  self::$lastNotifyArgs[3] );
141  $this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() );
142  $this->assertEquals( self::$pageRev->getParentId(), self::$lastNotifyArgs[5] );
143  $this->assertEquals( $revision->getId(), self::$lastNotifyArgs[6] );
144  $this->assertEquals( null, self::$lastNotifyArgs[7] );
145  $this->assertEquals( 0, self::$lastNotifyArgs[8] );
146  $this->assertEquals( '127.0.0.1', self::$lastNotifyArgs[9] );
147  $this->assertEquals( 0, self::$lastNotifyArgs[10] );
148  }
149 
150 }
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:99
insertPage($pageName, $text= 'Sample page for unit test.')
Insert a new page.
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:277
static array Title[] User[] $lastNotifyArgs
Base class that store and restore the Language objects.
const NS_CATEGORY
Definition: Defines.php:83
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
static newFromId($id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:99
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:35
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2338