phpbb/tests/console/searchindex/delete_test.php
Ruben Calvo ac227a9ea6
[ticket/12683] Add basic tests
PHPBB3-12683
2022-12-11 17:16:44 +01:00

70 lines
1.8 KiB
PHP

<?php
use phpbb\console\command\searchindex\delete;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;
require_once __DIR__ . '/base.php';
require_once __DIR__ . '/mock/search_backend_mock.php';
class delete_test extends base
{
public function get_command_tester()
{
$application = new Application();
$application->add(new delete(
$this->config,
$this->language,
$this->log,
$this->post_helper,
$this->search_backend_factory,
$this->state_helper,
$this->user
));
$command = $application->find('searchindex:delete');
return new CommandTester($command);
}
public function test_delete()
{
$command_tester = $this->get_command_tester();
$command_tester->execute([
'search-backend' => 'search_backend_mock',
]);
$this->assertEquals(Command::SUCCESS, $command_tester->getStatusCode());
$this->assertStringContainsString('CLI_SEARCHINDEX_DELETE_SUCCESS', $command_tester->getDisplay());
}
public function test_delete_when_search_backend_dont_exist()
{
$command_tester = $this->get_command_tester();
$command_tester->execute([
'search-backend' => 'missing',
]);
$this->assertEquals(Command::FAILURE, $command_tester->getStatusCode());
$this->assertStringContainsString('CLI_SEARCHINDEX_BACKEND_NOT_FOUND', $command_tester->getDisplay());
}
public function test_delete_when_action_in_progress()
{
$this->config['search_indexing_state'] = ['not', 'empty'];
$command_tester = $this->get_command_tester();
$command_tester->execute([
'search-backend' => 'search_backend_mock',
]);
$this->assertEquals(Command::FAILURE, $command_tester->getStatusCode());
$this->assertStringContainsString('CLI_SEARCHINDEX_ACTION_IN_PROGRESS', $command_tester->getDisplay());
$this->config['search_indexing_state'] = [];
}
}