mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
c3af3157b4
Changes to the use statements done automatically via script Addition of missing use statement done manually Change-Id: I48fcc02c61d423c9c5111ae545634fdc5c5cc710
71 lines
2.9 KiB
PHP
71 lines
2.9 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Hooks\Handlers\SchemaChangesHandler;
|
|
use MediaWiki\Installer\DatabaseUpdater;
|
|
use MediaWiki\User\User;
|
|
use MediaWiki\User\UserFactory;
|
|
use MediaWiki\User\UserGroupManager;
|
|
|
|
/**
|
|
* @group Database
|
|
* @covers \MediaWiki\Extension\AbuseFilter\Hooks\Handlers\SchemaChangesHandler
|
|
* @todo Make this a unit test once User::newSystemUser is moved to a service
|
|
*/
|
|
class SchemaChangesHandlerTest extends MediaWikiIntegrationTestCase {
|
|
|
|
public function testConstruct() {
|
|
$this->assertInstanceOf(
|
|
SchemaChangesHandler::class,
|
|
new SchemaChangesHandler(
|
|
$this->createMock( MessageLocalizer::class ),
|
|
$this->createMock( UserGroupManager::class ),
|
|
$this->createMock( UserFactory::class )
|
|
)
|
|
);
|
|
}
|
|
|
|
public function testCreateAbuseFilterUser_invalidUserName() {
|
|
$noRowUpdater = $this->createMock( DatabaseUpdater::class );
|
|
$noRowUpdater->method( 'updateRowExists' )->willReturn( false );
|
|
$invalidML = $this->createMock( MessageLocalizer::class );
|
|
$invalidML->method( 'msg' )->with( 'abusefilter-blocker' )->willReturn( $this->getMockMessage( '' ) );
|
|
$userFactory = $this->createMock( UserFactory::class );
|
|
$userFactory->method( 'newFromName' )->willReturn( null );
|
|
$handler = new SchemaChangesHandler(
|
|
$invalidML,
|
|
$this->createNoOpMock( UserGroupManager::class ),
|
|
$userFactory
|
|
);
|
|
$this->assertFalse( $handler->createAbuseFilterUser( $noRowUpdater ) );
|
|
}
|
|
|
|
public function testCreateAbuseFilterUser_alreadyCreated() {
|
|
$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' ) );
|
|
$userFactory = $this->createMock( UserFactory::class );
|
|
$userFactory->method( 'newFromName' )->willReturn( $this->createMock( User::class ) );
|
|
$handler = new SchemaChangesHandler(
|
|
$validML,
|
|
$this->createNoOpMock( UserGroupManager::class ),
|
|
$userFactory
|
|
);
|
|
$this->assertFalse( $handler->createAbuseFilterUser( $rowExistsUpdater ) );
|
|
}
|
|
|
|
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' );
|
|
$userFactory = $this->createMock( UserFactory::class );
|
|
$userFactory->method( 'newFromName' )->willReturn( $this->createMock( User::class ) );
|
|
$okHandler = new SchemaChangesHandler( $validML, $ugm, $userFactory );
|
|
$this->assertTrue( $okHandler->createAbuseFilterUser( $noRowUpdater ) );
|
|
}
|
|
|
|
}
|