From 2f2feaa4e8ad9a18fd9ddcb7d65ae958c544dbcb Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 30 Apr 2013 21:38:40 -0500 Subject: [PATCH] [ticket/11413] Don't use the database for the convert test Different databases seem to work slightly differently here and are causing errors PHPBB3-11413 --- .../db/migration/data/310/notifications2.php | 11 +++++- tests/notification/convert_test.php | 37 ++++++++----------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/phpBB/includes/db/migration/data/310/notifications2.php b/phpBB/includes/db/migration/data/310/notifications2.php index 44b3f8fd49..c90944dcc9 100644 --- a/phpBB/includes/db/migration/data/310/notifications2.php +++ b/phpBB/includes/db/migration/data/310/notifications2.php @@ -100,7 +100,16 @@ class phpbb_db_migration_data_310_notifications2 extends phpbb_db_migration public function convert_notifications() { $insert_table = $this->table_prefix . 'user_notifications'; + $insert_buffer = new phpbb_db_sql_insert_buffer($this->db, $insert_table); + $this->perform_conversion($insert_buffer, $insert_table); + } + + /** + * Perform the conversion (separate for testability) + */ + public function perform_conversion($insert_buffer, $insert_table) + { $sql = 'DELETE FROM ' . $insert_table; $this->db->sql_query($sql); @@ -108,7 +117,6 @@ class phpbb_db_migration_data_310_notifications2 extends phpbb_db_migration FROM ' . USERS_TABLE; $result = $this->db->sql_query($sql); - $insert_buffer = new phpbb_db_sql_insert_buffer($this->db, $insert_table); while ($row = $this->db->sql_fetchrow($result)) { $notification_methods = array(); @@ -162,6 +170,7 @@ class phpbb_db_migration_data_310_notifications2 extends phpbb_db_migration 'item_type' => $item_type, 'item_id' => (int) $item_id, 'user_id' => (int) $user_id, + 'notify' => 1 ); foreach ($methods as $method) diff --git a/tests/notification/convert_test.php b/tests/notification/convert_test.php index 9fa7fc6a42..529b2935e1 100644 --- a/tests/notification/convert_test.php +++ b/tests/notification/convert_test.php @@ -38,38 +38,33 @@ class phpbb_notification_convert_test extends phpbb_database_test_case public function test_convert() { - $this->migration->convert_notifications(); + $buffer = new phpbb_mock_sql_insert_buffer($this->db, 'phpbb_user_notifications'); + $this->migration->perform_conversion($buffer, 'phpbb_user_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('pm', 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('pm', 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') + $this->create_expected('topic', 6, 'both'), + $this->create_expected('pm', 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); + $this->assertEquals($expected, $buffer->get_buffer()); } protected function create_expected($type, $user_id, $method = '') @@ -80,10 +75,10 @@ class phpbb_notification_convert_test extends phpbb_database_test_case { $return[] = array( 'item_type' => $type, - 'item_id' => '0', - 'user_id' => (string) $user_id, + 'item_id' => 0, + 'user_id' => $user_id, 'method' => '', - 'notify' => '1', + 'notify' => 1, ); } @@ -91,10 +86,10 @@ class phpbb_notification_convert_test extends phpbb_database_test_case { $return[] = array( 'item_type' => $type, - 'item_id' => '0', - 'user_id' => (string) $user_id, + 'item_id' => 0, + 'user_id' => $user_id, 'method' => 'email', - 'notify' => '1', + 'notify' => 1, ); } @@ -102,10 +97,10 @@ class phpbb_notification_convert_test extends phpbb_database_test_case { $return[] = array( 'item_type' => $type, - 'item_id' => '0', - 'user_id' => (string) $user_id, + 'item_id' => 0, + 'user_id' => $user_id, 'method' => 'jabber', - 'notify' => '1', + 'notify' => 1, ); }