1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-11 11:13:59 +02:00

Merge pull request #6564 from marc1706/ticket/13162

[ticket/13162] Add truncate table functionality to database tools
This commit is contained in:
Marc Alexander
2024-02-23 19:57:49 +01:00
committed by GitHub
22 changed files with 144 additions and 113 deletions

View File

@@ -22,6 +22,7 @@ class phpbb_console_command_cache_purge_test extends phpbb_test_case
protected $cache_dir;
protected $cache;
protected $db;
protected $db_tools;
protected $config;
protected $user;
@@ -42,6 +43,8 @@ class phpbb_console_command_cache_purge_test extends phpbb_test_case
$this->cache = new \phpbb\cache\driver\file($this->cache_dir);
$this->db = $this->createMock('\phpbb\db\driver\driver_interface');
$tools_factory = new \phpbb\db\tools\factory();
$this->db_tools = $this->createMock('\phpbb\db\tools\doctrine');
$this->config = new \phpbb\config\config(array('assets_version' => 1));
$this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
@@ -86,7 +89,7 @@ class phpbb_console_command_cache_purge_test extends phpbb_test_case
public function get_command_tester()
{
$application = new Application();
$application->add(new purge($this->user, $this->cache, $this->db, $this->createMock('\phpbb\auth\auth'), new \phpbb\log\dummy(), $this->config));
$application->add(new purge($this->user, $this->cache, $this->db, $this->db_tools, $this->createMock('\phpbb\auth\auth'), new \phpbb\log\dummy(), $this->config));
$command = $application->find('cache:purge');
return new CommandTester($command);

View File

@@ -357,6 +357,34 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$this->assertFalse($this->tools->sql_table_exists('prefix_test_table'));
}
public function test_truncate_table()
{
$this->tools->sql_create_table('truncate_test_table',
['COLUMNS' => [
'foo' => ['UINT', 42],
]]
);
$this->assertTrue($this->tools->sql_table_exists('truncate_test_table'));
$sql = 'INSERT INTO truncate_test_table(foo) VALUES(19)';
$this->db->sql_query($sql);
$sql = 'SELECT * FROM truncate_test_table';
$result = $this->db->sql_query($sql);
$rowset = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
$this->assertGreaterThan(0, count($rowset), 'Failed asserting that data exists in truncate_test_table.');
$this->tools->sql_truncate_table('truncate_test_table');
$result = $this->db->sql_query($sql);
$rowset = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
$this->assertEquals(0, count($rowset), 'Failed asserting that truncate was successful for table.');
}
public function test_perform_schema_changes_drop_tables()
{
$db_tools = $this->getMockBuilder('\phpbb\db\tools\doctrine')

View File

@@ -16,6 +16,7 @@ require_once __DIR__ . '/../test_framework/phpbb_search_test_case.php';
class phpbb_search_native_test extends phpbb_search_test_case
{
protected $db;
protected $db_tools;
public function getDataSet()
{
@@ -34,11 +35,13 @@ class phpbb_search_native_test extends phpbb_search_test_case
$user = $this->createMock('\phpbb\user');
$this->db = $this->new_dbal();
$tools_factory = new \phpbb\db\tools\factory();
$this->db_tools = $tools_factory->get($this->new_doctrine_dbal());
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$class = self::get_search_wrapper('\phpbb\search\backend\fulltext_native');
$config['fulltext_native_min_chars'] = 2;
$config['fulltext_native_max_chars'] = 14;
$this->search = new $class($config, $this->db, $phpbb_dispatcher, $language, $user, SEARCH_RESULTS_TABLE, SEARCH_WORDLIST_TABLE, SEARCH_WORDMATCH_TABLE, $phpbb_root_path, $phpEx);
$this->search = new $class($config, $this->db, $this->db_tools, $phpbb_dispatcher, $language, $user, SEARCH_RESULTS_TABLE, SEARCH_WORDLIST_TABLE, SEARCH_WORDMATCH_TABLE, $phpbb_root_path, $phpEx);
}
public function keywords()