From 00ea297b614a10ad045075cad6f69f2c431c2757 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 30 Apr 2013 20:54:01 -0500 Subject: [PATCH] [ticket/11413] Create test for notification conversion PHPBB3-11413 --- tests/notification/convert_test.php | 114 ++++++++++++++++++++++++ tests/notification/fixtures/convert.xml | 52 +++++++++++ 2 files changed, 166 insertions(+) create mode 100644 tests/notification/convert_test.php create mode 100644 tests/notification/fixtures/convert.xml diff --git a/tests/notification/convert_test.php b/tests/notification/convert_test.php new file mode 100644 index 0000000000..9fa7fc6a42 --- /dev/null +++ b/tests/notification/convert_test.php @@ -0,0 +1,114 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/convert.xml'); + } + + protected function setUp() + { + parent::setUp(); + + global $phpbb_root_path, $phpEx; + + $this->db = $this->new_dbal(); + + $this->migration = new phpbb_db_migration_data_310_notifications2( + new phpbb_config(array()), + $this->db, + new phpbb_db_tools($this->db), + $phpbb_root_path, + $phpEx, + 'phpbb_' + ); + } + + public function test_convert() + { + $this->migration->convert_notifications(); + + $expected = array_merge( + $this->create_expected('post', 1, 'email'), + $this->create_expected('topic', 1, 'email'), + + $this->create_expected('pm', 2, 'email'), + $this->create_expected('post', 2, 'email'), + $this->create_expected('topic', 2, 'email'), + + $this->create_expected('post', 3, 'jabber'), + $this->create_expected('topic', 3, 'jabber'), + + $this->create_expected('pm', 4, 'jabber'), + $this->create_expected('post', 4, 'jabber'), + $this->create_expected('topic', 4, 'jabber'), + + $this->create_expected('post', 5, 'both'), + $this->create_expected('topic', 5, 'both'), + + $this->create_expected('pm', 6, 'both'), + $this->create_expected('post', 6, 'both'), + $this->create_expected('topic', 6, 'both') + ); + + $sql = 'SELECT * FROM phpbb_user_notifications + ORDER BY user_id ASC, item_type ASC'; + $result = $this->db->sql_query($sql); + $rowset = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + $this->assertEquals($expected, $rowset); + } + + protected function create_expected($type, $user_id, $method = '') + { + $return = array(); + + if ($method != '') + { + $return[] = array( + 'item_type' => $type, + 'item_id' => '0', + 'user_id' => (string) $user_id, + 'method' => '', + 'notify' => '1', + ); + } + + if ($method == 'email' || $method == 'both') + { + $return[] = array( + 'item_type' => $type, + 'item_id' => '0', + 'user_id' => (string) $user_id, + 'method' => 'email', + 'notify' => '1', + ); + } + + if ($method == 'jabber' || $method == 'both') + { + $return[] = array( + 'item_type' => $type, + 'item_id' => '0', + 'user_id' => (string) $user_id, + 'method' => 'jabber', + 'notify' => '1', + ); + } + + return $return; + } +} diff --git a/tests/notification/fixtures/convert.xml b/tests/notification/fixtures/convert.xml new file mode 100644 index 0000000000..a244070a95 --- /dev/null +++ b/tests/notification/fixtures/convert.xml @@ -0,0 +1,52 @@ + + + + user_id + username + username_clean + user_notify_type + user_notify_pm + + 1 + 1 + 1 + 0 + 0 + + + 2 + 2 + 2 + 0 + 1 + + + 3 + 3 + 3 + 1 + 0 + + + 4 + 4 + 4 + 1 + 1 + + + 5 + 5 + 5 + 2 + 0 + + + 6 + 6 + 6 + 2 + 1 + +
+