4 * @covers CategoryMembershipChange
10 class CategoryMembershipChangeTest
extends MediaWikiLangTestCase
{
13 * @var array|Title[]|User[]
15 private static $lastNotifyArgs;
20 private static $notifyCallCounter = 0;
25 private static $mockRecentChange;
30 private static $pageRev = null;
35 private static $pageName = 'CategoryMembershipChangeTestPage';
37 public static function newForCategorizationCallback() {
38 self
::$lastNotifyArgs = func_get_args();
39 self
::$notifyCallCounter +
= 1;
40 return self
::$mockRecentChange;
43 public function setUp() {
45 self
::$notifyCallCounter = 0;
46 self
::$mockRecentChange = self
::getMock( 'RecentChange' );
48 $this->setContentLang( 'qqx' );
51 public function addDBDataOnce() {
52 $info = $this->insertPage( self
::$pageName );
53 $title = $info['title'];
55 $page = WikiPage
::factory( $title );
56 self
::$pageRev = $page->getRevision();
59 private function newChange( Revision
$revision = null ) {
60 $change = new CategoryMembershipChange( Title
::newFromText( self
::$pageName ), $revision );
61 $change->overrideNewForCategorizationCallback(
62 'CategoryMembershipChangeTest::newForCategorizationCallback'
68 public function testChangeAddedNoRev() {
69 $change = $this->newChange();
70 $change->triggerCategoryAddedNotification( Title
::newFromText( 'CategoryName', NS_CATEGORY
) );
72 $this->assertEquals( 1, self
::$notifyCallCounter );
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] );
88 public function testChangeRemovedNoRev() {
89 $change = $this->newChange();
90 $change->triggerCategoryRemovedNotification( Title
::newFromText( 'CategoryName', NS_CATEGORY
) );
92 $this->assertEquals( 1, self
::$notifyCallCounter );
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] );
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
) );
113 $this->assertEquals( 1, self
::$notifyCallCounter );
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] );
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
) );
134 $this->assertEquals( 1, self
::$notifyCallCounter );
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] );