From 0ae7e3f99272f9d9f1480016e0aac92848ee929b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 10 Nov 2023 20:27:16 +0100 Subject: [PATCH] [ticket/13162] Add tests for truncate table via tools PHPBB3-13162 --- tests/dbal/db_tools_test.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 70295b2165..73543ed97d 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -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')