4 * @covers CategoryMembershipChange
8 * @author Adam Shorland
10 class CategoryMembershipChangeTest
extends MediaWikiLangTestCase
{
13 * @var array|Title[]|User[]
15 private static $lastNotifyArgs;
20 private static $notifyCallCounter = 0;
25 private static $mockRecentChange;
27 public static function newForCategorizationCallback() {
28 self
::$lastNotifyArgs = func_get_args();
29 self
::$notifyCallCounter +
= 1;
30 return self
::$mockRecentChange;
33 public function setUp() {
35 self
::$notifyCallCounter = 0;
36 self
::$mockRecentChange = self
::getMock( 'RecentChange' );
39 private function newChange( Revision
$revision = null ) {
40 $change = new CategoryMembershipChange( Title
::newFromText( 'UTPage' ), $revision );
41 $change->overrideNewForCategorizationCallback(
42 'CategoryMembershipChangeTest::newForCategorizationCallback'
48 public function testChangeAddedNoRev() {
49 $change = $this->newChange();
50 $change->triggerCategoryAddedNotification( Title
::newFromText( 'CategoryName', NS_CATEGORY
) );
52 $this->assertEquals( 1, self
::$notifyCallCounter );
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] );
67 public function testChangeRemovedNoRev() {
68 $change = $this->newChange();
69 $change->triggerCategoryRemovedNotification( Title
::newFromText( 'CategoryName', NS_CATEGORY
) );
71 $this->assertEquals( 1, self
::$notifyCallCounter );
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] );
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
) );
91 $this->assertEquals( 1, self
::$notifyCallCounter );
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] );
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
) );
111 $this->assertEquals( 1, self
::$notifyCallCounter );
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] );