| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Api\ApiResult; |
| 4 |
use MediaWiki\Context\DerivativeContext; |
| 5 |
use MediaWiki\Context\RequestContext; |
| 6 |
use MediaWiki\Linker\Linker; |
| 7 |
use MediaWiki\MainConfigNames; |
| 8 |
use MediaWiki\Message\Message; |
| 9 |
use MediaWiki\Permissions\SimpleAuthority; |
| 10 |
use MediaWiki\RCFeed\IRCColourfulRCFeedFormatter; |
| 11 |
use MediaWiki\SpecialPage\SpecialPage; |
| 12 |
use MediaWiki\Title\Title; |
| 13 |
use MediaWiki\User\User; |
| 14 |
use MediaWiki\User\UserIdentityValue; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
class LogFormatterTest extends MediaWikiLangTestCase { |
| 20 |
|
| 21 |
private static $oldExtMsgFiles; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
protected $user; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
protected $title; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
protected $context; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
protected $target; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
protected $user_comment; |
| 47 |
|
| 48 |
public static function setUpBeforeClass(): void { |
| 49 |
parent::setUpBeforeClass(); |
| 50 |
|
| 51 |
global $wgExtensionMessagesFiles; |
| 52 |
self::$oldExtMsgFiles = $wgExtensionMessagesFiles; |
| 53 |
$wgExtensionMessagesFiles['LogTests'] = __DIR__ . '/LogTests.i18n.php'; |
| 54 |
} |
| 55 |
|
| 56 |
public static function tearDownAfterClass(): void { |
| 57 |
global $wgExtensionMessagesFiles; |
| 58 |
$wgExtensionMessagesFiles = self::$oldExtMsgFiles; |
| 59 |
|
| 60 |
parent::tearDownAfterClass(); |
| 61 |
} |
| 62 |
|
| 63 |
protected function setUp(): void { |
| 64 |
parent::setUp(); |
| 65 |
|
| 66 |
$this->overrideConfigValues( [ |
| 67 |
MainConfigNames::LogTypes => [ 'phpunit' ], |
| 68 |
MainConfigNames::LogActionsHandlers => [ 'phpunit/test' => LogFormatter::class, |
| 69 |
'phpunit/param' => LogFormatter::class ], |
| 70 |
] ); |
| 71 |
|
| 72 |
$this->user = User::newFromName( 'Testuser' ); |
| 73 |
$this->title = Title::makeTitle( NS_MAIN, 'SomeTitle' ); |
| 74 |
$this->target = Title::makeTitle( NS_MAIN, 'TestTarget' ); |
| 75 |
|
| 76 |
$this->context = new RequestContext(); |
| 77 |
$this->context->setUser( $this->user ); |
| 78 |
$this->context->setTitle( $this->title ); |
| 79 |
$this->context->setLanguage( RequestContext::getMain()->getLanguage() ); |
| 80 |
|
| 81 |
$this->user_comment = '<User comment about action>'; |
| 82 |
} |
| 83 |
|
| 84 |
public function newLogEntry( $action, $params ) { |
| 85 |
$logEntry = new ManualLogEntry( 'phpunit', $action ); |
| 86 |
$logEntry->setPerformer( $this->user ); |
| 87 |
$logEntry->setTarget( $this->title ); |
| 88 |
$logEntry->setComment( 'A very good reason' ); |
| 89 |
|
| 90 |
$logEntry->setParameters( $params ); |
| 91 |
|
| 92 |
return $logEntry; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public function testNormalLogParams() { |
| 99 |
$entry = $this->newLogEntry( 'test', [] ); |
| 100 |
$formatter = $this->getServiceContainer()->getLogFormatterFactory()->newFromEntry( $entry ); |
| 101 |
$formatter->setContext( $this->context ); |
| 102 |
|
| 103 |
$formatter->setShowUserToolLinks( false ); |
| 104 |
$paramsWithoutTools = $formatter->getMessageParametersForTesting(); |
| 105 |
|
| 106 |
$formatter2 = $this->getServiceContainer()->getLogFormatterFactory()->newFromEntry( $entry ); |
| 107 |
$formatter2->setContext( $this->context ); |
| 108 |
$formatter2->setShowUserToolLinks( true ); |
| 109 |
$paramsWithTools = $formatter2->getMessageParametersForTesting(); |
| 110 |
|
| 111 |
$userLink = Linker::userLink( |
| 112 |
$this->user->getId(), |
| 113 |
$this->user->getName() |
| 114 |
); |
| 115 |
|
| 116 |
$userTools = Linker::userToolLinksRedContribs( |
| 117 |
$this->user->getId(), |
| 118 |
$this->user->getName(), |
| 119 |
$this->user->getEditCount(), |
| 120 |
false |
| 121 |
); |
| 122 |
|
| 123 |
$titleLink = Linker::link( $this->title, null, [], [] ); |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
$this->assertEquals( $paramsWithoutTools[1], $paramsWithTools[1] ); |
| 128 |
$this->assertEquals( $paramsWithoutTools[2], $paramsWithTools[2] ); |
| 129 |
|
| 130 |
$this->assertEquals( Message::rawParam( $userLink ), $paramsWithoutTools[0] ); |
| 131 |
$this->assertEquals( Message::rawParam( $userLink . $userTools ), $paramsWithTools[0] ); |
| 132 |
|
| 133 |
$this->assertEquals( $this->user->getName(), $paramsWithoutTools[1] ); |
| 134 |
|
| 135 |
$this->assertEquals( Message::rawParam( $titleLink ), $paramsWithoutTools[2] ); |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
public function testLogParamsTypeRaw() { |
| 142 |
$params = [ '4:raw:raw' => '<a href="">hello</a>' ]; |
| 143 |
$expected = htmlspecialchars( '<a href="">hello</a>' ); |
| 144 |
|
| 145 |
$entry = $this->newLogEntry( 'param', $params ); |
| 146 |
$formatter = $this->getServiceContainer()->getLogFormatterFactory()->newFromEntry( $entry ); |
| 147 |
$formatter->setContext( $this->context ); |
| 148 |
|
| 149 |
$logParam = $formatter->getActionText(); |
| 150 |
|
| 151 |
$this->assertEquals( $expected, $logParam, "Raw HTML log parameters are no longer allowed" ); |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
public function testLogParamsTypeMsg() { |
| 158 |
$params = [ '4:msg:msg' => 'log-description-phpunit' ]; |
| 159 |
$expected = wfMessage( 'log-description-phpunit' )->text(); |
| 160 |
|
| 161 |
$entry = $this->newLogEntry( 'param', $params ); |
| 162 |
$formatter = $this->getServiceContainer()->getLogFormatterFactory()->newFromEntry( $entry ); |
| 163 |
$formatter->setContext( $this->context ); |
| 164 |
|
| 165 |
$logParam = $formatter->getActionText(); |
| 166 |
|
| 167 |
$this->assertEquals( $expected, $logParam ); |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
public function testLogParamsTypeMsgContent() { |
| 174 |
$params = [ '4:msg-content:msgContent' => 'log-description-phpunit' ]; |
| 175 |
$expected = wfMessage( 'log-description-phpunit' )->inContentLanguage()->text(); |
| 176 |
|
| 177 |
$entry = $this->newLogEntry( 'param', $params ); |
| 178 |
$formatter = $this->getServiceContainer()->getLogFormatterFactory()->newFromEntry( $entry ); |
| 179 |
$formatter->setContext( $this->context ); |
| 180 |
|
| 181 |
$logParam = $formatter->getActionText(); |
| 182 |
|
| 183 |
$this->assertEquals( $expected, $logParam ); |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
public function testLogParamsTypeNumber() { |
| 190 |
global $wgLang; |
| 191 |
|
| 192 |
$params = [ '4:number:number' => 123456789 ]; |
| 193 |
$expected = $wgLang->formatNum( 123456789 ); |
| 194 |
|
| 195 |
$entry = $this->newLogEntry( 'param', $params ); |
| 196 |
$formatter = $this->getServiceContainer()->getLogFormatterFactory()->newFromEntry( $entry ); |
| 197 |
$formatter->setContext( $this->context ); |
| 198 |
|
| 199 |
$logParam = $formatter->getActionText(); |
| 200 |
|
| 201 |
$this->assertEquals( $expected, $logParam ); |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
public function testLogParamsTypeUserLink() { |
| 208 |
$params = [ '4:user-link:userLink' => $this->user->getName() ]; |
| 209 |
$expected = Linker::userLink( |
| 210 |
$this->user->getId(), |
| 211 |
$this->user->getName() |
| 212 |
); |
| 213 |
|
| 214 |
$entry = $this->newLogEntry( 'param', $params ); |
| 215 |
$formatter = $this->getServiceContainer()->getLogFormatterFactory()->newFromEntry( $entry ); |
| 216 |
$formatter->setContext( $this->context ); |
| 217 |
|
| 218 |
$logParam = $formatter->getActionText(); |
| 219 |
|
| 220 |
$this->assertEquals( $expected, $logParam ); |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
public function testLogParamsTypeUserLink_empty() { |
| 227 |
$params = [ '4:user-link:userLink' => ':' ]; |
| 228 |
|
| 229 |
$entry = $this->newLogEntry( 'param', $params ); |
| 230 |
$formatter = $this->getServiceContainer()->getLogFormatterFactory()->newFromEntry( $entry ); |
| 231 |
|
| 232 |
$this->context->setLanguage( 'qqx' ); |
| 233 |
$formatter->setContext( $this->context ); |
| 234 |
|
| 235 |
$logParam = $formatter->getActionText(); |
| 236 |
$this->assertStringContainsString( '(empty-username)', $logParam ); |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
public function testLogParamsTypeTitleLink() { |
| 243 |
$params = [ '4:title-link:titleLink' => $this->title->getText() ]; |
| 244 |
$expected = Linker::link( $this->title, null, [], [] ); |
| 245 |
|
| 246 |
$entry = $this->newLogEntry( 'param', $params ); |
| 247 |
$formatter = $this->getServiceContainer()->getLogFormatterFactory()->newFromEntry( $entry ); |
| 248 |
$formatter->setContext( $this->context ); |
| 249 |
|
| 250 |
$logParam = $formatter->getActionText(); |
| 251 |
|
| 252 |
$this->assertEquals( $expected, $logParam ); |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
public function testLogParamsTypePlain() { |
| 259 |
$params = [ '4:plain:plain' => 'Some plain text' ]; |
| 260 |
$expected = 'Some plain text'; |
| 261 |
|
| 262 |
$entry = $this->newLogEntry( 'param', $params ); |
| 263 |
$formatter = $this->getServiceContainer()->getLogFormatterFactory()->newFromEntry( $entry ); |
| 264 |
$formatter->setContext( $this->context ); |
| 265 |
|
| 266 |
$logParam = $formatter->getActionText(); |
| 267 |
|
| 268 |
$this->assertEquals( $expected, $logParam ); |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
public function testGetPerformerElement( $deletedFlag, $allowedAction ) { |
| 276 |
$entry = $this->newLogEntry( 'param', [] ); |
| 277 |
$entry->setPerformer( new UserIdentityValue( 1328435, 'Test' ) ); |
| 278 |
if ( $deletedFlag !== 'none' ) { |
| 279 |
$entry->setDeleted( |
| 280 |
LogPage::DELETED_USER | |
| 281 |
( $deletedFlag === 'suppressed' ? LogPage::DELETED_RESTRICTED : 0 ) |
| 282 |
); |
| 283 |
} |
| 284 |
|
| 285 |
$context = new DerivativeContext( $this->context ); |
| 286 |
if ( $allowedAction !== 'none' ) { |
| 287 |
$context->setAuthority( new SimpleAuthority( |
| 288 |
$this->context->getUser(), |
| 289 |
[ $deletedFlag === 'suppressed' ? 'suppressrevision' : 'deletedhistory' ] |
| 290 |
) ); |
| 291 |
} |
| 292 |
|
| 293 |
$formatter = $this->getServiceContainer()->getLogFormatterFactory()->newFromEntry( $entry ); |
| 294 |
$formatter->setContext( $context ); |
| 295 |
if ( $allowedAction === 'view-for-user' ) { |
| 296 |
$formatter->setAudience( LogFormatter::FOR_THIS_USER ); |
| 297 |
} |
| 298 |
|
| 299 |
$element = $formatter->getPerformerElement(); |
| 300 |
if ( $allowedAction === 'none' || |
| 301 |
( $deletedFlag !== 'none' && $allowedAction === 'view-public' ) |
| 302 |
) { |
| 303 |
$this->assertStringNotContainsString( 'User:Test', $element ); |
| 304 |
} else { |
| 305 |
$this->assertStringContainsString( 'User:Test', $element ); |
| 306 |
} |
| 307 |
|
| 308 |
if ( $deletedFlag === 'none' ) { |
| 309 |
$this->assertStringNotContainsString( 'history-deleted', $element ); |
| 310 |
} else { |
| 311 |
$this->assertStringContainsString( 'history-deleted', $element ); |
| 312 |
} |
| 313 |
if ( $deletedFlag === 'suppressed' ) { |
| 314 |
$this->assertStringContainsString( 'mw-history-suppressed', $element ); |
| 315 |
} else { |
| 316 |
$this->assertStringNotContainsString( 'mw-history-suppressed', $element ); |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
public function testLogComment( $deletedFlag, $allowedAction ) { |
| 325 |
$entry = $this->newLogEntry( 'test', [] ); |
| 326 |
if ( $deletedFlag !== 'none' ) { |
| 327 |
$entry->setDeleted( |
| 328 |
LogPage::DELETED_COMMENT | |
| 329 |
( $deletedFlag === 'suppressed' ? LogPage::DELETED_RESTRICTED : 0 ) |
| 330 |
); |
| 331 |
} |
| 332 |
|
| 333 |
$context = new DerivativeContext( $this->context ); |
| 334 |
if ( $allowedAction !== 'none' ) { |
| 335 |
$context->setAuthority( new SimpleAuthority( |
| 336 |
$this->context->getUser(), |
| 337 |
[ $deletedFlag === 'suppressed' ? 'suppressrevision' : 'deletedhistory' ] |
| 338 |
) ); |
| 339 |
} |
| 340 |
|
| 341 |
$formatter = $this->getServiceContainer()->getLogFormatterFactory()->newFromEntry( $entry ); |
| 342 |
$formatter->setContext( $context ); |
| 343 |
if ( $allowedAction === 'view-for-user' ) { |
| 344 |
$formatter->setAudience( LogFormatter::FOR_THIS_USER ); |
| 345 |
} |
| 346 |
|
| 347 |
$expectedComment = ltrim( $this->getServiceContainer()->getCommentFormatter()->formatBlock( $entry->getComment() ) ); |
| 348 |
$comment = $formatter->getComment(); |
| 349 |
|
| 350 |
if ( $allowedAction === 'none' || |
| 351 |
( $deletedFlag !== 'none' && $allowedAction === 'view-public' ) |
| 352 |
) { |
| 353 |
$this->assertStringNotContainsString( $expectedComment, $comment ); |
| 354 |
} else { |
| 355 |
$this->assertStringContainsString( $expectedComment, $comment ); |
| 356 |
} |
| 357 |
if ( $deletedFlag === 'none' ) { |
| 358 |
$this->assertStringNotContainsString( 'history-deleted', $comment ); |
| 359 |
} else { |
| 360 |
$this->assertStringContainsString( 'history-deleted', $comment ); |
| 361 |
} |
| 362 |
if ( $deletedFlag === 'suppressed' ) { |
| 363 |
$this->assertStringContainsString( 'mw-history-suppressed', $comment ); |
| 364 |
} else { |
| 365 |
$this->assertStringNotContainsString( 'mw-history-suppressed', $comment ); |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
public static function provideLogElement() { |
| 370 |
return [ |
| 371 |
[ 'none', 'view' ], |
| 372 |
[ 'deleted', 'none' ], |
| 373 |
[ 'deleted', 'view-for-user' ], |
| 374 |
[ 'deleted', 'view-public' ], |
| 375 |
[ 'suppressed', 'none' ], |
| 376 |
[ 'suppressed', 'view-for-user' ], |
| 377 |
[ 'suppressed', 'view-public' ], |
| 378 |
]; |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
public function testApiParamFormatting( $key, $value, $expected ) { |
| 387 |
$entry = $this->newLogEntry( 'param', [ $key => $value ] ); |
| 388 |
$formatter = $this->getServiceContainer()->getLogFormatterFactory()->newFromEntry( $entry ); |
| 389 |
$formatter->setContext( $this->context ); |
| 390 |
|
| 391 |
ApiResult::setIndexedTagName( $expected, 'param' ); |
| 392 |
ApiResult::setArrayType( $expected, 'assoc' ); |
| 393 |
|
| 394 |
$this->assertEquals( $expected, $formatter->formatParametersForApi() ); |
| 395 |
} |
| 396 |
|
| 397 |
public static function provideApiParamFormatting() { |
| 398 |
return [ |
| 399 |
[ 0, 'value', [ 'value' ] ], |
| 400 |
[ 'named', 'value', [ 'named' => 'value' ] ], |
| 401 |
[ '::key', 'value', [ 'key' => 'value' ] ], |
| 402 |
[ '4::key', 'value', [ 'key' => 'value' ] ], |
| 403 |
[ '4:raw:key', 'value', [ 'key' => 'value' ] ], |
| 404 |
[ '4:plain:key', 'value', [ 'key' => 'value' ] ], |
| 405 |
[ '4:bool:key', '1', [ 'key' => true ] ], |
| 406 |
[ '4:bool:key', '0', [ 'key' => false ] ], |
| 407 |
[ '4:number:key', '123', [ 'key' => 123 ] ], |
| 408 |
[ '4:number:key', '123.5', [ 'key' => 123.5 ] ], |
| 409 |
[ '4:array:key', [], [ 'key' => [ ApiResult::META_TYPE => 'array' ] ] ], |
| 410 |
[ '4:assoc:key', [], [ 'key' => [ ApiResult::META_TYPE => 'assoc' ] ] ], |
| 411 |
[ '4:kvp:key', [], [ 'key' => [ ApiResult::META_TYPE => 'kvp' ] ] ], |
| 412 |
[ '4:timestamp:key', '20150102030405', [ 'key' => '2015-01-02T03:04:05Z' ] ], |
| 413 |
[ '4:msg:key', 'parentheses', [ |
| 414 |
'key_key' => 'parentheses', |
| 415 |
'key_text' => wfMessage( 'parentheses' )->text(), |
| 416 |
] ], |
| 417 |
[ '4:msg-content:key', 'parentheses', [ |
| 418 |
'key_key' => 'parentheses', |
| 419 |
'key_text' => wfMessage( 'parentheses' )->inContentLanguage()->text(), |
| 420 |
] ], |
| 421 |
[ '4:title:key', 'project:foo', [ |
| 422 |
'key_ns' => NS_PROJECT, |
| 423 |
'key_title' => Title::makeTitle( NS_PROJECT, 'Foo' )->getFullText(), |
| 424 |
] ], |
| 425 |
[ '4:title-link:key', 'project:foo', [ |
| 426 |
'key_ns' => NS_PROJECT, |
| 427 |
'key_title' => Title::makeTitle( NS_PROJECT, 'Foo' )->getFullText(), |
| 428 |
] ], |
| 429 |
[ '4:title-link:key', '<invalid>', [ |
| 430 |
'key_ns' => NS_SPECIAL, |
| 431 |
'key_title' => SpecialPage::getTitleFor( 'Badtitle', '<invalid>' )->getFullText(), |
| 432 |
] ], |
| 433 |
[ '4:user:key', 'foo', [ 'key' => 'Foo' ] ], |
| 434 |
[ '4:user-link:key', 'foo', [ 'key' => 'Foo' ] ], |
| 435 |
]; |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
public function testIrcMsgForLogTypeBlock() { |
| 481 |
$sep = $this->context->msg( 'colon-separator' )->text(); |
| 482 |
|
| 483 |
|
| 484 |
$this->assertIRCComment( |
| 485 |
$this->context->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain() |
| 486 |
. $sep . $this->user_comment, |
| 487 |
'block', 'block', |
| 488 |
[ |
| 489 |
'5::duration' => 'duration', |
| 490 |
'6::flags' => 'flags', |
| 491 |
], |
| 492 |
$this->user_comment |
| 493 |
); |
| 494 |
|
| 495 |
$this->assertIRCComment( |
| 496 |
$this->context->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain() |
| 497 |
. $sep . $this->user_comment, |
| 498 |
'block', 'block', |
| 499 |
[ |
| 500 |
'duration', |
| 501 |
'flags', |
| 502 |
], |
| 503 |
$this->user_comment, |
| 504 |
'', |
| 505 |
true |
| 506 |
); |
| 507 |
|
| 508 |
$this->assertIRCComment( |
| 509 |
$this->context->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment, |
| 510 |
'block', 'unblock', |
| 511 |
[], |
| 512 |
$this->user_comment |
| 513 |
); |
| 514 |
|
| 515 |
$this->assertIRCComment( |
| 516 |
$this->context->msg( 'reblock-logentry', 'SomeTitle', 'duration', '(flags)' )->plain() |
| 517 |
. $sep . $this->user_comment, |
| 518 |
'block', 'reblock', |
| 519 |
[ |
| 520 |
'5::duration' => 'duration', |
| 521 |
'6::flags' => 'flags', |
| 522 |
], |
| 523 |
$this->user_comment |
| 524 |
); |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
public function testIrcMsgForLogTypeDelete() { |
| 532 |
$sep = $this->context->msg( 'colon-separator' )->text(); |
| 533 |
|
| 534 |
|
| 535 |
$this->assertIRCComment( |
| 536 |
$this->context->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment, |
| 537 |
'delete', 'delete', |
| 538 |
[], |
| 539 |
$this->user_comment |
| 540 |
); |
| 541 |
|
| 542 |
|
| 543 |
$this->assertIRCComment( |
| 544 |
$this->context->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment, |
| 545 |
'delete', 'restore', |
| 546 |
[], |
| 547 |
$this->user_comment |
| 548 |
); |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
public function testIrcMsgForLogTypeNewusers() { |
| 556 |
$this->assertIRCComment( |
| 557 |
'New user account', |
| 558 |
'newusers', 'newusers', |
| 559 |
[] |
| 560 |
); |
| 561 |
$this->assertIRCComment( |
| 562 |
'New user account', |
| 563 |
'newusers', 'create', |
| 564 |
[] |
| 565 |
); |
| 566 |
$this->assertIRCComment( |
| 567 |
'created new account SomeTitle', |
| 568 |
'newusers', 'create2', |
| 569 |
[] |
| 570 |
); |
| 571 |
$this->assertIRCComment( |
| 572 |
'Account created automatically', |
| 573 |
'newusers', 'autocreate', |
| 574 |
[] |
| 575 |
); |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
public function testIrcMsgForLogTypeMove() { |
| 583 |
$move_params = [ |
| 584 |
'4::target' => $this->target->getPrefixedText(), |
| 585 |
'5::noredir' => 0, |
| 586 |
]; |
| 587 |
$sep = $this->context->msg( 'colon-separator' )->text(); |
| 588 |
|
| 589 |
|
| 590 |
$this->assertIRCComment( |
| 591 |
$this->context->msg( '1movedto2', 'SomeTitle', 'TestTarget' ) |
| 592 |
->plain() . $sep . $this->user_comment, |
| 593 |
'move', 'move', |
| 594 |
$move_params, |
| 595 |
$this->user_comment |
| 596 |
); |
| 597 |
|
| 598 |
|
| 599 |
$this->assertIRCComment( |
| 600 |
$this->context->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' ) |
| 601 |
->plain() . $sep . $this->user_comment, |
| 602 |
'move', 'move_redir', |
| 603 |
$move_params, |
| 604 |
$this->user_comment |
| 605 |
); |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
public function testIrcMsgForLogTypePatrol() { |
| 613 |
|
| 614 |
$this->assertIRCComment( |
| 615 |
$this->context->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(), |
| 616 |
'patrol', 'patrol', |
| 617 |
[ |
| 618 |
'4::curid' => '777', |
| 619 |
'5::previd' => '666', |
| 620 |
'6::auto' => 0, |
| 621 |
] |
| 622 |
); |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
public function testIrcMsgForLogTypeProtect() { |
| 630 |
$protectParams = [ |
| 631 |
'4::description' => '[edit=sysop] (indefinite) [move=sysop] (indefinite)' |
| 632 |
]; |
| 633 |
$sep = $this->context->msg( 'colon-separator' )->text(); |
| 634 |
|
| 635 |
|
| 636 |
$this->assertIRCComment( |
| 637 |
$this->context->msg( 'protectedarticle', 'SomeTitle ' . $protectParams['4::description'] ) |
| 638 |
->plain() . $sep . $this->user_comment, |
| 639 |
'protect', 'protect', |
| 640 |
$protectParams, |
| 641 |
$this->user_comment |
| 642 |
); |
| 643 |
|
| 644 |
|
| 645 |
$this->assertIRCComment( |
| 646 |
$this->context->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment, |
| 647 |
'protect', 'unprotect', |
| 648 |
[], |
| 649 |
$this->user_comment |
| 650 |
); |
| 651 |
|
| 652 |
|
| 653 |
$this->assertIRCComment( |
| 654 |
$this->context->msg( |
| 655 |
'modifiedarticleprotection', |
| 656 |
'SomeTitle ' . $protectParams['4::description'] |
| 657 |
)->plain() . $sep . $this->user_comment, |
| 658 |
'protect', 'modify', |
| 659 |
$protectParams, |
| 660 |
$this->user_comment |
| 661 |
); |
| 662 |
|
| 663 |
|
| 664 |
$this->assertIRCComment( |
| 665 |
$this->context->msg( 'movedarticleprotection', 'SomeTitle', 'OldTitle' ) |
| 666 |
->plain() . $sep . $this->user_comment, |
| 667 |
'protect', 'move_prot', |
| 668 |
[ |
| 669 |
'4::oldtitle' => 'OldTitle' |
| 670 |
], |
| 671 |
$this->user_comment |
| 672 |
); |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
public function testIrcMsgForLogTypeUpload() { |
| 680 |
$sep = $this->context->msg( 'colon-separator' )->text(); |
| 681 |
|
| 682 |
|
| 683 |
$this->assertIRCComment( |
| 684 |
$this->context->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment, |
| 685 |
'upload', 'upload', |
| 686 |
[], |
| 687 |
$this->user_comment |
| 688 |
); |
| 689 |
|
| 690 |
|
| 691 |
$this->assertIRCComment( |
| 692 |
$this->context->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment, |
| 693 |
'upload', 'overwrite', |
| 694 |
[], |
| 695 |
$this->user_comment |
| 696 |
); |
| 697 |
} |
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
public function testIrcMsgForLogTypeMerge() { |
| 704 |
$sep = $this->context->msg( 'colon-separator' )->text(); |
| 705 |
|
| 706 |
|
| 707 |
$this->assertIRCComment( |
| 708 |
$this->context->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain() |
| 709 |
. $sep . $this->user_comment, |
| 710 |
'merge', 'merge', |
| 711 |
[ |
| 712 |
'4::dest' => 'Dest', |
| 713 |
'5::mergepoint' => 'timestamp', |
| 714 |
], |
| 715 |
$this->user_comment |
| 716 |
); |
| 717 |
} |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
public function testIrcMsgForLogTypeImport() { |
| 724 |
$sep = $this->context->msg( 'colon-separator' )->text(); |
| 725 |
|
| 726 |
|
| 727 |
$msg = $this->context->msg( 'import-logentry-upload', 'SomeTitle' )->plain() . |
| 728 |
$sep . |
| 729 |
$this->user_comment; |
| 730 |
$this->assertIRCComment( |
| 731 |
$msg, |
| 732 |
'import', 'upload', |
| 733 |
[], |
| 734 |
$this->user_comment |
| 735 |
); |
| 736 |
|
| 737 |
|
| 738 |
$msg = $this->context->msg( 'import-logentry-interwiki', 'SomeTitle' )->plain() . |
| 739 |
$sep . |
| 740 |
$this->user_comment; |
| 741 |
$this->assertIRCComment( |
| 742 |
$msg, |
| 743 |
'import', 'interwiki', |
| 744 |
[], |
| 745 |
$this->user_comment |
| 746 |
); |
| 747 |
} |
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
protected function assertIRCComment( $expected, $type, $action, $params, |
| 759 |
$comment = null, $msg = '', $legacy = false |
| 760 |
) { |
| 761 |
$logEntry = new ManualLogEntry( $type, $action ); |
| 762 |
$logEntry->setPerformer( $this->user ); |
| 763 |
$logEntry->setTarget( $this->title ); |
| 764 |
if ( $comment !== null ) { |
| 765 |
$logEntry->setComment( $comment ); |
| 766 |
} |
| 767 |
$logEntry->setParameters( $params ); |
| 768 |
$logEntry->setLegacy( $legacy ); |
| 769 |
|
| 770 |
$formatter = $this->getServiceContainer()->getLogFormatterFactory()->newFromEntry( $logEntry ); |
| 771 |
$formatter->setContext( $this->context ); |
| 772 |
|
| 773 |
|
| 774 |
$ircRcComment = IRCColourfulRCFeedFormatter::cleanupForIRC( $formatter->getIRCActionComment() ); |
| 775 |
|
| 776 |
$this->assertEquals( |
| 777 |
$expected, |
| 778 |
$ircRcComment, |
| 779 |
$msg |
| 780 |
); |
| 781 |
} |
| 782 |
|
| 783 |
} |