diff options
| author | Andreas Fischer <bantu@phpbb.com> | 2012-07-17 17:59:56 +0200 |
|---|---|---|
| committer | Andreas Fischer <bantu@phpbb.com> | 2012-07-17 17:59:56 +0200 |
| commit | 6980b3dcfde13a7bf3c3986fb1add6ce0f5d8c79 (patch) | |
| tree | 6f85434457d1e094430401a701285fe7ca1a7946 /tests | |
| parent | b45bc27339d03016d47c0247aede8da5ce38a4ee (diff) | |
| parent | 1b826842aadc16ad35485479f4bb3bdef03b534c (diff) | |
| download | forums-6980b3dcfde13a7bf3c3986fb1add6ce0f5d8c79.tar forums-6980b3dcfde13a7bf3c3986fb1add6ce0f5d8c79.tar.gz forums-6980b3dcfde13a7bf3c3986fb1add6ce0f5d8c79.tar.bz2 forums-6980b3dcfde13a7bf3c3986fb1add6ce0f5d8c79.tar.xz forums-6980b3dcfde13a7bf3c3986fb1add6ce0f5d8c79.zip | |
Merge remote-tracking branch 'nickvergessen/ticket/10942' into develop
* nickvergessen/ticket/10942:
[ticket/10942] Avoid possible conflicts with magic words in unit tests
[ticket/10942] Add access modifiers
[ticket/10942] Use ANSI SQL standard || in dbal.php
[ticket/10942] Fix up unit tests for sql_case()
[ticket/10942] Require same data type and do not cast expressions automatically
[ticket/10942] Make unit tests for sql_case simpler
[ticket/10942] Add a comment why we cast to sql_case()
[ticket/10942] Rename method sql_conditional() to sql_case()
[ticket/10942] Change term string to expression to avoid confusion
[ticket/10942] Fix sql_conditional for mssql, postgre and oracle
[ticket/10942] Fix function name on order_lower_test.php
[ticket/10942] Add unit tests for sql_concatenate
[ticket/10942] Add sql_concatenate to dbal
[ticket/10942] Add unit tests for sql_conditional
[ticket/10942] Add sql_conditional to dbal
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/dbal/case_test.php | 69 | ||||
| -rw-r--r-- | tests/dbal/concatenate_test.php | 64 | ||||
| -rw-r--r-- | tests/dbal/order_lower_test.php | 2 |
3 files changed, 134 insertions, 1 deletions
diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php new file mode 100644 index 0000000000..57a1729a39 --- /dev/null +++ b/tests/dbal/case_test.php @@ -0,0 +1,69 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_dbal_case_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function test_case_int() + { + $db = $this->new_dbal(); + + $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS test_num + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals(1, (int) $db->sql_fetchfield('test_num')); + + $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS test_num + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals(2, (int) $db->sql_fetchfield('test_num')); + } + + public function test_case_string() + { + $db = $this->new_dbal(); + + $sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS test_string + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals('foo', $db->sql_fetchfield('test_string')); + + $sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS test_string + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals('bar', $db->sql_fetchfield('test_string')); + } + + public function test_case_column() + { + $db = $this->new_dbal(); + + $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string + FROM phpbb_config + WHERE config_name = 'config1'"; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals('config1', $db->sql_fetchfield('test_string')); + + $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string + FROM phpbb_config + WHERE config_value = 'bar'"; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals('bar', $db->sql_fetchfield('test_string')); + } +} diff --git a/tests/dbal/concatenate_test.php b/tests/dbal/concatenate_test.php new file mode 100644 index 0000000000..0891fa58a0 --- /dev/null +++ b/tests/dbal/concatenate_test.php @@ -0,0 +1,64 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_dbal_concatenate_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function test_concatenate_string() + { + $db = $this->new_dbal(); + + $sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', "'" . $db->sql_escape('append') . "'") . ' AS string + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array( + 'config_name' => 'config1', + 'string' => 'config1append', + ), + array( + 'config_name' => 'config2', + 'string' => 'config2append', + ), + ), + $db->sql_fetchrowset($result) + ); + } + + public function test_concatenate_statement() + { + $db = $this->new_dbal(); + + $sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', 'config_value') . ' AS string + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array( + 'config_name' => 'config1', + 'string' => 'config1foo', + ), + array( + 'config_name' => 'config2', + 'string' => 'config2bar', + ), + ), + $db->sql_fetchrowset($result) + ); + } +} diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php index e16c0c20ee..84d454742f 100644 --- a/tests/dbal/order_lower_test.php +++ b/tests/dbal/order_lower_test.php @@ -14,7 +14,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/styles.xml'); } - public function test_cross_join() + public function test_order_lower() { $db = $this->new_dbal(); |
