Add tests for Special:Log/suppress, fix for PostgreSQL

Also handle unknown "offender" actors more nicely.

Change-Id: Iaf30aae9f14c5a8edc44b89ea67acd6a96909d66
This commit is contained in:
Marius Hoch 2023-06-14 11:26:04 +02:00
parent 1d47512ea1
commit 23ad1fd91b
2 changed files with 50 additions and 1 deletions

View file

@ -149,7 +149,10 @@ class SpecialLog extends SpecialPage {
$offenderName = $opts->getValue( 'offender' );
$offenderId = $this->actorNormalization->findActorIdByName( $offenderName, $dbr );
if ( $offenderId ) {
$qc = [ 'ls_field' => 'target_author_actor', 'ls_value' => $offenderId ];
$qc = [ 'ls_field' => 'target_author_actor', 'ls_value' => strval( $offenderId ) ];
} else {
// Unknown offender, thus results have to be empty
$qc = [ '1=0' ];
}
} else {
// Allow extensions to add relations to their search types

View file

@ -5,9 +5,11 @@
*/
use MediaWiki\Request\FauxRequest;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Specials\SpecialLog;
/**
* @group Database
* @covers \MediaWiki\Specials\SpecialLog
*/
class SpecialLogTest extends SpecialPageTestBase {
@ -41,4 +43,48 @@ class SpecialLogTest extends SpecialPageTestBase {
$this->assertStringContainsString( '(log-summary)', $html );
}
public function testSuppressionLog() {
// Have "BadGuy" create a revision
$user = ( new TestUser( 'BadGuy' ) )->getUser();
$title = $this->insertPage( 'Foo', 'Bar', null, $user )['title'];
$revId = $title->getLatestRevID();
// Hide our revision's comment
$list = RevisionDeleter::createList( 'revision', RequestContext::getMain(), $title, [ $revId ] );
$status = $list->setVisibility( [
'value' => [
RevisionRecord::DELETED_RESTRICTED => 1,
RevisionRecord::DELETED_COMMENT => 1
],
'comment' => 'SpecialLogTest'
] );
$this->assertTrue( $status->isGood() );
// Allow everyone to read the suppression log
$this->mergeMwGlobalArrayValue(
'wgGroupPermissions', [
'*' => [
'suppressionlog' => true
]
]
);
[ $html, ] = $this->executeSpecialPage(
'suppress',
new FauxRequest( [ 'offender' => 'BadGuy' ] ),
'qqx'
);
$this->assertStringNotContainsString( '(logempty)', $html );
$this->assertStringContainsString( '(logentry-suppress-revision', $html );
// Suppression log for unknown user should be empty
[ $html, ] = $this->executeSpecialPage(
'suppress',
new FauxRequest( [ 'offender' => 'GoodGuy' ] ),
'qqx'
);
$this->assertStringContainsString( '(logempty)', $html );
$this->assertStringNotContainsString( '(logentry-suppress-revision', $html );
}
}