mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-23 10:28:55 +00:00
[ticket/17347] Add tests for delete ids
PHPBB-17347
This commit is contained in:
parent
77d1010081
commit
8432e506c4
3 changed files with 95 additions and 17 deletions
|
@ -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.',
|
||||
|
|
|
@ -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;
|
||||
|
|
90
tests/console/user/delete_ids_test.php
Normal file
90
tests/console/user/delete_ids_test.php
Normal file
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @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'));
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue