Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
65 / 65 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_console_user_delete_ids_test | |
100.00% |
65 / 65 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
| get_command_tester | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete_one | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete_bot | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete_non_user | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete_cancel | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | use Symfony\Component\Console\Application; |
| 15 | use Symfony\Component\Console\Tester\CommandTester; |
| 16 | use phpbb\console\command\user\delete_id; |
| 17 | |
| 18 | require_once __DIR__ . '/base.php'; |
| 19 | |
| 20 | class phpbb_console_user_delete_ids_test extends phpbb_console_user_base |
| 21 | { |
| 22 | public function get_command_tester() |
| 23 | { |
| 24 | $application = new Application(); |
| 25 | $application->add(new delete_id( |
| 26 | $this->db, |
| 27 | $this->language, |
| 28 | $this->log, |
| 29 | $this->user, |
| 30 | $this->user_loader, |
| 31 | BOTS_TABLE, |
| 32 | USER_GROUP_TABLE, |
| 33 | USERS_TABLE, |
| 34 | $this->phpbb_root_path, |
| 35 | $this->php_ext |
| 36 | )); |
| 37 | |
| 38 | $command = $application->find('user:delete_id'); |
| 39 | $this->command_name = $command->getName(); |
| 40 | $this->question = $command->getHelper('question'); |
| 41 | |
| 42 | return new CommandTester($command); |
| 43 | } |
| 44 | |
| 45 | public function test_delete() |
| 46 | { |
| 47 | $command_tester = $this->get_command_tester(); |
| 48 | |
| 49 | $command_tester->setInputs(['yes', '']); |
| 50 | |
| 51 | $command_tester->execute(array( |
| 52 | 'command' => $this->command_name, |
| 53 | 'user_ids' => [3, 4], |
| 54 | '--delete-posts' => false, |
| 55 | )); |
| 56 | |
| 57 | $this->assertNull($this->get_user_id('Test')); |
| 58 | $this->assertNull($this->get_user_id('Test 2')); |
| 59 | $this->assertStringContainsString('CLI_USER_DELETE_ID_SUCCESS', $command_tester->getDisplay()); |
| 60 | } |
| 61 | |
| 62 | public function test_delete_one() |
| 63 | { |
| 64 | $command_tester = $this->get_command_tester(); |
| 65 | |
| 66 | $command_tester->setInputs(['yes', '']); |
| 67 | |
| 68 | $command_tester->execute(array( |
| 69 | 'command' => $this->command_name, |
| 70 | 'user_ids' => [3], |
| 71 | '--delete-posts' => false, |
| 72 | )); |
| 73 | |
| 74 | $this->assertNull($this->get_user_id('Test')); |
| 75 | $this->assertNotNull($this->get_user_id('Test 2')); |
| 76 | $this->assertStringContainsString('CLI_USER_DELETE_ID_SUCCESS', $command_tester->getDisplay()); |
| 77 | } |
| 78 | |
| 79 | public function test_delete_bot() |
| 80 | { |
| 81 | $command_tester = $this->get_command_tester(); |
| 82 | |
| 83 | $this->assertNotNull($this->get_user_id('Test Bot')); |
| 84 | |
| 85 | $command_tester->setInputs(['yes', '']); |
| 86 | |
| 87 | $command_tester->execute(array( |
| 88 | 'command' => $this->command_name, |
| 89 | 'user_ids' => [6], |
| 90 | '--delete-posts' => false, |
| 91 | )); |
| 92 | |
| 93 | $this->assertNull($this->get_user_id('Test Bot')); |
| 94 | $this->assertStringContainsString('CLI_USER_DELETE_ID_SUCCESS', $command_tester->getDisplay()); |
| 95 | } |
| 96 | |
| 97 | public function test_delete_non_user() |
| 98 | { |
| 99 | $command_tester = $this->get_command_tester(); |
| 100 | |
| 101 | $command_tester->setInputs(['yes', '']); |
| 102 | |
| 103 | $command_tester->execute(array( |
| 104 | 'command' => $this->command_name, |
| 105 | 'user_ids' => [999], |
| 106 | '--delete-posts' => false, |
| 107 | )); |
| 108 | |
| 109 | $this->assertStringContainsString('CLI_USER_DELETE_NONE', $command_tester->getDisplay()); |
| 110 | } |
| 111 | |
| 112 | public function test_delete_cancel() |
| 113 | { |
| 114 | $command_tester = $this->get_command_tester(); |
| 115 | |
| 116 | $this->assertEquals(3, $this->get_user_id('Test')); |
| 117 | |
| 118 | $command_tester->setInputs(['no', '']); |
| 119 | |
| 120 | $command_tester->execute(array( |
| 121 | 'command' => $this->command_name, |
| 122 | 'user_ids' => [3, 4], |
| 123 | '--delete-posts' => false, |
| 124 | )); |
| 125 | |
| 126 | $this->assertNotNull($this->get_user_id('Test')); |
| 127 | $this->assertNotNull($this->get_user_id('Test 2')); |
| 128 | } |
| 129 | } |