mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-12-18 08:30:52 +00:00
352a207c70
Bug: T201193 Change-Id: Ie086fd525bec19c63c13f8710a27897229cc33c8
82 lines
2.3 KiB
PHP
82 lines
2.3 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\AbuseFilter\EchoNotifier;
|
|
use MediaWiki\Extension\AbuseFilter\Filter\MutableFilter;
|
|
use MediaWiki\Extension\AbuseFilter\FilterLookup;
|
|
|
|
/**
|
|
* @coversDefaultClass \MediaWiki\Extension\AbuseFilter\EchoNotifier
|
|
*/
|
|
class EchoNotifierTest extends MediaWikiIntegrationTestCase {
|
|
|
|
private const USER_IDS = [
|
|
'1' => 1,
|
|
'2' => 42,
|
|
];
|
|
|
|
private function getFilterLookup() : FilterLookup {
|
|
$lookup = $this->createMock( FilterLookup::class );
|
|
$lookup->method( 'getFilter' )
|
|
->willReturnCallback( function ( $filter, $global ) {
|
|
$filterObj = MutableFilter::newDefault();
|
|
$filterObj->setUserID( self::USER_IDS[ $global ? "global-$filter" : $filter ] ?? 0 );
|
|
return $filterObj;
|
|
} );
|
|
return $lookup;
|
|
}
|
|
|
|
public function provideDataForEvent() : array {
|
|
return [
|
|
[ true, 1, 1 ],
|
|
[ true, 2, 42 ],
|
|
[ false, 1, 1 ],
|
|
[ false, 2, 42 ],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideDataForEvent
|
|
* @covers ::__construct
|
|
* @covers ::getDataForEvent
|
|
* @covers ::getLastUserIDForFilter
|
|
* @covers ::getTitleForFilter
|
|
*/
|
|
public function testGetDataForEvent( bool $loaded, int $filter, int $userID ) {
|
|
$notifier = new EchoNotifier( $this->getFilterLookup(), $loaded );
|
|
[
|
|
'type' => $type,
|
|
'title' => $title,
|
|
'extra' => $extra
|
|
] = $notifier->getDataForEvent( $filter );
|
|
|
|
$this->assertSame( EchoNotifier::EVENT_TYPE, $type );
|
|
$this->assertInstanceOf( Title::class, $title );
|
|
$this->assertSame( -1, $title->getNamespace() );
|
|
[ , $subpage ] = explode( '/', $title->getText(), 2 );
|
|
$this->assertSame( (string)$filter, $subpage );
|
|
$this->assertSame( [ 'user' => $userID ], $extra );
|
|
}
|
|
|
|
/**
|
|
* @covers ::notifyForFilter
|
|
*/
|
|
public function testNotifyForFilter() {
|
|
if ( !class_exists( EchoEvent::class ) ) {
|
|
$this->markTestSkipped( 'Echo not loaded' );
|
|
}
|
|
$notifier = new EchoNotifier( $this->getFilterLookup(), true );
|
|
$this->assertInstanceOf( EchoEvent::class, $notifier->notifyForFilter( 1 ) );
|
|
}
|
|
|
|
/**
|
|
* @covers ::notifyForFilter
|
|
*/
|
|
public function testNotifyForFilter_EchoNotLoaded() {
|
|
$lookup = $this->createMock( FilterLookup::class );
|
|
$lookup->expects( $this->never() )->method( $this->anything() );
|
|
$notifier = new EchoNotifier( $lookup, false );
|
|
$this->assertFalse( $notifier->notifyForFilter( 1 ) );
|
|
}
|
|
|
|
}
|