From 15516bd07853cbda585f1716ce1b614d43cf9d9a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 23 May 2014 16:10:07 +0200 Subject: [ticket/12570] Add a unit test to show broken sql_affectedrows() PHPBB3-12570 --- tests/dbal/sql_affected_rows_test.php | 73 +++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/dbal/sql_affected_rows_test.php (limited to 'tests/dbal/sql_affected_rows_test.php') diff --git a/tests/dbal/sql_affected_rows_test.php b/tests/dbal/sql_affected_rows_test.php new file mode 100644 index 0000000000..df008bab9a --- /dev/null +++ b/tests/dbal/sql_affected_rows_test.php @@ -0,0 +1,73 @@ +db = $this->new_dbal(); + } + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + public function test_select() + { + $sql = 'SELECT * + FROM ' . CONFIG_TABLE; + $this->db->sql_query($sql); + + $this->assertEquals(2, $this->db->sql_affectedrows()); + } + + public function test_update() + { + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = 'bertie'"; + $this->db->sql_query($sql); + + $this->assertEquals(2, $this->db->sql_affectedrows()); + } + + public function test_update_all_matched_unequal_updated() + { + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = 'foo'"; + $this->db->sql_query($sql); + + $this->assertEquals(2, $this->db->sql_affectedrows()); + } + + public function test_update_some_matched_unequal_updated() + { + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = 'foo' + WHERE config_value = 'foo'"; + $this->db->sql_query($sql); + + $this->assertEquals(1, $this->db->sql_affectedrows()); + } + + public function test_insert() + { + $sql = 'INSERT INTO ' . CONFIG_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( + 'config_name' => 'bertie', + 'config_value' => 'rules', + )); + $this->db->sql_query($sql); + + $this->assertEquals(1, $this->db->sql_affectedrows()); + } +} -- cgit v1.2.1 From 275e56ce70b194ed6712ba30707494607dbdc1cf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 23 May 2014 18:04:40 +0200 Subject: [ticket/12570] Remove test for affected rows after SELECT It's not supposed to work PHPBB3-12570 --- tests/dbal/sql_affected_rows_test.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'tests/dbal/sql_affected_rows_test.php') diff --git a/tests/dbal/sql_affected_rows_test.php b/tests/dbal/sql_affected_rows_test.php index df008bab9a..860b8bf237 100644 --- a/tests/dbal/sql_affected_rows_test.php +++ b/tests/dbal/sql_affected_rows_test.php @@ -23,15 +23,6 @@ class phpbb_dbal_sql_affected_rows_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); } - public function test_select() - { - $sql = 'SELECT * - FROM ' . CONFIG_TABLE; - $this->db->sql_query($sql); - - $this->assertEquals(2, $this->db->sql_affectedrows()); - } - public function test_update() { $sql = 'UPDATE ' . CONFIG_TABLE . " @@ -50,7 +41,7 @@ class phpbb_dbal_sql_affected_rows_test extends phpbb_database_test_case $this->assertEquals(2, $this->db->sql_affectedrows()); } - public function test_update_some_matched_unequal_updated() + public function test_update_same_value_matched_unequal_updated() { $sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'foo' -- cgit v1.2.1