2021-01-16 14:52:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Tests\Unit\Watcher;
|
|
|
|
|
|
|
|
use MediaWiki\Extension\AbuseFilter\CentralDBManager;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Watcher\UpdateHitCountWatcher;
|
2021-02-12 13:15:00 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
2021-08-31 17:50:52 +00:00
|
|
|
use Wikimedia\Rdbms\DBConnRef;
|
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
2023-02-26 12:51:08 +00:00
|
|
|
use Wikimedia\Rdbms\LBFactory;
|
2021-01-16 14:52:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @coversDefaultClass \MediaWiki\Extension\AbuseFilter\Watcher\UpdateHitCountWatcher
|
|
|
|
* @covers ::__construct
|
2021-02-12 13:15:00 +00:00
|
|
|
* @todo Make this a unit test once DeferredUpdates uses DI (T265749)
|
2021-01-16 14:52:09 +00:00
|
|
|
*/
|
2021-02-12 13:15:00 +00:00
|
|
|
class UpdateHitCountWatcherTest extends MediaWikiIntegrationTestCase {
|
2021-01-16 14:52:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::run
|
|
|
|
* @covers ::updateHitCounts
|
|
|
|
*/
|
|
|
|
public function testRun() {
|
|
|
|
$localFilters = [ 1, 2, 3 ];
|
|
|
|
$globalFilters = [ 4, 5, 6 ];
|
|
|
|
|
2021-08-31 17:50:52 +00:00
|
|
|
$localDB = $this->createMock( DBConnRef::class );
|
2021-01-16 14:52:09 +00:00
|
|
|
$localDB->expects( $this->once() )->method( 'update' )->with(
|
|
|
|
'abuse_filter',
|
|
|
|
[ 'af_hit_count=af_hit_count+1' ],
|
|
|
|
[ 'af_id' => $localFilters ]
|
|
|
|
);
|
2023-02-26 12:51:08 +00:00
|
|
|
$lb = $this->createMock( LBFactory::class );
|
|
|
|
$lb->method( 'getPrimaryDatabase' )->willReturn( $localDB );
|
2021-01-16 14:52:09 +00:00
|
|
|
|
|
|
|
$globalDB = $this->createMock( IDatabase::class );
|
|
|
|
$globalDB->expects( $this->once() )->method( 'update' )->with(
|
|
|
|
'abuse_filter',
|
|
|
|
[ 'af_hit_count=af_hit_count+1' ],
|
|
|
|
[ 'af_id' => $globalFilters ]
|
|
|
|
);
|
|
|
|
$centralDBManager = $this->createMock( CentralDBManager::class );
|
|
|
|
$centralDBManager->method( 'getConnection' )->willReturn( $globalDB );
|
|
|
|
|
|
|
|
$watcher = new UpdateHitCountWatcher( $lb, $centralDBManager );
|
|
|
|
$watcher->run( $localFilters, $globalFilters, 'default' );
|
|
|
|
// Two soft assertions done above
|
|
|
|
$this->addToAssertionCount( 2 );
|
|
|
|
}
|
|
|
|
}
|