aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dbal/auto_increment_test.php
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2012-05-10 23:22:35 -0400
committerOleg Pudeyev <oleg@bsdpower.com>2012-05-10 23:50:42 -0400
commit1019226dfa359cb223d68e7b9132006a8cd2a859 (patch)
tree0e14eb68300afbce63ce520153af93e7f86bff6f /tests/dbal/auto_increment_test.php
parent4b3d80729332adbdac5060a1b561615cc35274ac (diff)
downloadforums-1019226dfa359cb223d68e7b9132006a8cd2a859.tar
forums-1019226dfa359cb223d68e7b9132006a8cd2a859.tar.gz
forums-1019226dfa359cb223d68e7b9132006a8cd2a859.tar.bz2
forums-1019226dfa359cb223d68e7b9132006a8cd2a859.tar.xz
forums-1019226dfa359cb223d68e7b9132006a8cd2a859.zip
[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
Diffstat (limited to 'tests/dbal/auto_increment_test.php')
-rw-r--r--tests/dbal/auto_increment_test.php100
1 files changed, 100 insertions, 0 deletions
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 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';
+
+class phpbb_dbal_auto_increment_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_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);
+ }
+}