Merge "Reject usernames with # as user-type API parameters"
[lhc/web/wiklou.git] / tests / phpunit / includes / changes / CategoryMembershipChangeTest.php
1 <?php
2
3 /**
4 * @covers CategoryMembershipChange
5 *
6 * @group Database
7 *
8 * @author Addshore
9 */
10 class CategoryMembershipChangeTest extends MediaWikiLangTestCase {
11
12 /**
13 * @var array|Title[]|User[]
14 */
15 private static $lastNotifyArgs;
16
17 /**
18 * @var int
19 */
20 private static $notifyCallCounter = 0;
21
22 /**
23 * @var RecentChange
24 */
25 private static $mockRecentChange;
26
27 /**
28 * @var Revision
29 */
30 private static $pageRev = null;
31
32 /**
33 * @var string
34 */
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
55 $page = WikiPage::factory( $title );
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 }