From 1879a95a76cc3aa1f9fa357cf74c74e5ef8ceebd Mon Sep 17 00:00:00 2001 From: Siebrand Date: Mon, 10 Dec 2012 01:23:07 +0000 Subject: [PATCH] Revert "(bug 24620) Add tests for LogFormatter" As I6a56c204 breaks extensions because of changing protected methods to public, this has to be reverted. We need a solid solution and the next 1.21-wmf is being branched tomorrow. Revert is the sanest solution at the moment. This reverts commit 888fe0ffb367e9714615e81f2890ec8314219125 --- includes/logging/LogFormatter.php | 12 +- .../includes/logging/LogFormatterTest.php | 200 ------------------ .../includes/logging/LogTests.i18n.php | 15 -- 3 files changed, 6 insertions(+), 221 deletions(-) delete mode 100755 tests/phpunit/includes/logging/LogFormatterTest.php delete mode 100755 tests/phpunit/includes/logging/LogTests.i18n.php diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index 1d8adf91db..f049126503 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -430,7 +430,7 @@ class LogFormatter { * - 3: target page with premade link * @return array */ - public function getMessageParameters() { + protected function getMessageParameters() { if ( isset( $this->parsedParameters ) ) { return $this->parsedParameters; } @@ -820,7 +820,7 @@ class MoveLogFormatter extends LogFormatter { return $key; } - public function getMessageParameters() { + protected function getMessageParameters() { $params = parent::getMessageParameters(); $oldname = $this->makePageLink( $this->entry->getTarget(), array( 'redirect' => 'no' ) ); $newname = $this->makePageLink( Title::newFromText( $params[3] ) ); @@ -873,7 +873,7 @@ class DeleteLogFormatter extends LogFormatter { return $key; } - public function getMessageParameters() { + protected function getMessageParameters() { if ( isset( $this->parsedParametersDeleteLog ) ) { return $this->parsedParametersDeleteLog; } @@ -1042,7 +1042,7 @@ class PatrolLogFormatter extends LogFormatter { return $key; } - public function getMessageParameters() { + protected function getMessageParameters() { $params = parent::getMessageParameters(); $target = $this->entry->getTarget(); @@ -1071,7 +1071,7 @@ class PatrolLogFormatter extends LogFormatter { * @since 1.19 */ class NewUsersLogFormatter extends LogFormatter { - public function getMessageParameters() { + protected function getMessageParameters() { $params = parent::getMessageParameters(); if ( $this->entry->getSubtype() === 'create2' ) { if ( isset( $params[3] ) ) { @@ -1138,7 +1138,7 @@ class RightsLogFormatter extends LogFormatter { return $key; } - public function getMessageParameters() { + protected function getMessageParameters() { $params = parent::getMessageParameters(); // Really old entries diff --git a/tests/phpunit/includes/logging/LogFormatterTest.php b/tests/phpunit/includes/logging/LogFormatterTest.php deleted file mode 100755 index 427be077d4..0000000000 --- a/tests/phpunit/includes/logging/LogFormatterTest.php +++ /dev/null @@ -1,200 +0,0 @@ -setMwGlobals( array( - 'wgLogTypes' => array( 'phpunit' ), - 'wgLogActionsHandlers' => array( 'phpunit/test' => 'LogFormatter', - 'phpunit/param' => 'LogFormatter' ), - 'wgUser' => User::newFromName( 'Testuser' ), - 'wgExtensionMessagesFiles' => array( 'LogTests' => __DIR__.'/LogTests.i18n.php' ), - ) ); - - $wgLang->getLocalisationCache()->recache( $wgLang->getCode() ); - - $this->user = User::newFromName( 'Testuser' ); - $this->title = Title::newMainPage(); - - $this->context = new RequestContext(); - $this->context->setUser( $this->user ); - $this->context->setTitle( $this->title ); - $this->context->setLanguage( $wgLang ); - } - - public function newLogEntry( $action, $params ) { - $logEntry = new ManualLogEntry( 'phpunit', $action ); - $logEntry->setPerformer( $this->user ); - $logEntry->setTarget( $this->title ); - $logEntry->setComment( 'A very good reason' ); - - $logEntry->setParameters( $params ); - - return $logEntry; - } - - public function testNormalLogParams() { - $entry = $this->newLogEntry( 'test', array() ); - $formatter = LogFormatter::newFromEntry( $entry ); - $formatter->setContext( $this->context ); - - $formatter->setShowUserToolLinks( false ); - $paramsWithoutTools = $formatter->getMessageParameters(); - unset( $formatter->parsedParameters ); - - $formatter->setShowUserToolLinks( true ); - $paramsWithTools = $formatter->getMessageParameters(); - - $userLink = Linker::userLink( - $this->user->getId(), - $this->user->getName() - ); - - $userTools = Linker::userToolLinksRedContribs( - $this->user->getId(), - $this->user->getName(), - $this->user->getEditCount() - ); - - $titleLink = Linker::link( $this->title, null, array(), array() ); - - // $paramsWithoutTools and $paramsWithTools should be only different - // in index 0 - $this->assertEquals( $paramsWithoutTools[1], $paramsWithTools[1] ); - $this->assertEquals( $paramsWithoutTools[2], $paramsWithTools[2] ); - - $this->assertEquals( $userLink, $paramsWithoutTools[0]['raw'] ); - $this->assertEquals( $userLink . $userTools, $paramsWithTools[0]['raw'] ); - - $this->assertEquals( $this->user->getName(), $paramsWithoutTools[1] ); - - $this->assertEquals( $titleLink, $paramsWithoutTools[2]['raw'] ); - } - - public function testLogParamsTypeRaw() { - $params = array( '4:raw:raw' => Linker::link( $this->title, null, array(), array() ) ); - $expected = Linker::link( $this->title, null, array(), array() ); - - $entry = $this->newLogEntry( 'param', $params ); - $formatter = LogFormatter::newFromEntry( $entry ); - $formatter->setContext( $this->context ); - - $logParam = $formatter->getActionText(); - - $this->assertEquals( $expected, $logParam ); - } - - public function testLogParamsTypeMsg() { - $params = array( '4:msg:msg' => 'log-description-phpunit' ); - $expected = wfMessage( 'log-description-phpunit' )->text(); - - $entry = $this->newLogEntry( 'param', $params ); - $formatter = LogFormatter::newFromEntry( $entry ); - $formatter->setContext( $this->context ); - - $logParam = $formatter->getActionText(); - - $this->assertEquals( $expected, $logParam ); - } - - public function testLogParamsTypeMsgContent() { - $params = array( '4:msg-content:msgContent' => 'log-description-phpunit' ); - $expected = wfMessage( 'log-description-phpunit' )->inContentLanguage()->text(); - - $entry = $this->newLogEntry( 'param', $params ); - $formatter = LogFormatter::newFromEntry( $entry ); - $formatter->setContext( $this->context ); - - $logParam = $formatter->getActionText(); - - $this->assertEquals( $expected, $logParam ); - } - - public function testLogParamsTypeNumber() { - global $wgLang; - - $params = array( '4:number:number' => 123456789 ); - $expected = $wgLang->formatNum( 123456789 ); - - $entry = $this->newLogEntry( 'param', $params ); - $formatter = LogFormatter::newFromEntry( $entry ); - $formatter->setContext( $this->context ); - - $logParam = $formatter->getActionText(); - - $this->assertEquals( $expected, $logParam ); - } - - public function testLogParamsTypeUserLink() { - $params = array( '4:user-link:userLink' => $this->user->getName() ); - $expected = Linker::userLink( - $this->user->getId(), - $this->user->getName() - ); - - $entry = $this->newLogEntry( 'param', $params ); - $formatter = LogFormatter::newFromEntry( $entry ); - $formatter->setContext( $this->context ); - - $logParam = $formatter->getActionText(); - - $this->assertEquals( $expected, $logParam ); - } - - public function testLogParamsTypeTitleLink() { - $params = array( '4:title-link:titleLink' => $this->title->getText() ); - $expected = Linker::link( $this->title, null, array(), array() ); - - $entry = $this->newLogEntry( 'param', $params ); - $formatter = LogFormatter::newFromEntry( $entry ); - $formatter->setContext( $this->context ); - - $logParam = $formatter->getActionText(); - - $this->assertEquals( $expected, $logParam ); - } - - public function testLogParamsTypePlain() { - $params = array( '4:plain:plain' => 'Some plain text' ); - $expected = 'Some plain text'; - - $entry = $this->newLogEntry( 'param', $params ); - $formatter = LogFormatter::newFromEntry( $entry ); - $formatter->setContext( $this->context ); - - $logParam = $formatter->getActionText(); - - $this->assertEquals( $expected, $logParam ); - } - - public function testLogComment() { - $entry = $this->newLogEntry( 'test', array() ); - $formatter = LogFormatter::newFromEntry( $entry ); - $formatter->setContext( $this->context ); - - $comment = ltrim( Linker::commentBlock( $entry->getComment() ) ); - - $this->assertEquals( $comment, $formatter->getComment() ); - } -} diff --git a/tests/phpunit/includes/logging/LogTests.i18n.php b/tests/phpunit/includes/logging/LogTests.i18n.php deleted file mode 100755 index 8a0a42174f..0000000000 --- a/tests/phpunit/includes/logging/LogTests.i18n.php +++ /dev/null @@ -1,15 +0,0 @@ - 'PHPUnit-log', - 'log-description-phpunit' => 'Log for PHPUnit-tests', - 'logentry-phpunit-test' => '$1 {{GENDER:$2|tests}} with page $3', - 'logentry-phpunit-param' => '$4', -); \ No newline at end of file -- 2.20.1