Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / jobqueue / jobs / UserEditCountInitJobTest.php
blob13e93504764185a869fcefcc4b8957003da3f7ad
1 <?php
3 /**
4 * @group JobQueue
5 * @group Database
6 */
7 class UserEditCountInitJobTest extends MediaWikiIntegrationTestCase {
9 public static function provideTestCases() {
10 // $startingEditCount, $setCount, $finalCount
11 yield 'Initiate count if not yet set' => [ false, 2, 2 ];
12 yield 'Update count when increasing' => [ 2, 3, 3 ];
13 yield 'Never decrease count' => [ 10, 3, 10 ];
16 /**
17 * @covers \UserEditCountInitJob
18 * @dataProvider provideTestCases
20 public function testUserEditCountInitJob( $startingEditCount, $setCount, $finalCount ) {
21 $user = $this->getMutableTestUser()->getUser();
23 if ( $startingEditCount !== false ) {
24 $this->getServiceContainer()->getConnectionProvider()->getPrimaryDatabase()
25 ->newUpdateQueryBuilder()
26 ->update( 'user' )
27 ->set( [ 'user_editcount' => $startingEditCount ] )
28 ->where( [ 'user_id' => $user->getId() ] )
29 ->caller( __METHOD__ )
30 ->execute();
33 $job = new UserEditCountInitJob( [
34 'userId' => $user->getId(),
35 'editCount' => $setCount
36 ] );
38 $result = $job->run();
40 $this->assertTrue( $result );
41 $this->assertEquals( $finalCount, $user->getEditCount() );