From 18f24a2270610d18b06a1ba2b6012beffe676603 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 25 Oct 2014 14:50:01 -0700 Subject: [PATCH 1/3] [ticket/13207] Add default subscription options for newly registered users PHPBB3-13207 --- phpBB/includes/functions_user.php | 13 ++++++++++++- phpBB/includes/ucp/ucp_register.php | 13 ++++++++++++- tests/functional/registration_test.php | 16 ++++++++++++++-- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index e4479f07b0..82a02eeb4b 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -161,9 +161,10 @@ function user_update_name($old_name, $new_name) * * @param mixed $user_row An array containing the following keys (and the appropriate values): username, group_id (the group to place the user in), user_email and the user_type(usually 0). Additional entries not overridden by defaults will be forwarded. * @param string $cp_data custom profile fields, see custom_profile::build_insert_sql_array + * @param array $notifications_data The notifications settings for the new user * @return the new user's ID. */ -function user_add($user_row, $cp_data = false) +function user_add($user_row, $cp_data = false, $notifications_data = array()) { global $db, $user, $auth, $config, $phpbb_root_path, $phpEx; global $phpbb_dispatcher, $phpbb_container; @@ -347,6 +348,16 @@ function user_add($user_row, $cp_data = false) set_config('newest_user_colour', $row['group_colour'], true); } + // Subscribe user to notifications if necessary + if (!empty($notifications_data)) + { + $phpbb_notifications = $phpbb_container->get('notification_manager'); + foreach ($notifications_data as $subscription) + { + $phpbb_notifications->add_subscription($subscription['item_type'], 0, $subscription['method'], $user_id); + } + } + /** * Event that returns user id, user detals and user CPF of newly registared user * diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php index 9a15967bae..3289273658 100644 --- a/phpBB/includes/ucp/ucp_register.php +++ b/phpBB/includes/ucp/ucp_register.php @@ -314,13 +314,24 @@ class ucp_register 'user_inactive_time' => $user_inactive_time, ); + $user_notifications_data = array( + array( + 'item_type' => 'notification.type.post', + 'method' => 'notification.method.email', + ), + array( + 'item_type' => 'notification.type.topic', + 'method' => 'notification.method.email', + ), + ); + if ($config['new_member_post_limit']) { $user_row['user_new'] = 1; } // Register user... - $user_id = user_add($user_row, $cp_data); + $user_id = user_add($user_row, $cp_data, $user_notifications_data); // This should not happen, because the required variables are listed above... if ($user_id === false) diff --git a/tests/functional/registration_test.php b/tests/functional/registration_test.php index 45a684db19..26473c4fcd 100644 --- a/tests/functional/registration_test.php +++ b/tests/functional/registration_test.php @@ -45,12 +45,24 @@ class phpbb_functional_registration_test extends phpbb_functional_test_case $form = $crawler->selectButton('Submit')->form(array( 'username' => 'user-reg-test', 'email' => 'user-reg-test@phpbb.com', - 'new_password' => 'testtest', - 'password_confirm' => 'testtest', + 'new_password' => 'user-reg-testuser-reg-test', + 'password_confirm' => 'user-reg-testuser-reg-test', )); $form['tz']->select('Europe/Berlin'); $crawler = self::submit($form); $this->assertContainsLang('ACCOUNT_ADDED', $crawler->filter('#message')->text()); } + + /** + * @depends test_register_new_account + */ + public function test_default_subscription_options() + { + $this->login('user-reg-test'); + $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options&sid=' . $this->sid); + $form_values = $crawler->selectButton('Submit')->form()->getValues(); + $this->assertEquals(1, $form_values['notification.type.post_notification.method.email']); + $this->assertEquals(1, $form_values['notification.type.topic_notification.method.email']); + } } From 81ad381263436bc2a5ef1a18388e1ed5c48eac9d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 25 Oct 2014 14:56:04 -0700 Subject: [PATCH 2/3] [ticket/13207] Move default user notifications settings to user_add() PHPBB3-13207 --- phpBB/includes/functions_user.php | 19 +++++++++++++++++-- phpBB/includes/ucp/ucp_register.php | 13 +------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 82a02eeb4b..f79a8998c4 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -161,10 +161,10 @@ function user_update_name($old_name, $new_name) * * @param mixed $user_row An array containing the following keys (and the appropriate values): username, group_id (the group to place the user in), user_email and the user_type(usually 0). Additional entries not overridden by defaults will be forwarded. * @param string $cp_data custom profile fields, see custom_profile::build_insert_sql_array - * @param array $notifications_data The notifications settings for the new user +* @param array $notifications_data The notifications settings for the new user * @return the new user's ID. */ -function user_add($user_row, $cp_data = false, $notifications_data = array()) +function user_add($user_row, $cp_data = false, $notifications_data = null) { global $db, $user, $auth, $config, $phpbb_root_path, $phpEx; global $phpbb_dispatcher, $phpbb_container; @@ -348,6 +348,21 @@ function user_add($user_row, $cp_data = false, $notifications_data = array()) set_config('newest_user_colour', $row['group_colour'], true); } + // Use default notifications settings if notifications_data is not set + if ($notifications_data === null) + { + $notifications_data = array( + array( + 'item_type' => 'notification.type.post', + 'method' => 'notification.method.email', + ), + array( + 'item_type' => 'notification.type.topic', + 'method' => 'notification.method.email', + ), + ); + } + // Subscribe user to notifications if necessary if (!empty($notifications_data)) { diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php index 3289273658..9a15967bae 100644 --- a/phpBB/includes/ucp/ucp_register.php +++ b/phpBB/includes/ucp/ucp_register.php @@ -314,24 +314,13 @@ class ucp_register 'user_inactive_time' => $user_inactive_time, ); - $user_notifications_data = array( - array( - 'item_type' => 'notification.type.post', - 'method' => 'notification.method.email', - ), - array( - 'item_type' => 'notification.type.topic', - 'method' => 'notification.method.email', - ), - ); - if ($config['new_member_post_limit']) { $user_row['user_new'] = 1; } // Register user... - $user_id = user_add($user_row, $cp_data, $user_notifications_data); + $user_id = user_add($user_row, $cp_data); // This should not happen, because the required variables are listed above... if ($user_id === false) From 0dcb874c0987156b0c4bb2ef4e935ff6b6f2fd46 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 25 Oct 2014 16:16:25 -0700 Subject: [PATCH 3/3] [ticket/13207] Add notification manager mock to user_add method in tests PHPBB3-13207 --- tests/test_framework/phpbb_functional_test_case.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 49cc72363e..840ff981cb 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -556,12 +556,10 @@ class phpbb_functional_test_case extends phpbb_test_case $cache = new phpbb_mock_null_cache; $cache_driver = new \phpbb\cache\driver\null(); - $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); - $phpbb_container - ->expects($this->any()) - ->method('get') - ->with('cache.driver') - ->will($this->returnValue($cache_driver)); + $phpbb_container = new phpbb_mock_container_builder(); + $phpbb_container->set('cache.driver', $cache_driver); + $phpbb_notifications = new phpbb_mock_notification_manager(); + $phpbb_container->set('notification_manager', $phpbb_notifications); if (!function_exists('utf_clean_string')) {