mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-15 10:15:24 +00:00
cbea88f818
Unfortunately, this isn't using DI completely, because of the User::newSystemUser call. I'm not even sure if we really need to call it or we can just stick to new UserIdentityValue, but leaving like this for now. Also, the types were weakened to UserIdentity, so the transition is going to be easy anyway. Change-Id: I08f8fae0fcc622ff0ac3f86771476d06d1c18549
57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\AbuseFilter\FilterUser;
|
|
use MediaWiki\MediaWikiServices;
|
|
use Psr\Log\NullLogger;
|
|
|
|
/**
|
|
* @group Test
|
|
* @group AbuseFilter
|
|
* @coversDefaultClass \MediaWiki\Extension\AbuseFilter\FilterUser
|
|
* @covers ::__construct()
|
|
* @todo Make a unit test once DI is possible for User::newSystemUser
|
|
*/
|
|
class AbuseFilterFilterUserTest extends MediaWikiIntegrationTestCase {
|
|
/**
|
|
* @covers ::getUser
|
|
*/
|
|
public function testGetUser() {
|
|
$name = 'AbuseFilter blocker user';
|
|
$ml = $this->createMock( MessageLocalizer::class );
|
|
$ml->method( 'msg' )->willReturn( $this->getMockMessage( $name ) );
|
|
$ugm = MediaWikiServices::getInstance()->getUserGroupManager();
|
|
$filterUser = new FilterUser( $ml, $ugm, new NullLogger() );
|
|
|
|
$actual = $filterUser->getUser();
|
|
$this->assertSame( $name, $actual->getName(), 'name' );
|
|
$this->assertContains( 'sysop', $ugm->getUserGroups( $actual ), 'sysop' );
|
|
}
|
|
|
|
/**
|
|
* @covers ::getUser
|
|
*/
|
|
public function testGetUser_invalidName() {
|
|
$name = 'Foobar filter user';
|
|
$ml = $this->createMock( MessageLocalizer::class );
|
|
$msg = $this->createMock( Message::class );
|
|
$msg->method( 'inContentLanguage' )->willReturn( $this->getMockMessage( '' ) );
|
|
$msg->method( 'inLanguage' )->willReturn( $this->getMockMessage( $name ) );
|
|
$ml->method( 'msg' )->willReturn( $msg );
|
|
$ugm = MediaWikiServices::getInstance()->getUserGroupManager();
|
|
$logger = new TestLogger();
|
|
$logger->setCollect( true );
|
|
$filterUser = new FilterUser( $ml, $ugm, $logger );
|
|
|
|
$actual = $filterUser->getUser();
|
|
$this->assertSame( $name, $actual->getName(), 'name' );
|
|
$found = false;
|
|
foreach ( $logger->getBuffer() as $msg ) {
|
|
if ( strpos( $msg[1], 'MediaWiki:abusefilter-blocker' ) !== false ) {
|
|
$found = true;
|
|
break;
|
|
}
|
|
}
|
|
$this->assertTrue( $found, 'Invalid name not logged' );
|
|
}
|
|
}
|