mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-11 16:28:21 +00:00
Convert AbuseFilterDBTest to pure unit tests
No integration needed, use a mock user. Change-Id: I206d019aec626e6e4c16de10ecf30a29d5ab12e5
This commit is contained in:
parent
85eab17de8
commit
5d8ac68310
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\AbuseFilter\AbuseFilter;
|
||||
use MediaWiki\Page\PageIdentityValue;
|
||||
use MediaWiki\Revision\MutableRevisionRecord;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
|
||||
|
@ -9,7 +10,7 @@ use MediaWiki\Revision\RevisionRecord;
|
|||
* @group AbuseFilter
|
||||
* @group AbuseFilterGeneric
|
||||
*/
|
||||
class AbuseFilterDBTest extends MediaWikiTestCase {
|
||||
class AbuseFilterTest extends MediaWikiUnitTestCase {
|
||||
/**
|
||||
* @param RevisionRecord $revRec
|
||||
* @param bool $privileged
|
||||
|
@ -18,9 +19,9 @@ class AbuseFilterDBTest extends MediaWikiTestCase {
|
|||
* @covers AbuseFilter::userCanViewRev
|
||||
*/
|
||||
public function testUserCanViewRev( RevisionRecord $revRec, bool $privileged, bool $expected ) {
|
||||
$user = $privileged
|
||||
? $this->getTestUser( 'suppress' )->getUser()
|
||||
: $this->getTestUser()->getUser();
|
||||
$user = $this->createMock( User::class );
|
||||
$user->method( 'isAllowedAny' )->willReturn( $privileged );
|
||||
$user->method( 'authorizeRead' )->willReturn( $privileged );
|
||||
$this->assertSame( $expected, AbuseFilter::userCanViewRev( $revRec, $user ) );
|
||||
}
|
||||
|
||||
|
@ -28,18 +29,18 @@ class AbuseFilterDBTest extends MediaWikiTestCase {
|
|||
* @return Generator|array
|
||||
*/
|
||||
public function provideUserCanViewRev() {
|
||||
$title = Title::newFromText( __METHOD__ );
|
||||
$page = new PageIdentityValue( 1, NS_MAIN, 'Foo', PageIdentityValue::LOCAL );
|
||||
|
||||
$visible = new MutableRevisionRecord( $title );
|
||||
$visible = new MutableRevisionRecord( $page );
|
||||
yield 'Visible, not privileged' => [ $visible, false, true ];
|
||||
yield 'Visible, privileged' => [ $visible, true, true ];
|
||||
|
||||
$userSup = new MutableRevisionRecord( $title );
|
||||
$userSup = new MutableRevisionRecord( $page );
|
||||
$userSup->setVisibility( RevisionRecord::SUPPRESSED_USER );
|
||||
yield 'User suppressed, not privileged' => [ $userSup, false, false ];
|
||||
yield 'User suppressed, privileged' => [ $userSup, true, true ];
|
||||
|
||||
$allSupp = new MutableRevisionRecord( $title );
|
||||
$allSupp = new MutableRevisionRecord( $page );
|
||||
$allSupp->setVisibility( RevisionRecord::SUPPRESSED_ALL );
|
||||
yield 'All suppressed, not privileged' => [ $allSupp, false, false ];
|
||||
yield 'All suppressed, privileged' => [ $allSupp, true, true ];
|
Loading…
Reference in a new issue