aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dbal
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2011-07-11 00:29:45 +0200
committerAndreas Fischer <bantu@phpbb.com>2011-07-11 00:29:45 +0200
commitc8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff (patch)
treeb7e507311afa3db9e372f9d5b8b01455dbd50841 /tests/dbal
parent7f21a5f46156660d7ea6a4bdb59166ac553e2be8 (diff)
parente6572b766f7fd5f8547b28fd52d25e4a96cfc2cd (diff)
downloadforums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.tar
forums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.tar.gz
forums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.tar.bz2
forums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.tar.xz
forums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.zip
Merge branch 'prep-release-3.0.9'
* prep-release-3.0.9: (359 commits) [prep-release-3.0.9] Bumping version number for 3.0.9 final. [prep-release-3.0.9] Update Changelog for 3.0.9-RC4 release. [prep-release-3.0.9] Decreasing version for an RC4 release. [ticket/9859] Changing all phpBB footers to match the new credit line [ticket/9859] New footer copyright line with registered symbol [ticket/10250] The site_logo hash is different depending on imageset & language [ticket/10250] Destroy cached md5 hash of site_logo on refreshing an imageset [ticket/10250] Overwrite the site_logo width&height when the phpbb logo is used [ticket/10247] Remove attempt_id as primary key from database_update.php [ticket/10250] Added the new phpBB Logo with the Registered Trademark Symbol [ticket/10247] Use COUNT(*) instead of COUNT(attempt_id) [prep-release-3.0.9] Update Changelog for 3.0.9 release. [prep-release-3.0.9] Bumping version number for the final 3.0.9 release. [ticket/10247] Removing attempt_id column from the 3.0.8 to 3.0.9-RC1 updater. [ticket/10247] Add a db_tools test for the removal of a primary key column. [ticket/10247] Add empty data section to database update for RC4 [ticket/10247] Remove unecessary attempt_id primary key column [prep-release-3.0.9] Bump database version to RC3 too. [prep-release-3.0.9] Update Changelog for 3.0.9-RC3 release. [prep-release-3.0.9] Bumping version number for 3.0.9-RC3. ...
Diffstat (limited to 'tests/dbal')
-rw-r--r--tests/dbal/all_tests.php42
-rw-r--r--tests/dbal/db_tools_test.php276
-rw-r--r--tests/dbal/select_test.php (renamed from tests/dbal/select.php)27
-rw-r--r--tests/dbal/write_test.php (renamed from tests/dbal/write.php)3
4 files changed, 302 insertions, 46 deletions
diff --git a/tests/dbal/all_tests.php b/tests/dbal/all_tests.php
deleted file mode 100644
index cfa8176246..0000000000
--- a/tests/dbal/all_tests.php
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-if (!defined('PHPUnit_MAIN_METHOD'))
-{
- define('PHPUnit_MAIN_METHOD', 'phpbb_dbal_all_tests::main');
-}
-
-require_once 'test_framework/framework.php';
-require_once 'PHPUnit/TextUI/TestRunner.php';
-
-require_once 'dbal/select.php';
-require_once 'dbal/write.php';
-
-class phpbb_dbal_all_tests
-{
- public static function main()
- {
- PHPUnit_TextUI_TestRunner::run(self::suite());
- }
-
- public static function suite()
- {
- $suite = new PHPUnit_Framework_TestSuite('phpBB Database Abstraction Layer');
-
- $suite->addTestSuite('phpbb_dbal_select_test');
- $suite->addTestSuite('phpbb_dbal_write_test');
-
- return $suite;
- }
-}
-
-if (PHPUnit_MAIN_METHOD == 'phpbb_dbal_all_tests::main')
-{
- phpbb_dbal_all_tests::main();
-}
diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php
new file mode 100644
index 0000000000..ddea500f83
--- /dev/null
+++ b/tests/dbal/db_tools_test.php
@@ -0,0 +1,276 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';
+
+class phpbb_dbal_db_tools_test extends phpbb_database_test_case
+{
+ protected $db;
+ protected $tools;
+ protected $table_exists;
+ protected $table_data;
+
+ public function getDataSet()
+ {
+ return $this->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_int_size' => array('INT:4', 4),
+ 'c_bint' => array('BINT', 4),
+ 'c_uint' => array('UINT', 4),
+ 'c_uint_size' => array('UINT:4', 4),
+ 'c_tint_size' => array('TINT:2', 4),
+ 'c_usint' => array('USINT', 4),
+ 'c_bool' => array('BOOL', 1),
+ 'c_vchar' => array('VCHAR', 'foo'),
+ 'c_vchar_size' => array('VCHAR:4', 'foo'),
+ 'c_char_size' => array('CHAR:4', 'foo'),
+ 'c_xstext' => array('XSTEXT', 'foo'),
+ 'c_stext' => array('STEXT', 'foo'),
+ 'c_text' => array('TEXT', 'foo'),
+ 'c_mtext' => array('MTEXT', 'foo'),
+ 'c_xstext_uni' => array('XSTEXT_UNI', 'foo'),
+ 'c_stext_uni' => array('STEXT_UNI', 'foo'),
+ 'c_text_uni' => array('TEXT_UNI', 'foo'),
+ 'c_mtext_uni' => array('MTEXT_UNI', 'foo'),
+ 'c_timestamp' => array('TIMESTAMP', 4),
+ 'c_decimal' => array('DECIMAL', 4.2),
+ 'c_decimal_size' => array('DECIMAL:6', 4.2),
+ 'c_pdecimal' => array('PDECIMAL', 4.2),
+ 'c_pdecimal_size' => array('PDECIMAL:7', 4.2),
+ 'c_vchar_uni' => array('VCHAR_UNI', 'foo'),
+ 'c_vchar_uni_size' => array('VCHAR_UNI:4', 'foo'),
+ 'c_vchar_ci' => array('VCHAR_CI', 'foo'),
+ 'c_varbinary' => array('VARBINARY', 'foo'),
+ ),
+ 'PRIMARY_KEY' => 'c_id',
+ 'KEYS' => array(
+ 'i_simple' => array('INDEX', 'c_uint'),
+ 'i_uniq' => array('UNIQUE', 'c_vchar'),
+ 'i_comp' => array('INDEX', array('c_vchar_uni', 'c_bool')),
+ 'i_comp_uniq' => array('UNIQUE', array('c_vchar_size', 'c_usint')),
+ ),
+ );
+ $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();
+ }
+
+ public function test_created_and_drop_table()
+ {
+ // table is empty after creation and queryable
+ $sql = 'SELECT * FROM prefix_table_name';
+ $result = $this->db->sql_query($sql);
+ $this->assertTrue(! $this->db->sql_fetchrow($result));
+ $this->db->sql_freeresult($result);
+
+ $this->table_exists = false;
+ $this->tools->sql_table_drop('prefix_table_name');
+ }
+
+ static protected function get_default_values()
+ {
+ return array(
+ 'c_int_size' => 0,
+ 'c_bint' => 0,
+ 'c_uint' => 0,
+ 'c_uint_size' => 0,
+ 'c_tint_size' => 0,
+ 'c_usint' => 0,
+ 'c_bool' => 0,
+ 'c_vchar' => '',
+ 'c_vchar_size' => '',
+ 'c_char_size' => '',
+ 'c_xstext' => '',
+ 'c_stext' => '',
+ 'c_text' => '',
+ 'c_mtext' => '',
+ 'c_xstext_uni' => '',
+ 'c_stext_uni' => '',
+ 'c_text_uni' => '',
+ 'c_mtext_uni' => '',
+ 'c_timestamp' => 0,
+ 'c_decimal' => 0,
+ 'c_decimal_size' => 0,
+ 'c_pdecimal' => 0,
+ 'c_pdecimal_size' => 0,
+ 'c_vchar_uni' => '',
+ 'c_vchar_uni_size' => '',
+ 'c_vchar_ci' => '',
+ 'c_varbinary' => '',
+ );
+ }
+
+ static public function column_values()
+ {
+ return array(
+ array('c_int_size', -9999),
+ array('c_bint', '99999999999999999'),
+ array('c_uint', 16777215),
+ array('c_uint_size', 9999),
+ array('c_tint_size', -99),
+ array('c_usint', 99),
+ array('c_bool', 0),
+ array('c_vchar', str_repeat('a', 255)),
+ array('c_vchar_size', str_repeat('a', 4)),
+ array('c_char_size', str_repeat('a', 4)),
+ array('c_xstext', str_repeat('a', 1000)),
+ array('c_stext', str_repeat('a', 3000)),
+ array('c_text', str_repeat('a', 8000)),
+ array('c_mtext', str_repeat('a', 10000)),
+ array('c_xstext_uni', str_repeat("\xC3\x84", 100)),
+ array('c_stext_uni', str_repeat("\xC3\x84", 255)),
+ array('c_text_uni', str_repeat("\xC3\x84", 4000)),
+ array('c_mtext_uni', str_repeat("\xC3\x84", 10000)),
+ array('c_timestamp', 2147483647),
+ array('c_decimal', 999.99),
+ array('c_decimal_size', 9999.99),
+ array('c_pdecimal', 999.999),
+ array('c_pdecimal_size', 9999.999),
+ array('c_vchar_uni', str_repeat("\xC3\x84", 255)),
+ array('c_vchar_uni_size', str_repeat("\xC3\x84", 4)),
+ array('c_vchar_ci', str_repeat("\xC3\x84", 255)),
+ array('c_varbinary', str_repeat("\x00\xFF", 127)),
+ );
+ }
+
+ /**
+ * @dataProvider column_values
+ */
+ public function test_created_column($column_name, $column_value)
+ {
+ $row_insert = self::get_default_values();
+ $row_insert[$column_name] = $column_value;
+
+ // empty table
+ $sql = 'DELETE FROM prefix_table_name';
+ $result = $this->db->sql_query($sql);
+
+ $sql = 'INSERT INTO prefix_table_name ' . $this->db->sql_build_array('INSERT', $row_insert);
+ $result = $this->db->sql_query($sql);
+
+ $sql = "SELECT *
+ FROM prefix_table_name";
+ $result = $this->db->sql_query($sql);
+ $row_actual = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ $row_expect = $row_insert;
+
+ unset($row_actual['id']); // auto increment id changes, so ignore
+
+ $type = $this->table_data['COLUMNS'][$column_name][0];
+ $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_column_exists()
+ {
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_id'));
+ $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'column_does_not_exist'));
+ }
+
+ public function test_column_remove()
+ {
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_int_size'));
+
+ $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_int_size'));
+
+ $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_int_size'));
+ }
+
+ public function test_column_remove_primary()
+ {
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_id'));
+
+ $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_id'));
+
+ $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_id'));
+ }
+
+ public function test_table_exists()
+ {
+ $this->assertTrue($this->tools->sql_table_exists('prefix_table_name'));
+ $this->assertFalse($this->tools->sql_table_exists('prefix_does_not_exist'));
+ }
+
+ public function test_table_drop()
+ {
+ $this->tools->sql_create_table('prefix_test_table',
+ array('COLUMNS' => array(
+ 'foo' => array('UINT', 42)))
+ );
+
+ $this->tools->sql_table_drop('prefix_test_table');
+ }
+}
diff --git a/tests/dbal/select.php b/tests/dbal/select_test.php
index 70f27549d2..e0d08d9306 100644
--- a/tests/dbal/select.php
+++ b/tests/dbal/select_test.php
@@ -7,8 +7,8 @@
*
*/
-require_once 'test_framework/framework.php';
-require_once '../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
class phpbb_dbal_select_test extends phpbb_database_test_case
{
@@ -318,4 +318,27 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
$db->sql_freeresult($result);
}
+
+ function test_nested_transactions()
+ {
+ $db = $this->new_dbal();
+
+ // nested transactions should work on systems that do not require
+ // buffering of nested transactions, so ignore the ones that need
+ // buffering
+ if ($db->sql_buffer_nested_transactions())
+ {
+ return;
+ }
+
+ $sql = 'SELECT user_id FROM phpbb_users ORDER BY user_id ASC';
+ $result1 = $db->sql_query($sql);
+
+ $db->sql_transaction('begin');
+ $result2 = $db->sql_query($sql);
+ $row = $db->sql_fetchrow($result2);
+ $db->sql_transaction('commit');
+
+ $this->assertEquals('1', $row['user_id']);
+ }
}
diff --git a/tests/dbal/write.php b/tests/dbal/write_test.php
index 01deacda69..4709d45fa5 100644
--- a/tests/dbal/write.php
+++ b/tests/dbal/write_test.php
@@ -7,8 +7,7 @@
*
*/
-require_once 'test_framework/framework.php';
-require_once '../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_dbal_write_test extends phpbb_database_test_case
{