Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
37 / 37 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_console_searchindex_delete_test | |
100.00% |
37 / 37 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
| get_command_tester | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete_when_search_backend_dont_exist | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete_when_action_in_progress | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete_when_search_backend_not_available | |
100.00% |
6 / 6 |
|
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 phpbb\console\command\searchindex\delete; |
| 15 | use Symfony\Component\Console\Application; |
| 16 | use Symfony\Component\Console\Command\Command; |
| 17 | use Symfony\Component\Console\Tester\CommandTester; |
| 18 | |
| 19 | require_once __DIR__ . '/phpbb_console_searchindex_base.php'; |
| 20 | require_once __DIR__ . '/../../mock/search_backend_mock.php'; |
| 21 | |
| 22 | class phpbb_console_searchindex_delete_test extends phpbb_console_searchindex_base |
| 23 | { |
| 24 | public function get_command_tester() |
| 25 | { |
| 26 | $application = new Application(); |
| 27 | $application->add(new delete( |
| 28 | $this->language, |
| 29 | $this->log, |
| 30 | $this->post_helper, |
| 31 | $this->search_backend_factory, |
| 32 | $this->state_helper, |
| 33 | $this->user |
| 34 | )); |
| 35 | |
| 36 | $command = $application->find('searchindex:delete'); |
| 37 | |
| 38 | return new CommandTester($command); |
| 39 | } |
| 40 | |
| 41 | public function test_delete() |
| 42 | { |
| 43 | $command_tester = $this->get_command_tester(); |
| 44 | |
| 45 | $command_tester->execute([ |
| 46 | 'search-backend' => 'search_backend_mock', |
| 47 | ]); |
| 48 | |
| 49 | $this->assertEquals(Command::SUCCESS, $command_tester->getStatusCode()); |
| 50 | $this->assertStringContainsString('CLI_SEARCHINDEX_DELETE_SUCCESS', $command_tester->getDisplay()); |
| 51 | } |
| 52 | |
| 53 | public function test_delete_when_search_backend_dont_exist() |
| 54 | { |
| 55 | $command_tester = $this->get_command_tester(); |
| 56 | |
| 57 | $command_tester->execute([ |
| 58 | 'search-backend' => 'missing', |
| 59 | ]); |
| 60 | |
| 61 | $this->assertEquals(Command::FAILURE, $command_tester->getStatusCode()); |
| 62 | $this->assertStringContainsString('CLI_SEARCHINDEX_BACKEND_NOT_FOUND', $command_tester->getDisplay()); |
| 63 | } |
| 64 | |
| 65 | public function test_delete_when_action_in_progress() |
| 66 | { |
| 67 | $this->config['search_indexing_state'] = ['not', 'empty']; |
| 68 | |
| 69 | $command_tester = $this->get_command_tester(); |
| 70 | |
| 71 | $command_tester->execute([ |
| 72 | 'search-backend' => 'search_backend_mock', |
| 73 | ]); |
| 74 | |
| 75 | $this->assertEquals(Command::FAILURE, $command_tester->getStatusCode()); |
| 76 | $this->assertStringContainsString('CLI_SEARCHINDEX_ACTION_IN_PROGRESS', $command_tester->getDisplay()); |
| 77 | |
| 78 | $this->config['search_indexing_state'] = []; |
| 79 | } |
| 80 | |
| 81 | public function test_delete_when_search_backend_not_available() |
| 82 | { |
| 83 | $command_tester = $this->get_command_tester(); |
| 84 | |
| 85 | $command_tester->execute([ |
| 86 | 'search-backend' => 'search_backend_mock_not_available', |
| 87 | ]); |
| 88 | |
| 89 | $this->assertEquals(Command::FAILURE, $command_tester->getStatusCode()); |
| 90 | $this->assertStringContainsString('CLI_SEARCHINDEX_BACKEND_NOT_AVAILABLE', $command_tester->getDisplay()); |
| 91 | } |
| 92 | } |