| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
class UserEditCountInitJobTest extends MediaWikiIntegrationTestCase { |
| 8 |
|
| 9 |
public static function provideTestCases() { |
| 10 |
|
| 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 ]; |
| 14 |
} |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public function testUserEditCountInitJob( $startingEditCount, $setCount, $finalCount ) { |
| 21 |
$user = $this->getMutableTestUser()->getUser(); |
| 22 |
|
| 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(); |
| 31 |
} |
| 32 |
|
| 33 |
$job = new UserEditCountInitJob( [ |
| 34 |
'userId' => $user->getId(), |
| 35 |
'editCount' => $setCount |
| 36 |
] ); |
| 37 |
|
| 38 |
$result = $job->run(); |
| 39 |
|
| 40 |
$this->assertTrue( $result ); |
| 41 |
$this->assertEquals( $finalCount, $user->getEditCount() ); |
| 42 |
} |
| 43 |
} |