mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-12-20 09:30:51 +00:00
8639e0c368
In particular, this brings stronger typing for getID(), and we can get rid of many phan suppressions. Change-Id: Icbf3a6f7db8105082646ec227f62c09449fb165d
48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilter;
|
|
use MediaWiki\Revision\MutableRevisionRecord;
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
|
|
/**
|
|
* @group Test
|
|
* @group AbuseFilter
|
|
* @group AbuseFilterGeneric
|
|
*/
|
|
class AbuseFilterDBTest extends MediaWikiTestCase {
|
|
/**
|
|
* @param RevisionRecord $revRec
|
|
* @param bool $privileged
|
|
* @param bool $expected
|
|
* @dataProvider provideUserCanViewRev
|
|
* @covers AbuseFilter::userCanViewRev
|
|
*/
|
|
public function testUserCanViewRev( RevisionRecord $revRec, bool $privileged, bool $expected ) {
|
|
$user = $privileged
|
|
? $this->getTestUser( 'suppress' )->getUser()
|
|
: $this->getTestUser()->getUser();
|
|
$this->assertSame( $expected, AbuseFilter::userCanViewRev( $revRec, $user ) );
|
|
}
|
|
|
|
/**
|
|
* @return Generator|array
|
|
*/
|
|
public function provideUserCanViewRev() {
|
|
$title = Title::newFromText( __METHOD__ );
|
|
|
|
$visible = new MutableRevisionRecord( $title );
|
|
yield 'Visible, not privileged' => [ $visible, false, true ];
|
|
yield 'Visible, privileged' => [ $visible, true, true ];
|
|
|
|
$userSup = new MutableRevisionRecord( $title );
|
|
$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->setVisibility( RevisionRecord::SUPPRESSED_ALL );
|
|
yield 'All suppressed, not privileged' => [ $allSupp, false, false ];
|
|
yield 'All suppressed, privileged' => [ $allSupp, true, true ];
|
|
}
|
|
}
|