https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112416
Revision: 112416 Author: hashar Date: 2012-02-25 21:39:54 +0000 (Sat, 25 Feb 2012) Log Message: ----------- rename test file to end with Test.php :D Added Paths: ----------- trunk/phase3/tests/phpunit/includes/RecentChangeTest.php Removed Paths: ------------- trunk/phase3/tests/phpunit/includes/RecentChange.php Deleted: trunk/phase3/tests/phpunit/includes/RecentChange.php =================================================================== --- trunk/phase3/tests/phpunit/includes/RecentChange.php 2012-02-25 21:22:49 UTC (rev 112415) +++ trunk/phase3/tests/phpunit/includes/RecentChange.php 2012-02-25 21:39:54 UTC (rev 112416) @@ -1,178 +0,0 @@ -<?php -class RecentChangeTest extends MediaWikiTestCase { - protected $title; - protected $target; - protected $user; - protected $user_comment; - - function __construct() { - parent::__construct(); - - $this->title = Title::newFromText( 'SomeTitle' ); - $this->target = Title::newFromText( 'TestTarget' ); - $this->user = User::newFromName( 'UserName' ); - - $this->user_comment = '<User comment about action>'; - } - - /** - * The testIrcMsgForAction* tests are supposed to cover the hacky - * LogFormatter::getIRCActionText / bug 34508 - * - * Third parties bots listen to those messages. They are clever enough - * to fetch the i18n messages from the wiki and then analyze the IRC feed - * to reverse engineer the $1, $2 messages. - * One thing bots can not detect is when MediaWiki change the meaning of - * a message like what happened when we deployed 1.19. $1 became the user - * performing the action which broke basically all bots around. - * - * Need to cover the various switches cases: - * move: move, move_redir, move-noredirect, move_redir-noredirect - * delete: delete, restore - * patrol: patrol - * newusers: newusers, create, create2, autocreate - * upload: upload, overwrite - * suppress - * and default case - */ - - /** - * @covers LogFormatter::getIRCActionText - */ - function testIrcMsgForActionMove() { - $move_params = array( - '4::target' => $this->target->getPrefixedText(), - '5::noredir' => 0, - ); - - # move/move - $this->assertIRCComment( - "moved [[SomeTitle]] to [[TestTarget]]: {$this->user_comment}" - , 'move', 'move' - , $move_params - ); - - # move/move_redir - $this->assertIRCComment( - "moved [[SomeTitle]] to [[TestTarget]] over redirect: {$this->user_comment}" - , 'move', 'move_redir' - , $move_params - ); - } - - /** - * @covers LogFormatter::getIRCActionText - */ - function testIrcMsgForActionDelete() { - # delete/delete - $this->assertIRCComment( - "deleted "[[SomeTitle]]": {$this->user_comment}" - , 'delete', 'delete' - , array() - ); - - # delete/restore - $this->assertIRCComment( - "restored "[[SomeTitle]]": {$this->user_comment}" - , 'delete', 'restore' - , array() - ); - } - - /** - * @covers LogFormatter::getIRCActionText - */ - function testIrcMsgForActionPatrol() { - # patrol/patrol - $this->assertIRCComment( - "marked revision 777 of [[SomeTitle]] patrolled : {$this->user_comment}" - , 'patrol', 'patrol' - , array( - '4::curid' => '777', - '5::previd' => '666', - '6::auto' => 0, - - ) - ); - } - - /** - * @covers LogFormatter::getIRCActionText - */ - function testIrcMsgForActionNewusers() { - $this->assertIRCComment( - "New user account: {$this->user_comment}" - , 'newusers', 'newusers' - , array() - ); - $this->assertIRCComment( - "New user account: {$this->user_comment}" - , 'newusers', 'create' - , array() - ); - $this->assertIRCComment( - "created new account SomeTitle: {$this->user_comment}" - , 'newusers', 'create2' - , array() - ); - $this->assertIRCComment( - "Account created automatically: {$this->user_comment}" - , 'newusers', 'autocreate' - , array() - ); - } - - /** - * @covers LogFormatter::getIRCActionText - */ - function testIrcMsgForActionUpload() { - # upload/upload - $this->assertIRCComment( - "uploaded "[[SomeTitle]]": {$this->user_comment}" - , 'upload', 'upload' - , array() - ); - - # upload/overwrite - $this->assertIRCComment( - "uploaded a new version of "[[SomeTitle]]": {$this->user_comment}" - , 'upload', 'overwrite' - , array() - ); - } - - /** - * @covers LogFormatter::getIRCActionText - */ - function testIrcMsgForActionSuppress() { - $this->assertIRCComment( - "{$this->user_comment}" - , 'suppress', '' - , array() - ); - } - - /** - * @param $expected String Expected IRC text without colors codes - * @param $type String Log type (move, delete, suppress, patrol ...) - * @param $action String A log type action - * @param $msg String (optional) A message for PHPUnit :-) - */ - function assertIRCComment( $expected, $type, $action, $params, $msg = '' ) { - - $logEntry = new ManualLogEntry( $type, $action ); - $logEntry->setPerformer( $this->user ); - $logEntry->setTarget ( $this->title ); - $logEntry->setComment ( $this->user_comment ); - $logEntry->setParameters( $params ); - - $formatter = LogFormatter::newFromEntry( $logEntry ); - $formatter->setContext( RequestContext::newExtraneousContext( $this->title ) ); - - $this->assertEquals( $expected, - $formatter->getIRCActionComment( ), - $msg - ); - } - -} Copied: trunk/phase3/tests/phpunit/includes/RecentChangeTest.php (from rev 112415, trunk/phase3/tests/phpunit/includes/RecentChange.php) =================================================================== --- trunk/phase3/tests/phpunit/includes/RecentChangeTest.php (rev 0) +++ trunk/phase3/tests/phpunit/includes/RecentChangeTest.php 2012-02-25 21:39:54 UTC (rev 112416) @@ -0,0 +1,178 @@ +<?php +class RecentChangeTest extends MediaWikiTestCase { + protected $title; + protected $target; + protected $user; + protected $user_comment; + + function __construct() { + parent::__construct(); + + $this->title = Title::newFromText( 'SomeTitle' ); + $this->target = Title::newFromText( 'TestTarget' ); + $this->user = User::newFromName( 'UserName' ); + + $this->user_comment = '<User comment about action>'; + } + + /** + * The testIrcMsgForAction* tests are supposed to cover the hacky + * LogFormatter::getIRCActionText / bug 34508 + * + * Third parties bots listen to those messages. They are clever enough + * to fetch the i18n messages from the wiki and then analyze the IRC feed + * to reverse engineer the $1, $2 messages. + * One thing bots can not detect is when MediaWiki change the meaning of + * a message like what happened when we deployed 1.19. $1 became the user + * performing the action which broke basically all bots around. + * + * Need to cover the various switches cases: + * move: move, move_redir, move-noredirect, move_redir-noredirect + * delete: delete, restore + * patrol: patrol + * newusers: newusers, create, create2, autocreate + * upload: upload, overwrite + * suppress + * and default case + */ + + /** + * @covers LogFormatter::getIRCActionText + */ + function testIrcMsgForActionMove() { + $move_params = array( + '4::target' => $this->target->getPrefixedText(), + '5::noredir' => 0, + ); + + # move/move + $this->assertIRCComment( + "moved [[SomeTitle]] to [[TestTarget]]: {$this->user_comment}" + , 'move', 'move' + , $move_params + ); + + # move/move_redir + $this->assertIRCComment( + "moved [[SomeTitle]] to [[TestTarget]] over redirect: {$this->user_comment}" + , 'move', 'move_redir' + , $move_params + ); + } + + /** + * @covers LogFormatter::getIRCActionText + */ + function testIrcMsgForActionDelete() { + # delete/delete + $this->assertIRCComment( + "deleted "[[SomeTitle]]": {$this->user_comment}" + , 'delete', 'delete' + , array() + ); + + # delete/restore + $this->assertIRCComment( + "restored "[[SomeTitle]]": {$this->user_comment}" + , 'delete', 'restore' + , array() + ); + } + + /** + * @covers LogFormatter::getIRCActionText + */ + function testIrcMsgForActionPatrol() { + # patrol/patrol + $this->assertIRCComment( + "marked revision 777 of [[SomeTitle]] patrolled : {$this->user_comment}" + , 'patrol', 'patrol' + , array( + '4::curid' => '777', + '5::previd' => '666', + '6::auto' => 0, + + ) + ); + } + + /** + * @covers LogFormatter::getIRCActionText + */ + function testIrcMsgForActionNewusers() { + $this->assertIRCComment( + "New user account: {$this->user_comment}" + , 'newusers', 'newusers' + , array() + ); + $this->assertIRCComment( + "New user account: {$this->user_comment}" + , 'newusers', 'create' + , array() + ); + $this->assertIRCComment( + "created new account SomeTitle: {$this->user_comment}" + , 'newusers', 'create2' + , array() + ); + $this->assertIRCComment( + "Account created automatically: {$this->user_comment}" + , 'newusers', 'autocreate' + , array() + ); + } + + /** + * @covers LogFormatter::getIRCActionText + */ + function testIrcMsgForActionUpload() { + # upload/upload + $this->assertIRCComment( + "uploaded "[[SomeTitle]]": {$this->user_comment}" + , 'upload', 'upload' + , array() + ); + + # upload/overwrite + $this->assertIRCComment( + "uploaded a new version of "[[SomeTitle]]": {$this->user_comment}" + , 'upload', 'overwrite' + , array() + ); + } + + /** + * @covers LogFormatter::getIRCActionText + */ + function testIrcMsgForActionSuppress() { + $this->assertIRCComment( + "{$this->user_comment}" + , 'suppress', '' + , array() + ); + } + + /** + * @param $expected String Expected IRC text without colors codes + * @param $type String Log type (move, delete, suppress, patrol ...) + * @param $action String A log type action + * @param $msg String (optional) A message for PHPUnit :-) + */ + function assertIRCComment( $expected, $type, $action, $params, $msg = '' ) { + + $logEntry = new ManualLogEntry( $type, $action ); + $logEntry->setPerformer( $this->user ); + $logEntry->setTarget ( $this->title ); + $logEntry->setComment ( $this->user_comment ); + $logEntry->setParameters( $params ); + + $formatter = LogFormatter::newFromEntry( $logEntry ); + $formatter->setContext( RequestContext::newExtraneousContext( $this->title ) ); + + $this->assertEquals( $expected, + $formatter->getIRCActionComment( ), + $msg + ); + } + +} _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs