From 1019226dfa359cb223d68e7b9132006a8cd2a859 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 10 May 2012 23:22:35 -0400 Subject: [PATCH 1/2] [ticket/10887] Split auto increment test from db tools test. Auto increment test does not need any particular columns and should not depend, in particular, on correct handling of binary data. This commit moves auto increment test into its own file and gives it its own table with a simple schema. PHPBB3-10887 --- tests/dbal/auto_increment_test.php | 100 +++++++++++++++++++++++++++++ tests/dbal/db_tools_test.php | 45 ------------- 2 files changed, 100 insertions(+), 45 deletions(-) create mode 100644 tests/dbal/auto_increment_test.php diff --git a/tests/dbal/auto_increment_test.php b/tests/dbal/auto_increment_test.php new file mode 100644 index 0000000000..c18e589861 --- /dev/null +++ b/tests/dbal/auto_increment_test.php @@ -0,0 +1,100 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->tools = new phpbb_db_tools($this->db); + + $this->table_data = array( + 'COLUMNS' => array( + 'c_id' => array('UINT', NULL, 'auto_increment'), + 'c_uint' => array('UINT', 4), + ), + 'PRIMARY_KEY' => 'c_id', + ); + $this->tools->sql_create_table('prefix_table_name', $this->table_data); + $this->table_exists = true; + } + + protected function tearDown() + { + if ($this->table_exists) + { + $this->tools->sql_table_drop('prefix_table_name'); + } + + parent::tearDown(); + } + + static protected function get_default_values() + { + return array( + 'c_uint' => 0, + ); + } + + public function test_auto_increment() + { + $sql = 'DELETE FROM prefix_table_name'; + $result = $this->db->sql_query($sql); + + $row1 = array_merge(self::get_default_values(), array( + 'c_uint' => 1, + )); + $row2 = array_merge(self::get_default_values(), array( + 'c_uint' => 2, + )); + + $sql = 'INSERT INTO prefix_table_name ' . $this->db->sql_build_array('INSERT', $row1); + $result = $this->db->sql_query($sql); + $id1 = $this->db->sql_nextid(); + + $sql = 'INSERT INTO prefix_table_name ' . $this->db->sql_build_array('INSERT', $row2); + $result = $this->db->sql_query($sql); + $id2 = $this->db->sql_nextid(); + + $this->assertGreaterThan($id1, $id2, 'Auto increment should increase the id value'); + + $sql = "SELECT * + FROM prefix_table_name WHERE c_id = $id1"; + $result = $this->db->sql_query($sql); + $row_actual = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $row1['c_id'] = $id1; + $this->assertEquals($row1, $row_actual); + + $sql = "SELECT * + FROM prefix_table_name WHERE c_id = $id2"; + $result = $this->db->sql_query($sql); + $row_actual = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $row2['c_id'] = $id2; + $this->assertEquals($row2, $row_actual); + } +} diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index c7ddb88ce8..516fb9e739 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -189,51 +189,6 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->assertEquals($row_expect[$column_name], $row_actual[$column_name], "Column $column_name of type $type should have equal return and input value."); } - public function test_auto_increment() - { - $sql = 'DELETE FROM prefix_table_name'; - $result = $this->db->sql_query($sql); - - $row1 = array_merge(self::get_default_values(), array( - 'c_uint' => 1, - 'c_vchar' => '1', // these values are necessary to avoid unique index issues - 'c_vchar_size' => '1', - )); - $row2 = array_merge(self::get_default_values(), array( - 'c_uint' => 2, - 'c_vchar' => '2', - 'c_vchar_size' => '2', - )); - - $sql = 'INSERT INTO prefix_table_name ' . $this->db->sql_build_array('INSERT', $row1); - $result = $this->db->sql_query($sql); - $id1 = $this->db->sql_nextid(); - - $sql = 'INSERT INTO prefix_table_name ' . $this->db->sql_build_array('INSERT', $row2); - $result = $this->db->sql_query($sql); - $id2 = $this->db->sql_nextid(); - - $this->assertGreaterThan($id1, $id2, 'Auto increment should increase the id value'); - - $sql = "SELECT * - FROM prefix_table_name WHERE c_id = $id1"; - $result = $this->db->sql_query($sql); - $row_actual = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - $row1['c_id'] = $id1; - $this->assertEquals($row1, $row_actual); - - $sql = "SELECT * - FROM prefix_table_name WHERE c_id = $id2"; - $result = $this->db->sql_query($sql); - $row_actual = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - $row2['c_id'] = $id2; - $this->assertEquals($row2, $row_actual); - } - public function test_list_columns() { $this->assertEquals( From b5b65c214dc42a9e7a9cf15ebc00600d00331985 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 11 May 2012 05:06:46 -0400 Subject: [PATCH 2/2] [ticket/10887] Add spaces. PHPBB3-10887 --- tests/dbal/auto_increment_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dbal/auto_increment_test.php b/tests/dbal/auto_increment_test.php index c18e589861..e87fc1c6bd 100644 --- a/tests/dbal/auto_increment_test.php +++ b/tests/dbal/auto_increment_test.php @@ -19,7 +19,7 @@ class phpbb_dbal_auto_increment_test extends phpbb_database_test_case public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); } protected function setUp()