mediawiki-extensions-AbuseF.../tests/phpunit/EchoNotifierTest.php
Matěj Suchánek dc7509811a Notify of a throttled filter
Use Echo for delivering the notification to the last
user who edited the filter.

Much boilerplate.

Change-Id: I7a46a03b4f15de20902ec70c62fb4fe750096842
Depends-On: If585b14a6dd6fb8c7d2c3bee1f20d9d08eaac706
2020-12-19 10:31:29 +01:00

59 lines
1.6 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 ::getDataForEvent
* @covers ::__construct
*/
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() );
[ $page, $subpage ] = explode( '/', $title->getText(), 2 );
$this->assertSame( (string)$filter, $subpage );
$this->assertSame( [ 'user' => $userID ], $extra );
}
}