2020-12-09 15:51:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use MediaWiki\Extension\AbuseFilter\BlockAutopromoteStore;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Consequences\Consequence\BlockAutopromote;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Consequences\Parameters;
|
|
|
|
use MediaWiki\User\UserIdentityValue;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @coversDefaultClass \MediaWiki\Extension\AbuseFilter\Consequences\Consequence\BlockAutopromote
|
|
|
|
* @covers ::__construct
|
|
|
|
* @todo with MessageLocalizer injected, this can be a unit test
|
|
|
|
*/
|
|
|
|
class BlockAutopromoteTest extends MediaWikiIntegrationTestCase {
|
2021-01-06 13:07:02 +00:00
|
|
|
use ConsequenceGetMessageTestTrait;
|
2020-12-09 15:51:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::execute
|
|
|
|
*/
|
|
|
|
public function testExecute_anonymous() {
|
2021-01-06 13:07:02 +00:00
|
|
|
$user = new UserIdentityValue( 0, 'Anonymous user', 1 );
|
|
|
|
$params = $this->provideGetMessageParameters( $user )->current()[0];
|
2020-12-09 15:51:59 +00:00
|
|
|
$blockAutopromoteStore = $this->createMock( BlockAutopromoteStore::class );
|
|
|
|
$blockAutopromoteStore->expects( $this->never() )
|
|
|
|
->method( 'blockAutoPromote' );
|
|
|
|
$blockAutopromote = new BlockAutopromote(
|
|
|
|
$params,
|
|
|
|
5 * 86400,
|
|
|
|
$blockAutopromoteStore
|
|
|
|
);
|
|
|
|
$this->assertFalse( $blockAutopromote->execute() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::execute
|
|
|
|
* @dataProvider provideExecute
|
|
|
|
*/
|
|
|
|
public function testExecute( bool $success ) {
|
2020-11-29 15:18:32 +00:00
|
|
|
$target = new UserIdentityValue( 1, 'A new user', 2 );
|
2021-01-06 13:07:02 +00:00
|
|
|
$params = $this->provideGetMessageParameters( $target )->current()[0];
|
2020-11-29 15:18:32 +00:00
|
|
|
$duration = 5 * 86400;
|
2020-12-09 15:51:59 +00:00
|
|
|
$blockAutopromoteStore = $this->createMock( BlockAutopromoteStore::class );
|
|
|
|
$blockAutopromoteStore->expects( $this->once() )
|
|
|
|
->method( 'blockAutoPromote' )
|
2020-11-29 15:18:32 +00:00
|
|
|
->with( $target, $this->anything(), $duration )
|
2020-12-09 15:51:59 +00:00
|
|
|
->willReturn( $success );
|
2020-11-29 15:18:32 +00:00
|
|
|
$blockAutopromote = new BlockAutopromote( $params, $duration, $blockAutopromoteStore );
|
2020-12-09 15:51:59 +00:00
|
|
|
$this->assertSame( $success, $blockAutopromote->execute() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideExecute() : array {
|
|
|
|
return [
|
|
|
|
[ true ],
|
|
|
|
[ false ]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-11-29 15:18:32 +00:00
|
|
|
/**
|
|
|
|
* @covers ::revert
|
|
|
|
* @dataProvider provideExecute
|
|
|
|
*/
|
|
|
|
public function testRevert( bool $success ) {
|
|
|
|
$target = new UserIdentityValue( 1, 'A new user', 2 );
|
|
|
|
$performer = new UserIdentityValue( 2, 'Reverting user', 3 );
|
2021-01-06 13:07:02 +00:00
|
|
|
$params = $this->provideGetMessageParameters( $target )->current()[0];
|
2020-11-29 15:18:32 +00:00
|
|
|
$blockAutopromoteStore = $this->createMock( BlockAutopromoteStore::class );
|
|
|
|
$blockAutopromoteStore->expects( $this->once() )
|
|
|
|
->method( 'unblockAutoPromote' )
|
|
|
|
->with( $target, $performer, $this->anything() )
|
|
|
|
->willReturn( $success );
|
|
|
|
$blockAutopromote = new BlockAutopromote( $params, 0, $blockAutopromoteStore );
|
|
|
|
$this->assertSame( $success, $blockAutopromote->revert( [], $performer, 'reason' ) );
|
|
|
|
}
|
|
|
|
|
2021-01-06 13:07:02 +00:00
|
|
|
/**
|
|
|
|
* @covers ::getMessage
|
|
|
|
* @dataProvider provideGetMessageParameters
|
|
|
|
*/
|
|
|
|
public function testGetMessage( Parameters $params ) {
|
|
|
|
$rangeBlock = new BlockAutopromote(
|
|
|
|
$params,
|
|
|
|
83,
|
|
|
|
$this->createMock( BlockAutopromoteStore::class )
|
|
|
|
);
|
|
|
|
$this->doTestGetMessage( $rangeBlock, $params, 'abusefilter-autopromote-blocked' );
|
|
|
|
}
|
2020-12-09 15:51:59 +00:00
|
|
|
}
|