summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/AutopromoteTest.php
blob: 8c4a488ef5ec0e285e9bbef3e7c72483e9d9ff5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

/**
 * @covers Autopromote
 */
class AutopromoteTest extends MediaWikiTestCase {
	/**
	 * T157718: Verify Autopromote does not perform edit count lookup if requirement is 0 or invalid
	 *
	 * @see Autopromote::getAutopromoteGroups()
	 * @dataProvider provideEditCountsAndRequirements
	 * @param int $editCount edit count of user to be checked by Autopromote
	 * @param int $requirement edit count required to autopromote user
	 */
	public function testEditCountLookupIsSkippedIfRequirementIsZero( $editCount, $requirement ) {
		$this->setMwGlobals( [
			'wgAutopromote' => [
				'autoconfirmed' => [ APCOND_EDITCOUNT, $requirement ]
			]
		] );

		/** @var PHPUnit_Framework_MockObject_MockObject|User $userMock */
		$userMock = $this->getMock( User::class, [ 'getEditCount' ] );
		if ( $requirement > 0 ) {
			$userMock->expects( $this->once() )
				->method( 'getEditCount' )
				->willReturn( $editCount );
		} else {
			$userMock->expects( $this->never() )
				->method( 'getEditCount' );
		}

		$result = Autopromote::getAutopromoteGroups( $userMock );
		if ( $editCount >= $requirement ) {
			$this->assertContains(
				'autoconfirmed',
				$result,
				'User must be promoted if they meet edit count requirement'
			);
		} else {
			$this->assertNotContains(
				'autoconfirmed',
				$result,
				'User must not be promoted if they fail edit count requirement'
			);
		}
	}

	public static function provideEditCountsAndRequirements() {
		return [
			'user with sufficient editcount' => [ 100, 10 ],
			'user with insufficient editcount' => [ 4, 10 ],
			'edit count requirement set to 0' => [ 1, 0 ],
		];
	}
}