2021-01-09 13:40:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Hooks\Handlers\SchemaChangesHandler;
|
|
|
|
use MediaWiki\User\UserGroupManager;
|
|
|
|
|
|
|
|
/**
|
2023-07-31 01:09:16 +00:00
|
|
|
* @group Database
|
2021-01-09 13:40:10 +00:00
|
|
|
* @coversDefaultClass \MediaWiki\Extension\AbuseFilter\Hooks\Handlers\SchemaChangesHandler
|
|
|
|
* @todo Make this a unit test once User::newSystemUser is moved to a service
|
|
|
|
*/
|
|
|
|
class SchemaChangesHandlerTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::__construct
|
|
|
|
*/
|
|
|
|
public function testConstruct() {
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
SchemaChangesHandler::class,
|
|
|
|
new SchemaChangesHandler(
|
|
|
|
$this->createMock( MessageLocalizer::class ),
|
|
|
|
$this->createMock( UserGroupManager::class )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-15 14:08:15 +00:00
|
|
|
/**
|
|
|
|
* @covers ::createAbuseFilterUser
|
|
|
|
*/
|
|
|
|
public function testCreateAbuseFilterUser_invalidUserName() {
|
2021-01-09 13:40:10 +00:00
|
|
|
$noRowUpdater = $this->createMock( DatabaseUpdater::class );
|
|
|
|
$noRowUpdater->method( 'updateRowExists' )->willReturn( false );
|
|
|
|
$invalidML = $this->createMock( MessageLocalizer::class );
|
|
|
|
$invalidML->method( 'msg' )->with( 'abusefilter-blocker' )->willReturn( $this->getMockMessage( '' ) );
|
2023-06-15 14:08:15 +00:00
|
|
|
$handler = new SchemaChangesHandler( $invalidML, $this->createNoOpMock( UserGroupManager::class ) );
|
|
|
|
$this->assertFalse( $handler->createAbuseFilterUser( $noRowUpdater ) );
|
|
|
|
}
|
2021-01-09 13:40:10 +00:00
|
|
|
|
2023-06-15 14:08:15 +00:00
|
|
|
/**
|
|
|
|
* @covers ::createAbuseFilterUser
|
|
|
|
*/
|
|
|
|
public function testCreateAbuseFilterUser_alreadyCreated() {
|
2021-01-09 13:40:10 +00:00
|
|
|
$rowExistsUpdater = $this->createMock( DatabaseUpdater::class );
|
|
|
|
$rowExistsUpdater->method( 'updateRowExists' )->willReturn( true );
|
|
|
|
$validML = $this->createMock( MessageLocalizer::class );
|
|
|
|
$validML->method( 'msg' )->with( 'abusefilter-blocker' )->willReturn( $this->getMockMessage( 'Foo' ) );
|
2023-06-15 14:08:15 +00:00
|
|
|
$handler = new SchemaChangesHandler( $validML, $this->createNoOpMock( UserGroupManager::class ) );
|
|
|
|
$this->assertFalse( $handler->createAbuseFilterUser( $rowExistsUpdater ) );
|
2021-01-09 13:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::createAbuseFilterUser
|
|
|
|
*/
|
2023-06-15 14:08:15 +00:00
|
|
|
public function testCreateAbuseFilterUser_success() {
|
|
|
|
$noRowUpdater = $this->createMock( DatabaseUpdater::class );
|
|
|
|
$noRowUpdater->method( 'updateRowExists' )->willReturn( false );
|
|
|
|
$validML = $this->createMock( MessageLocalizer::class );
|
|
|
|
$validML->method( 'msg' )->with( 'abusefilter-blocker' )->willReturn( $this->getMockMessage( 'Foo' ) );
|
|
|
|
$ugm = $this->createMock( UserGroupManager::class );
|
|
|
|
$ugm->expects( $this->once() )->method( 'addUserToGroup' );
|
|
|
|
$okHandler = new SchemaChangesHandler( $validML, $ugm );
|
|
|
|
$this->assertTrue( $okHandler->createAbuseFilterUser( $noRowUpdater ) );
|
2021-01-09 13:40:10 +00:00
|
|
|
}
|
2023-06-15 14:08:15 +00:00
|
|
|
|
2021-01-09 13:40:10 +00:00
|
|
|
}
|