MediaWiki  1.33.0
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 $revUser = null;
36 
40  private static $pageName = 'CategoryMembershipChangeTestPage';
41 
42  public static function newForCategorizationCallback() {
43  self::$lastNotifyArgs = func_get_args();
44  self::$notifyCallCounter += 1;
46  }
47 
48  public function setUp() {
49  parent::setUp();
50  self::$notifyCallCounter = 0;
51  self::$mockRecentChange = self::getMock( RecentChange::class );
52 
53  $this->setContentLang( 'qqx' );
54  }
55 
56  public function addDBDataOnce() {
57  $info = $this->insertPage( self::$pageName );
58  $title = $info['title'];
59 
60  $page = WikiPage::factory( $title );
61  self::$pageRev = $page->getRevision();
62  self::$revUser = User::newFromId( self::$pageRev->getUser( Revision::RAW ) );
63  }
64 
65  private function newChange( Revision $revision = null ) {
66  $change = new CategoryMembershipChange( Title::newFromText( self::$pageName ), $revision );
67  $change->overrideNewForCategorizationCallback(
68  'CategoryMembershipChangeTest::newForCategorizationCallback'
69  );
70 
71  return $change;
72  }
73 
74  public function testChangeAddedNoRev() {
75  $change = $this->newChange();
76  $change->triggerCategoryAddedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
77 
78  $this->assertEquals( 1, self::$notifyCallCounter );
79 
80  $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
81  $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
82  $this->assertEquals( '(autochange-username)', self::$lastNotifyArgs[2]->getName() );
83  $this->assertEquals( '(recentchanges-page-added-to-category: ' . self::$pageName . ')',
84  self::$lastNotifyArgs[3] );
85  $this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() );
86  $this->assertEquals( 0, self::$lastNotifyArgs[5] );
87  $this->assertEquals( 0, self::$lastNotifyArgs[6] );
88  $this->assertEquals( null, self::$lastNotifyArgs[7] );
89  $this->assertEquals( 1, self::$lastNotifyArgs[8] );
90  $this->assertEquals( null, self::$lastNotifyArgs[9] );
91  $this->assertEquals( 0, self::$lastNotifyArgs[10] );
92  }
93 
94  public function testChangeRemovedNoRev() {
95  $change = $this->newChange();
96  $change->triggerCategoryRemovedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
97 
98  $this->assertEquals( 1, self::$notifyCallCounter );
99 
100  $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
101  $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
102  $this->assertEquals( '(autochange-username)', self::$lastNotifyArgs[2]->getName() );
103  $this->assertEquals( '(recentchanges-page-removed-from-category: ' . self::$pageName . ')',
104  self::$lastNotifyArgs[3] );
105  $this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() );
106  $this->assertEquals( 0, self::$lastNotifyArgs[5] );
107  $this->assertEquals( 0, self::$lastNotifyArgs[6] );
108  $this->assertEquals( null, self::$lastNotifyArgs[7] );
109  $this->assertEquals( 1, self::$lastNotifyArgs[8] );
110  $this->assertEquals( null, self::$lastNotifyArgs[9] );
111  $this->assertEquals( 0, self::$lastNotifyArgs[10] );
112  }
113 
114  public function testChangeAddedWithRev() {
115  $revision = Revision::newFromId( Title::newFromText( self::$pageName )->getLatestRevID() );
116  $change = $this->newChange( $revision );
117  $change->triggerCategoryAddedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
118 
119  $this->assertEquals( 1, self::$notifyCallCounter );
120 
121  $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
122  $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
123  $this->assertEquals( self::$revUser->getName(), self::$lastNotifyArgs[2]->getName() );
124  $this->assertEquals( '(recentchanges-page-added-to-category: ' . self::$pageName . ')',
125  self::$lastNotifyArgs[3] );
126  $this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() );
127  $this->assertEquals( self::$pageRev->getParentId(), self::$lastNotifyArgs[5] );
128  $this->assertEquals( $revision->getId(), self::$lastNotifyArgs[6] );
129  $this->assertEquals( null, self::$lastNotifyArgs[7] );
130  $this->assertEquals( 0, self::$lastNotifyArgs[8] );
131  $this->assertEquals( '127.0.0.1', self::$lastNotifyArgs[9] );
132  $this->assertEquals( 0, self::$lastNotifyArgs[10] );
133  }
134 
135  public function testChangeRemovedWithRev() {
136  $revision = Revision::newFromId( Title::newFromText( self::$pageName )->getLatestRevID() );
137  $change = $this->newChange( $revision );
138  $change->triggerCategoryRemovedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
139 
140  $this->assertEquals( 1, self::$notifyCallCounter );
141 
142  $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
143  $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
144  $this->assertEquals( self::$revUser->getName(), self::$lastNotifyArgs[2]->getName() );
145  $this->assertEquals( '(recentchanges-page-removed-from-category: ' . self::$pageName . ')',
146  self::$lastNotifyArgs[3] );
147  $this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() );
148  $this->assertEquals( self::$pageRev->getParentId(), self::$lastNotifyArgs[5] );
149  $this->assertEquals( $revision->getId(), self::$lastNotifyArgs[6] );
150  $this->assertEquals( null, self::$lastNotifyArgs[7] );
151  $this->assertEquals( 0, self::$lastNotifyArgs[8] );
152  $this->assertEquals( '127.0.0.1', self::$lastNotifyArgs[9] );
153  $this->assertEquals( 0, self::$lastNotifyArgs[10] );
154  }
155 
156 }
CategoryMembershipChangeTest\$pageName
static string $pageName
Definition: CategoryMembershipChangeTest.php:40
CategoryMembershipChangeTest
CategoryMembershipChange.
Definition: CategoryMembershipChangeTest.php:10
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:609
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:306
Revision\newFromId
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:118
RecentChange
Utility class for creating new RC entries.
Definition: RecentChange.php:69
CategoryMembershipChangeTest\testChangeAddedNoRev
testChangeAddedNoRev()
Definition: CategoryMembershipChangeTest.php:74
CategoryMembershipChangeTest\newForCategorizationCallback
static newForCategorizationCallback()
Definition: CategoryMembershipChangeTest.php:42
CategoryMembershipChangeTest\testChangeRemovedNoRev
testChangeRemovedNoRev()
Definition: CategoryMembershipChangeTest.php:94
MediaWikiTestCase\insertPage
insertPage( $pageName, $text='Sample page for unit test.', $namespace=null, User $user=null)
Insert a new page.
Definition: MediaWikiTestCase.php:1222
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:35
CategoryMembershipChangeTest\testChangeRemovedWithRev
testChangeRemovedWithRev()
Definition: CategoryMembershipChangeTest.php:135
Revision
Definition: Revision.php:40
CategoryMembershipChangeTest\$pageRev
static Revision $pageRev
Definition: CategoryMembershipChangeTest.php:30
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
CategoryMembershipChangeTest\$lastNotifyArgs
static array Title[] User[] $lastNotifyArgs
Definition: CategoryMembershipChangeTest.php:15
CategoryMembershipChangeTest\setUp
setUp()
Definition: CategoryMembershipChangeTest.php:48
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:78
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
MediaWikiTestCase\setContentLang
setContentLang( $lang)
Definition: MediaWikiTestCase.php:1066
CategoryMembershipChangeTest\$revUser
static User $revUser
Definition: CategoryMembershipChangeTest.php:35
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:8
CategoryMembershipChangeTest\$notifyCallCounter
static int $notifyCallCounter
Definition: CategoryMembershipChangeTest.php:20
Revision\RAW
const RAW
Definition: Revision.php:56
CategoryMembershipChangeTest\testChangeAddedWithRev
testChangeAddedWithRev()
Definition: CategoryMembershipChangeTest.php:114
CategoryMembershipChangeTest\$mockRecentChange
static RecentChange $mockRecentChange
Definition: CategoryMembershipChangeTest.php:25
Title
Represents a title within MediaWiki.
Definition: Title.php:40
CategoryMembershipChangeTest\newChange
newChange(Revision $revision=null)
Definition: CategoryMembershipChangeTest.php:65
CategoryMembershipChangeTest\addDBDataOnce
addDBDataOnce()
Stub.
Definition: CategoryMembershipChangeTest.php:56
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
CategoryMembershipChange
Definition: CategoryMembershipChange.php:26
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:48