2015-09-17 09:51:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers CategoryMembershipChange
|
|
|
|
|
*
|
|
|
|
|
* @group Database
|
|
|
|
|
*
|
2016-01-27 09:59:31 +00:00
|
|
|
* @author Addshore
|
2015-09-17 09:51:25 +00:00
|
|
|
*/
|
|
|
|
|
class CategoryMembershipChangeTest extends MediaWikiLangTestCase {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var array|Title[]|User[]
|
|
|
|
|
*/
|
|
|
|
|
private static $lastNotifyArgs;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
|
|
|
|
private static $notifyCallCounter = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var RecentChange
|
|
|
|
|
*/
|
|
|
|
|
private static $mockRecentChange;
|
|
|
|
|
|
2016-03-07 17:26:25 +00:00
|
|
|
/**
|
|
|
|
|
* @var Revision
|
|
|
|
|
*/
|
|
|
|
|
private static $pageRev = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private static $pageName = 'CategoryMembershipChangeTestPage';
|
|
|
|
|
|
2015-09-17 09:51:25 +00:00
|
|
|
public static function newForCategorizationCallback() {
|
|
|
|
|
self::$lastNotifyArgs = func_get_args();
|
|
|
|
|
self::$notifyCallCounter += 1;
|
|
|
|
|
return self::$mockRecentChange;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
self::$notifyCallCounter = 0;
|
|
|
|
|
self::$mockRecentChange = self::getMock( 'RecentChange' );
|
2016-03-07 17:26:25 +00:00
|
|
|
|
|
|
|
|
$this->setContentLang( 'qqx' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addDBDataOnce() {
|
|
|
|
|
$info = $this->insertPage( self::$pageName );
|
|
|
|
|
$title = $info['title'];
|
|
|
|
|
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
self::$pageRev = $page->getRevision();
|
2015-09-17 09:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function newChange( Revision $revision = null ) {
|
2016-03-07 17:26:25 +00:00
|
|
|
$change = new CategoryMembershipChange( Title::newFromText( self::$pageName ), $revision );
|
2015-09-17 09:51:25 +00:00
|
|
|
$change->overrideNewForCategorizationCallback(
|
|
|
|
|
'CategoryMembershipChangeTest::newForCategorizationCallback'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $change;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testChangeAddedNoRev() {
|
|
|
|
|
$change = $this->newChange();
|
|
|
|
|
$change->triggerCategoryAddedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( 1, self::$notifyCallCounter );
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
|
|
|
|
|
$this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
|
2016-03-07 17:26:25 +00:00
|
|
|
$this->assertEquals( '(autochange-username)', self::$lastNotifyArgs[2]->getName() );
|
2016-04-02 16:06:40 +00:00
|
|
|
$this->assertEquals( '(recentchanges-page-added-to-category: ' . self::$pageName . ')',
|
2016-03-07 17:26:25 +00:00
|
|
|
self::$lastNotifyArgs[3] );
|
|
|
|
|
$this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() );
|
2015-09-17 09:51:25 +00:00
|
|
|
$this->assertEquals( 0, self::$lastNotifyArgs[5] );
|
|
|
|
|
$this->assertEquals( 0, self::$lastNotifyArgs[6] );
|
|
|
|
|
$this->assertEquals( null, self::$lastNotifyArgs[7] );
|
|
|
|
|
$this->assertEquals( 1, self::$lastNotifyArgs[8] );
|
|
|
|
|
$this->assertEquals( null, self::$lastNotifyArgs[9] );
|
|
|
|
|
$this->assertEquals( 0, self::$lastNotifyArgs[10] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testChangeRemovedNoRev() {
|
|
|
|
|
$change = $this->newChange();
|
|
|
|
|
$change->triggerCategoryRemovedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( 1, self::$notifyCallCounter );
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
|
|
|
|
|
$this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
|
2016-03-07 17:26:25 +00:00
|
|
|
$this->assertEquals( '(autochange-username)', self::$lastNotifyArgs[2]->getName() );
|
2016-04-02 16:06:40 +00:00
|
|
|
$this->assertEquals( '(recentchanges-page-removed-from-category: ' . self::$pageName . ')',
|
2016-03-07 17:26:25 +00:00
|
|
|
self::$lastNotifyArgs[3] );
|
|
|
|
|
$this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() );
|
2015-09-17 09:51:25 +00:00
|
|
|
$this->assertEquals( 0, self::$lastNotifyArgs[5] );
|
|
|
|
|
$this->assertEquals( 0, self::$lastNotifyArgs[6] );
|
|
|
|
|
$this->assertEquals( null, self::$lastNotifyArgs[7] );
|
|
|
|
|
$this->assertEquals( 1, self::$lastNotifyArgs[8] );
|
|
|
|
|
$this->assertEquals( null, self::$lastNotifyArgs[9] );
|
|
|
|
|
$this->assertEquals( 0, self::$lastNotifyArgs[10] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testChangeAddedWithRev() {
|
2016-03-07 17:26:25 +00:00
|
|
|
$revision = Revision::newFromId( Title::newFromText( self::$pageName )->getLatestRevID() );
|
2015-09-17 09:51:25 +00:00
|
|
|
$change = $this->newChange( $revision );
|
|
|
|
|
$change->triggerCategoryAddedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( 1, self::$notifyCallCounter );
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
|
|
|
|
|
$this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
|
|
|
|
|
$this->assertEquals( 'UTSysop', self::$lastNotifyArgs[2]->getName() );
|
2016-04-02 16:06:40 +00:00
|
|
|
$this->assertEquals( '(recentchanges-page-added-to-category: ' . self::$pageName . ')',
|
2016-03-07 17:26:25 +00:00
|
|
|
self::$lastNotifyArgs[3] );
|
|
|
|
|
$this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() );
|
|
|
|
|
$this->assertEquals( self::$pageRev->getParentId(), self::$lastNotifyArgs[5] );
|
2015-09-17 09:51:25 +00:00
|
|
|
$this->assertEquals( $revision->getId(), self::$lastNotifyArgs[6] );
|
|
|
|
|
$this->assertEquals( null, self::$lastNotifyArgs[7] );
|
|
|
|
|
$this->assertEquals( 0, self::$lastNotifyArgs[8] );
|
|
|
|
|
$this->assertEquals( '127.0.0.1', self::$lastNotifyArgs[9] );
|
|
|
|
|
$this->assertEquals( 0, self::$lastNotifyArgs[10] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testChangeRemovedWithRev() {
|
2016-03-07 17:26:25 +00:00
|
|
|
$revision = Revision::newFromId( Title::newFromText( self::$pageName )->getLatestRevID() );
|
2015-09-17 09:51:25 +00:00
|
|
|
$change = $this->newChange( $revision );
|
|
|
|
|
$change->triggerCategoryRemovedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( 1, self::$notifyCallCounter );
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 );
|
|
|
|
|
$this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() );
|
|
|
|
|
$this->assertEquals( 'UTSysop', self::$lastNotifyArgs[2]->getName() );
|
2016-04-02 16:06:40 +00:00
|
|
|
$this->assertEquals( '(recentchanges-page-removed-from-category: ' . self::$pageName . ')',
|
2016-03-07 17:26:25 +00:00
|
|
|
self::$lastNotifyArgs[3] );
|
|
|
|
|
$this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() );
|
|
|
|
|
$this->assertEquals( self::$pageRev->getParentId(), self::$lastNotifyArgs[5] );
|
2015-09-17 09:51:25 +00:00
|
|
|
$this->assertEquals( $revision->getId(), self::$lastNotifyArgs[6] );
|
|
|
|
|
$this->assertEquals( null, self::$lastNotifyArgs[7] );
|
|
|
|
|
$this->assertEquals( 0, self::$lastNotifyArgs[8] );
|
|
|
|
|
$this->assertEquals( '127.0.0.1', self::$lastNotifyArgs[9] );
|
|
|
|
|
$this->assertEquals( 0, self::$lastNotifyArgs[10] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|