| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Maintenance; |
| 4 |
|
| 5 |
use EmptyUserGroup; |
| 6 |
use MediaWiki\User\UserIdentity; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class EmptyUserGroupTest extends MaintenanceBaseTestCase { |
| 14 |
|
| 15 |
protected function getMaintenanceClass() { |
| 16 |
return EmptyUserGroup::class; |
| 17 |
} |
| 18 |
|
| 19 |
public function testExecuteForEmptyGroup() { |
| 20 |
$this->maintenance->setArg( 0, 'sysop' ); |
| 21 |
$this->maintenance->execute(); |
| 22 |
$this->expectOutputString( |
| 23 |
"Removing users from sysop...\n" . |
| 24 |
" ...nothing to do, group was empty.\n" |
| 25 |
); |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
private function createTestUsersWithGroup( string $group, int $numberOfUsers ): array { |
| 36 |
$userGroupManager = $this->getServiceContainer()->getUserGroupManager(); |
| 37 |
$returnArray = []; |
| 38 |
for ( $i = 0; $i < $numberOfUsers; $i++ ) { |
| 39 |
$user = $this->getMutableTestUser()->getUserIdentity(); |
| 40 |
$userGroupManager->addUserToGroup( $user, $group ); |
| 41 |
$returnArray[] = $user; |
| 42 |
} |
| 43 |
return $returnArray; |
| 44 |
} |
| 45 |
|
| 46 |
public function testExecuteForGroupWithUsers() { |
| 47 |
|
| 48 |
$sysopUsers = $this->createTestUsersWithGroup( 'sysop', 5 ); |
| 49 |
|
| 50 |
$botUsers = $this->createTestUsersWithGroup( 'bot', 1 ); |
| 51 |
|
| 52 |
$this->maintenance->setArg( 0, 'sysop' ); |
| 53 |
$this->maintenance->setOption( 'batch-size', 2 ); |
| 54 |
$this->maintenance->execute(); |
| 55 |
$this->expectOutputString( |
| 56 |
"Removing users from sysop...\n" . |
| 57 |
" ...done! Removed 5 users in total.\n" |
| 58 |
); |
| 59 |
|
| 60 |
foreach ( $sysopUsers as $user ) { |
| 61 |
$this->assertNotContains( |
| 62 |
'sysop', |
| 63 |
$this->getServiceContainer()->getUserGroupManager()->getUserGroups( $user ) |
| 64 |
); |
| 65 |
} |
| 66 |
|
| 67 |
foreach ( $botUsers as $user ) { |
| 68 |
$this->assertContains( |
| 69 |
'bot', |
| 70 |
$this->getServiceContainer()->getUserGroupManager()->getUserGroups( $user ) |
| 71 |
); |
| 72 |
} |
| 73 |
} |
| 74 |
} |