Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / CheckSignaturesTest.php
blob205e35c243fa8499d80b8ae517b8f920fc4abc2c
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use CheckSignatures;
6 use MediaWiki\User\UserIdentity;
8 /**
9 * @covers \CheckSignatures
10 * @group Database
11 * @author Dreamy Jazz
13 class CheckSignaturesTest extends MaintenanceBaseTestCase {
15 protected function getMaintenanceClass() {
16 return CheckSignatures::class;
19 /**
20 * @param int $count
21 * @return UserIdentity[]
23 private function generateMutableTestUsers( int $count ): array {
24 $returnArray = [];
25 for ( $i = 0; $i < $count; $i++ ) {
26 $testUser = $this->getMutableTestUser()->getUserIdentity();
27 $returnArray[] = $testUser;
29 return $returnArray;
32 /**
33 * @param int $count
34 * @return UserIdentity[]
36 private function generateUsersWithInvalidSignatures( int $count ): array {
37 $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager();
38 $returnArray = $this->generateMutableTestUsers( $count );
39 foreach ( $returnArray as $user ) {
40 // Set the signature to invalid HTML
41 $userOptionsManager->setOption( $user, 'nickname', '<b>{{test' );
42 $userOptionsManager->setOption( $user, 'fancysig', true );
43 $userOptionsManager->saveOptions( $user );
45 return $returnArray;
48 private function generateUsersWithValidSignatures( int $count ) {
49 $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager();
50 foreach ( $this->generateMutableTestUsers( $count ) as $user ) {
51 // Set the signature to invalid HTML
52 $userOptionsManager->setOption( $user, 'nickname', '[[User:' . $user->getName() . "]]" );
53 $userOptionsManager->setOption( $user, 'fancysig', true );
54 $userOptionsManager->saveOptions( $user );
58 /** @dataProvider provideExecute */
59 public function testExecute( $validCount, $invalidCount ) {
60 $usersWithInvalidSignatures = $this->generateUsersWithInvalidSignatures( $invalidCount );
61 $this->generateUsersWithValidSignatures( $validCount );
62 $this->maintenance->execute();
63 $expectedOutputRegex = '/';
64 foreach ( $usersWithInvalidSignatures as $user ) {
65 $expectedOutputRegex .= $user->getName() . "\n";
67 $expectedOutputRegex .= ".*$invalidCount invalid signatures/";
68 $this->expectOutputRegex( $expectedOutputRegex );
71 public static function provideExecute() {
72 return [
73 'All signatures valid' => [ 4, 0 ],
74 'Some signatures valid' => [ 2, 3 ],