TableDiffFormatter: Don't repeatedly call array_shift()
[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 public static function newForCategorizationCallback() {
28 self::$lastNotifyArgs = func_get_args();
29 self::$notifyCallCounter += 1;
30 return self::$mockRecentChange;
31 }
32
33 public function setUp() {
34 parent::setUp();
35 self::$notifyCallCounter = 0;
36 self::$mockRecentChange = self::getMock( 'RecentChange' );
37 }
38
39 private function newChange( Revision $revision = null ) {
40 $change = new CategoryMembershipChange( Title::newFromText( 'UTPage' ), $revision );
41 $change->overrideNewForCategorizationCallback(
42 'CategoryMembershipChangeTest::newForCategorizationCallback'
43 );
44
45 return $change;
46 }
47
48 public function testChangeAddedNoRev() {
49 $change = $this->newChange();
50 $change->triggerCategoryAddedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
51
52 $this->assertEquals( 1, self::$notifyCallCounter );
53
54 $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
55 $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
56 $this->assertEquals( 'MediaWiki automatic change', self::$lastNotifyArgs[2]->getName() );
57 $this->assertEquals( '[[:UTPage]] added to category', self::$lastNotifyArgs[3] );
58 $this->assertEquals( 'UTPage', self::$lastNotifyArgs[4]->getPrefixedText() );
59 $this->assertEquals( 0, self::$lastNotifyArgs[5] );
60 $this->assertEquals( 0, self::$lastNotifyArgs[6] );
61 $this->assertEquals( null, self::$lastNotifyArgs[7] );
62 $this->assertEquals( 1, self::$lastNotifyArgs[8] );
63 $this->assertEquals( null, self::$lastNotifyArgs[9] );
64 $this->assertEquals( 0, self::$lastNotifyArgs[10] );
65 }
66
67 public function testChangeRemovedNoRev() {
68 $change = $this->newChange();
69 $change->triggerCategoryRemovedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
70
71 $this->assertEquals( 1, self::$notifyCallCounter );
72
73 $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
74 $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
75 $this->assertEquals( 'MediaWiki automatic change', self::$lastNotifyArgs[2]->getName() );
76 $this->assertEquals( '[[:UTPage]] removed from category', self::$lastNotifyArgs[3] );
77 $this->assertEquals( 'UTPage', self::$lastNotifyArgs[4]->getPrefixedText() );
78 $this->assertEquals( 0, self::$lastNotifyArgs[5] );
79 $this->assertEquals( 0, self::$lastNotifyArgs[6] );
80 $this->assertEquals( null, self::$lastNotifyArgs[7] );
81 $this->assertEquals( 1, self::$lastNotifyArgs[8] );
82 $this->assertEquals( null, self::$lastNotifyArgs[9] );
83 $this->assertEquals( 0, self::$lastNotifyArgs[10] );
84 }
85
86 public function testChangeAddedWithRev() {
87 $revision = Revision::newFromId( Title::newFromText( 'UTPage' )->getLatestRevID() );
88 $change = $this->newChange( $revision );
89 $change->triggerCategoryAddedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
90
91 $this->assertEquals( 1, self::$notifyCallCounter );
92
93 $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
94 $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
95 $this->assertEquals( 'UTSysop', self::$lastNotifyArgs[2]->getName() );
96 $this->assertEquals( '[[:UTPage]] added to category', self::$lastNotifyArgs[3] );
97 $this->assertEquals( 'UTPage', self::$lastNotifyArgs[4]->getPrefixedText() );
98 $this->assertEquals( 0, self::$lastNotifyArgs[5] );
99 $this->assertEquals( $revision->getId(), self::$lastNotifyArgs[6] );
100 $this->assertEquals( null, self::$lastNotifyArgs[7] );
101 $this->assertEquals( 0, self::$lastNotifyArgs[8] );
102 $this->assertEquals( '127.0.0.1', self::$lastNotifyArgs[9] );
103 $this->assertEquals( 0, self::$lastNotifyArgs[10] );
104 }
105
106 public function testChangeRemovedWithRev() {
107 $revision = Revision::newFromId( Title::newFromText( 'UTPage' )->getLatestRevID() );
108 $change = $this->newChange( $revision );
109 $change->triggerCategoryRemovedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
110
111 $this->assertEquals( 1, self::$notifyCallCounter );
112
113 $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
114 $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
115 $this->assertEquals( 'UTSysop', self::$lastNotifyArgs[2]->getName() );
116 $this->assertEquals( '[[:UTPage]] removed from category', self::$lastNotifyArgs[3] );
117 $this->assertEquals( 'UTPage', self::$lastNotifyArgs[4]->getPrefixedText() );
118 $this->assertEquals( 0, self::$lastNotifyArgs[5] );
119 $this->assertEquals( $revision->getId(), self::$lastNotifyArgs[6] );
120 $this->assertEquals( null, self::$lastNotifyArgs[7] );
121 $this->assertEquals( 0, self::$lastNotifyArgs[8] );
122 $this->assertEquals( '127.0.0.1', self::$lastNotifyArgs[9] );
123 $this->assertEquals( 0, self::$lastNotifyArgs[10] );
124 }
125
126 }