diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php index a0c2f3693a..e271380a2f 100644 --- a/phpBB/language/en/cli.php +++ b/phpBB/language/en/cli.php @@ -159,7 +159,7 @@ $lang = array_merge($lang, array( 'CLI_USER_DELETE_CONFIRM' => 'Are you sure you want to delete ā€˜%s’? [y/N]', 'CLI_USER_DELETE_IDS_CONFIRM' => 'Are you sure you want to delete the user IDs ā€˜%s’? [y/N]', 'CLI_USER_DELETE_IDS_SUCCESS' => 'Successfully deleted user IDs.', - 'CLI_USER_DELETE_IDS_NOT_FOUND' => 'No users were deleted by user ID.', + 'CLI_USER_DELETE_NONE' => 'No users were deleted by user ID.', 'CLI_USER_RECLEAN_START' => 'Re-cleaning usernames', 'CLI_USER_RECLEAN_DONE' => [ 0 => 'Re-cleaning complete. No usernames needed to be cleaned.', diff --git a/phpBB/phpbb/console/command/user/delete_ids.php b/phpBB/phpbb/console/command/user/delete_ids.php index cdd7ef544e..3ecd43b314 100644 --- a/phpBB/phpbb/console/command/user/delete_ids.php +++ b/phpBB/phpbb/console/command/user/delete_ids.php @@ -14,7 +14,6 @@ namespace phpbb\console\command\user; use phpbb\console\command\command; -use phpbb\db\driver\driver_interface; use phpbb\language\language; use phpbb\log\log_interface; use phpbb\user; @@ -28,9 +27,6 @@ use Symfony\Component\Console\Style\SymfonyStyle; class delete_ids extends command { - /** @var driver_interface */ - protected $db; - /** @var language */ protected $language; @@ -40,18 +36,10 @@ class delete_ids extends command /** @var user_loader */ protected $user_loader; - /** - * phpBB root path - * - * @var string - */ + /** @var string phpBB root path */ protected $phpbb_root_path; - /** - * PHP extension. - * - * @var string - */ + /** @var string PHP extension */ protected $php_ext; /** @@ -122,7 +110,7 @@ class delete_ids extends command { foreach ($user_ids as $user_id) { - $user_row = $this->user_loader->get_user((int) $user_id); + $user_row = $this->user_loader->get_user($user_id); // Skip anonymous user if ($user_row['user_id'] == ANONYMOUS) @@ -148,7 +136,7 @@ class delete_ids extends command if (!$deleted_users) { - $io->caution($this->language->lang('CLI_USER_DELETE_IDS_NOT_FOUND')); + $io->note($this->language->lang('CLI_USER_DELETE_NONE')); } return 0; diff --git a/tests/console/user/delete_ids_test.php b/tests/console/user/delete_ids_test.php new file mode 100644 index 0000000000..0595271b6b --- /dev/null +++ b/tests/console/user/delete_ids_test.php @@ -0,0 +1,90 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Tester\CommandTester; +use phpbb\console\command\user\delete_ids; + +require_once __DIR__ . '/base.php'; + +class phpbb_console_user_delete_ids_test extends phpbb_console_user_base +{ + public function get_command_tester() + { + $application = new Application(); + $application->add(new delete_ids( + $this->language, + $this->log, + $this->user, + $this->user_loader, + $this->phpbb_root_path, + $this->php_ext + )); + + $command = $application->find('user:delete_ids'); + $this->command_name = $command->getName(); + $this->question = $command->getHelper('question'); + + return new CommandTester($command); + } + + public function test_delete() + { + $command_tester = $this->get_command_tester(); + + $command_tester->setInputs(['yes', '']); + + $command_tester->execute(array( + 'command' => $this->command_name, + 'user_ids' => [3, 4], + '--delete-posts' => false, + )); + + $this->assertNull($this->get_user_id('Test')); + $this->assertNull($this->get_user_id('Test 2')); + $this->assertStringContainsString('CLI_USER_DELETE_IDS_SUCCESS', $command_tester->getDisplay()); + } + + public function test_delete_non_user() + { + $command_tester = $this->get_command_tester(); + + $command_tester->setInputs(['yes', '']); + + $command_tester->execute(array( + 'command' => $this->command_name, + 'user_ids' => [999], + '--delete-posts' => false, + )); + + $this->assertStringContainsString('CLI_USER_DELETE_NONE', $command_tester->getDisplay()); + } + + public function test_delete_cancel() + { + $command_tester = $this->get_command_tester(); + + $this->assertEquals(3, $this->get_user_id('Test')); + + $command_tester->setInputs(['no', '']); + + $command_tester->execute(array( + 'command' => $this->command_name, + 'user_ids' => [3, 4], + '--delete-posts' => false, + )); + + $this->assertNotNull($this->get_user_id('Test')); + $this->assertNotNull($this->get_user_id('Test 2')); + } +}