3 namespace MediaWiki\Tests\Maintenance
;
6 use MediaWiki\User\UserIdentity
;
9 * @covers \CheckSignatures
13 class CheckSignaturesTest
extends MaintenanceBaseTestCase
{
15 protected function getMaintenanceClass() {
16 return CheckSignatures
::class;
21 * @return UserIdentity[]
23 private function generateMutableTestUsers( int $count ): array {
25 for ( $i = 0; $i < $count; $i++
) {
26 $testUser = $this->getMutableTestUser()->getUserIdentity();
27 $returnArray[] = $testUser;
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 );
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() {
73 'All signatures valid' => [ 4, 0 ],
74 'Some signatures valid' => [ 2, 3 ],