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