RevisionTest: Revision::constructFromRowArray is not a function
[lhc/web/wiklou.git] / tests / phpunit / includes / AutopromoteTest.php
1 <?php
2
3 class AutopromoteTest extends MediaWikiTestCase {
4 /**
5 * T157718: Verify Autopromote does not perform edit count lookup if requirement is 0 or invalid
6 *
7 * @see Autopromote::getAutopromoteGroups()
8 * @dataProvider provideEditCountsAndRequirements
9 * @param int $editCount edit count of user to be checked by Autopromote
10 * @param int $requirement edit count required to autopromote user
11 */
12 public function testEditCountLookupIsSkippedIfRequirementIsZero( $editCount, $requirement ) {
13 $this->setMwGlobals( [
14 'wgAutopromote' => [
15 'autoconfirmed' => [ APCOND_EDITCOUNT, $requirement ]
16 ]
17 ] );
18
19 /** @var PHPUnit_Framework_MockObject_MockObject|User $userMock */
20 $userMock = $this->getMock( 'User', [ 'getEditCount' ] );
21 if ( $requirement > 0 ) {
22 $userMock->expects( $this->once() )
23 ->method( 'getEditCount' )
24 ->willReturn( $editCount );
25 } else {
26 $userMock->expects( $this->never() )
27 ->method( 'getEditCount' );
28 }
29
30 $result = Autopromote::getAutopromoteGroups( $userMock );
31 if ( $editCount >= $requirement ) {
32 $this->assertContains(
33 'autoconfirmed',
34 $result,
35 'User must be promoted if they meet edit count requirement'
36 );
37 } else {
38 $this->assertNotContains(
39 'autoconfirmed',
40 $result,
41 'User must not be promoted if they fail edit count requirement'
42 );
43 }
44 }
45
46 public static function provideEditCountsAndRequirements() {
47 return [
48 'user with sufficient editcount' => [ 100, 10 ],
49 'user with insufficient editcount' => [ 4, 10 ],
50 'edit count requirement set to 0' => [ 1, 0 ],
51 ];
52 }
53 }