mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-12-19 00:51:02 +00:00
63b950e5b6
Sadly, these are not unit tests. Bug: T201193 Change-Id: I4c977ab14b273b02803a63f0a7b152a581a838b2
71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\AbuseFilter\BlockAutopromoteStore;
|
|
use MediaWiki\Extension\AbuseFilter\Consequences\Consequence\BlockAutopromote;
|
|
use MediaWiki\Extension\AbuseFilter\Consequences\Parameters;
|
|
use MediaWiki\Extension\AbuseFilter\Filter\Filter;
|
|
use MediaWiki\Linker\LinkTarget;
|
|
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 {
|
|
|
|
/**
|
|
* @covers ::execute
|
|
*/
|
|
public function testExecute_anonymous() {
|
|
$params = new Parameters(
|
|
$this->createMock( Filter::class ),
|
|
false,
|
|
new UserIdentityValue( 0, 'Anonymous user', 1 ),
|
|
$this->createMock( LinkTarget::class ),
|
|
'edit'
|
|
);
|
|
$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 ) {
|
|
$params = new Parameters(
|
|
$this->createMock( Filter::class ),
|
|
false,
|
|
new UserIdentityValue( 1, 'A new user', 2 ),
|
|
$this->createMock( LinkTarget::class ),
|
|
'edit'
|
|
);
|
|
$blockAutopromoteStore = $this->createMock( BlockAutopromoteStore::class );
|
|
$blockAutopromoteStore->expects( $this->once() )
|
|
->method( 'blockAutoPromote' )
|
|
->willReturn( $success );
|
|
$blockAutopromote = new BlockAutopromote(
|
|
$params,
|
|
5 * 86400,
|
|
$blockAutopromoteStore
|
|
);
|
|
$this->assertSame( $success, $blockAutopromote->execute() );
|
|
}
|
|
|
|
public function provideExecute() : array {
|
|
return [
|
|
[ true ],
|
|
[ false ]
|
|
];
|
|
}
|
|
|
|
}
|