From 9653276ebcd1a5c24302cb8d06f905f90e158e45 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 4 Oct 2013 12:10:27 -0500 Subject: [ticket/11881] Better split the timezone conversion into chunks; add test PHPBB3-11881 --- tests/dbal/convert_timezones.php | 94 +++++++++++++++++++++++++++++++ tests/dbal/fixtures/convert_timezones.xml | 80 ++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 tests/dbal/convert_timezones.php create mode 100644 tests/dbal/fixtures/convert_timezones.xml (limited to 'tests') diff --git a/tests/dbal/convert_timezones.php b/tests/dbal/convert_timezones.php new file mode 100644 index 0000000000..718b28b9ff --- /dev/null +++ b/tests/dbal/convert_timezones.php @@ -0,0 +1,94 @@ +db = $this->new_dbal(); + $db_tools = new \phpbb\db\tools($this->db); + + // user_dst doesn't exist anymore, must re-add it to test this + $db_tools->sql_column_add('phpbb_users', 'user_dst', array('BOOL', 1)); + + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/convert_timezones.xml'); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'users' => array( + 'user_dst', + ), + ), + ); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'users' => array( + 'user_dst' => array('BOOL', 0), + ), + ), + ); + } + + protected function setUp() + { + parent::setUp(); + + global $phpbb_root_path, $phpEx; + + $this->db = $this->new_dbal(); + + $this->migration = new \phpbb\db\migration\data\v310\timezone( + new \phpbb\config\config(array()), + $this->db, + new \phpbb\db\tools($this->db), + $phpbb_root_path, + $phpEx, + 'phpbb_' + ); + } + + protected $expected_results = array( + //user_id => user_timezone + 1 => 'Etc/GMT+12', + 2 => 'Etc/GMT+11', + 3 => 'Etc/GMT-3', + 4 => 'Etc/GMT-4', + 5 => 'America/St_Johns', + 6 => 'Australia/Eucla', + ); + + public function test_convert() + { + $this->migration->update_timezones(0); + + $sql = 'SELECT user_id, user_timezone + FROM phpbb_users + ORDER BY user_id ASC'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $this->assertEquals($this->expected_results[$row['user_id']], $row['user_timezone']); + } + $this->db->sql_freeresult($result); + + $db_tools = new \phpbb\db\tools($this->db); + + // Remove the user_dst field again + $db_tools->sql_column_remove('phpbb_users', 'user_dst'); + } +} diff --git a/tests/dbal/fixtures/convert_timezones.xml b/tests/dbal/fixtures/convert_timezones.xml new file mode 100644 index 0000000000..ce941d8b74 --- /dev/null +++ b/tests/dbal/fixtures/convert_timezones.xml @@ -0,0 +1,80 @@ + + + + user_id + username + username_clean + user_permissions + user_sig + user_occ + user_interests + user_timezone + user_dst + + 1 + 1 + 1 + + + + + -12 + 0 + + + 2 + 2 + 2 + + + + + -12 + 1 + + + 3 + 3 + 3 + + + + + 3 + 0 + + + 4 + 4 + 4 + + + + + 3 + 1 + + + 5 + 5 + 5 + + + + + -3.5 + 0 + + + 6 + 6 + 6 + + + + + 8.75 + 0 + +
+
-- cgit v1.2.1