From bc5f8e30d09be1ded463b7d7a0e0d9b001de6b3b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 23 Mar 2013 13:20:32 +0100 Subject: [PATCH 01/16] [ticket/11405] Add some basic tests for notifications in submit_post() Poster, should NOT receive a notification Topic subscribed, should receive a notification Topic subscribed, but unauthed to read, should NOT receive a notification Topic subscribed, but already notified, should NOT receive a new notification Topic and forum subscribed, should receive ONE notification Forum subscribed, should receive a notification Forum subscribed, but already notified, should NOT receive a new notification PHPBB3-11405 --- .../fixtures/submit_post_notification.xml | 132 ++++++++++++ .../submit_post_notifications_test.php | 195 ++++++++++++++++++ 2 files changed, 327 insertions(+) create mode 100644 tests/notification/fixtures/submit_post_notification.xml create mode 100644 tests/notification/submit_post_notifications_test.php diff --git a/tests/notification/fixtures/submit_post_notification.xml b/tests/notification/fixtures/submit_post_notification.xml new file mode 100644 index 0000000000..c082402056 --- /dev/null +++ b/tests/notification/fixtures/submit_post_notification.xml @@ -0,0 +1,132 @@ + + + + forum_id + user_id + notify_status + + 1 + 6 + 0 + + + 1 + 7 + 0 + + + 1 + 8 + 0 + +
+ + item_type + user_id + item_id + item_parent_id + notification_data + + post + 5 + 1 + 1 + + + + post + 8 + 1 + 1 + + +
+ +
+ + topic_id + user_id + notify_status + + 1 + 2 + 0 + + + 1 + 3 + 0 + + + 1 + 4 + 0 + + + 1 + 5 + 0 + + + 1 + 6 + 0 + +
+ + item_type + item_id + user_id + method + notify + + post + 0 + 2 + + 1 + + + post + 0 + 3 + + 1 + + + post + 0 + 4 + + 1 + + + post + 0 + 5 + + 1 + + + post + 0 + 6 + + 1 + + + post + 0 + 7 + + 1 + + + post + 0 + 8 + + 1 + +
+
diff --git a/tests/notification/submit_post_notifications_test.php b/tests/notification/submit_post_notifications_test.php new file mode 100644 index 0000000000..e08d7a439a --- /dev/null +++ b/tests/notification/submit_post_notifications_test.php @@ -0,0 +1,195 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); + } + + public function setUp() + { + parent::setUp(); + + global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; + + // Database + $this->db = $this->new_dbal(); + $db = $this->db; + + // Cache + $cache = new phpbb_mock_cache(); + + // Auth + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap(array( + array('f_noapprove', 1, true), + array('f_postcount', 1, true), + array('m_edit', 1, false), + ))); + + $auth->expects($this->any()) + ->method('acl_get_list') + ->with($this->anything(), + $this->stringContains('_'), + $this->greaterThan(0)) + ->will($this->returnValueMap(array( + array( + array( + 0 => '3', + 1 => '4', + 2 => '5', + 3 => '6', + 5 => '7', + 6 => '8', + ), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 5, 6, 7, 8,), + ), + ), + ), + array( + array( + 0 => '3', + 1 => '4', + 2 => '5', + 3 => '6', + ), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 5, 6,), + ), + ), + ), + ))); + + // Config + $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); + set_config(null, null, null, $config); + set_config_count(null, null, null, $config); + + // Event dispatcher + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + + // User + $user = $this->getMock('phpbb_user'); + $user->ip = ''; + $user->data = array( + 'user_id' => 2, + 'username' => 'user-name', + 'is_registered' => true, + 'user_colour' => '', + ); + + // Request + $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); + $request = $this->getMock('phpbb_request'); + + // Container + $phpbb_container = new phpbb_mock_container_builder(); + + $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); + + // Notification Manager + $phpbb_notifications = new phpbb_notification_manager(array(), array(), + $phpbb_container, $user_loader, $db, $user, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); + $phpbb_container->set('notification_manager', $phpbb_notifications); + + // Notification Types + $notification_types = array('quote', 'bookmark', 'post'); + foreach ($notification_types as $type) + { + $class_name = 'phpbb_notification_type_' . $type; + $phpbb_container->set('notification.type.' . $type, new $class_name( + $user_loader, $db, $cache, $user, $auth, $config, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); + } + } + + /** + * submit_post() Notifications test + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => Topic subscribed, should receive a notification + * 4 => Topic subscribed, but unauthed to read, should NOT receive a notification + * 5 => Topic subscribed, but already notified, should NOT receive a new notification + * 6 => Topic and forum subscribed, should receive ONE notification + * 7 => Forum subscribed, should receive a notification + * 8 => Forum subscribed, but already notified, should NOT receive a new notification + */ + public function test_type_post() + { + $sql = 'SELECT user_id, item_id, item_parent_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = 'post' + ORDER BY user_id, item_id ASC"; + $result = $this->db->sql_query($sql); + $this->assertEquals(array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), + ), $this->db->sql_fetchrowset($result)); + $this->db->sql_freeresult($result); + + $poll = array(); + $data = array( + 'forum_id' => 1, + 'topic_id' => 1, + 'topic_title' => 'topic_title', + 'icon_id' => 0, + 'enable_bbcode' => 0, + 'enable_smilies' => 0, + 'enable_urls' => 0, + 'enable_sig' => 0, + 'message' => '', + 'message_md5' => '', + 'attachment_data' => array(), + 'bbcode_bitfield' => '', + 'bbcode_uid' => '', + 'post_edit_locked' => false, + //'force_approved_state' => 1, + ); + + submit_post('reply', '', 'poster-name', POST_NORMAL, $poll, $data, false, false); + + $sql = 'SELECT user_id, item_id, item_parent_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = 'post' + ORDER BY user_id ASC, item_id ASC"; + $result = $this->db->sql_query($sql); + $this->assertEquals(array( + array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1,), + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1,), + array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1,), + array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1,), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1,), + ), $this->db->sql_fetchrowset($result)); + $this->db->sql_freeresult($result); + } +} From a91ffe06c79dd067162fe3d659be44382a20df0e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 23 Mar 2013 13:25:01 +0100 Subject: [PATCH 02/16] [ticket/11405] Send post notifications to forum subscribers Like in 3.0 we should also send notifications about new posts to users that subscribed to the forum. (Subscriptions are verbose) PHPBB3-11405 --- phpBB/includes/notification/type/post.php | 15 ++++++++++++ .../submit_post_notifications_test.php | 24 +------------------ 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index d8ffdea81d..626c13b7fd 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -106,11 +106,26 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } $this->db->sql_freeresult($result); + $sql = 'SELECT user_id + FROM ' . FORUMS_WATCH_TABLE . ' + WHERE forum_id = ' . (int) $post['forum_id'] . ' + AND notify_status = ' . NOTIFY_YES . ' + AND user_id <> ' . (int) $post['poster_id']; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $users[] = $row['user_id']; + } + $this->db->sql_freeresult($result); + if (empty($users)) { return array(); } + $users = array_unique($users); + sort($users); + $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); if (empty($auth_read)) diff --git a/tests/notification/submit_post_notifications_test.php b/tests/notification/submit_post_notifications_test.php index e08d7a439a..3dfb948ca9 100644 --- a/tests/notification/submit_post_notifications_test.php +++ b/tests/notification/submit_post_notifications_test.php @@ -53,14 +53,7 @@ class phpbb_notification_submit_post_notifications_test extends phpbb_database_t $this->greaterThan(0)) ->will($this->returnValueMap(array( array( - array( - 0 => '3', - 1 => '4', - 2 => '5', - 3 => '6', - 5 => '7', - 6 => '8', - ), + array('3', '4', '5', '6', '7', '8',), 'f_read', 1, array( @@ -69,21 +62,6 @@ class phpbb_notification_submit_post_notifications_test extends phpbb_database_t ), ), ), - array( - array( - 0 => '3', - 1 => '4', - 2 => '5', - 3 => '6', - ), - 'f_read', - 1, - array( - 1 => array( - 'f_read' => array(3, 5, 6,), - ), - ), - ), ))); // Config From 7d5949ae3d2faba5dc76c3d355e73b5abaa8e6c1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Mar 2013 14:37:22 +0100 Subject: [PATCH 03/16] [ticket/11405] Fix some coding style issues PHPBB3-11405 --- .../submit_post_notifications_test.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/notification/submit_post_notifications_test.php b/tests/notification/submit_post_notifications_test.php index 3dfb948ca9..6b61624481 100644 --- a/tests/notification/submit_post_notifications_test.php +++ b/tests/notification/submit_post_notifications_test.php @@ -53,12 +53,12 @@ class phpbb_notification_submit_post_notifications_test extends phpbb_database_t $this->greaterThan(0)) ->will($this->returnValueMap(array( array( - array('3', '4', '5', '6', '7', '8',), + array('3', '4', '5', '6', '7', '8'), 'f_read', 1, array( 1 => array( - 'f_read' => array(3, 5, 6, 7, 8,), + 'f_read' => array(3, 5, 6, 7, 8), ), ), ), @@ -113,6 +113,9 @@ class phpbb_notification_submit_post_notifications_test extends phpbb_database_t /** * submit_post() Notifications test * + * submit_post() $mode = 'reply' + * Notification item_type = 'post' + * * User => State description * 2 => Poster, should NOT receive a notification * 3 => Topic subscribed, should receive a notification @@ -162,11 +165,11 @@ class phpbb_notification_submit_post_notifications_test extends phpbb_database_t ORDER BY user_id ASC, item_id ASC"; $result = $this->db->sql_query($sql); $this->assertEquals(array( - array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1,), - array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1,), - array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1,), - array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1,), - array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1,), + array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), ), $this->db->sql_fetchrowset($result)); $this->db->sql_freeresult($result); } From 499eded88004f0bbae554090939b38e6158c8271 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Mar 2013 14:40:53 +0100 Subject: [PATCH 04/16] [ticket/11405] Add unit tests for quoted users notifications PHPBB3-11405 --- .../fixtures/submit_post_notification.xml | 98 ++++++++++ ...est.php => submit_post_type_post_test.php} | 2 +- .../submit_post_type_quote_test.php | 180 ++++++++++++++++++ 3 files changed, 279 insertions(+), 1 deletion(-) rename tests/notification/{submit_post_notifications_test.php => submit_post_type_post_test.php} (98%) create mode 100644 tests/notification/submit_post_type_quote_test.php diff --git a/tests/notification/fixtures/submit_post_notification.xml b/tests/notification/fixtures/submit_post_notification.xml index c082402056..5c59edf073 100644 --- a/tests/notification/fixtures/submit_post_notification.xml +++ b/tests/notification/fixtures/submit_post_notification.xml @@ -33,6 +33,13 @@ 1 + + quote + 5 + 1 + 1 + + post 8 @@ -73,6 +80,62 @@ 0 + + user_id + username_clean + user_permissions + user_sig + user_occ + user_interests + + 2 + poster + + + + + + + 3 + test + + + + + + + 4 + unauthorized + + + + + + + 5 + notified + + + + + + + 6 + disabled + + + + + + + 7 + default + + + + + +
item_typeitem_id @@ -86,6 +149,13 @@ 1 + + quote + 0 + 2 + + 1 + post 0 @@ -93,6 +163,13 @@ 1 + + quote + 0 + 3 + + 1 + post 0 @@ -100,6 +177,13 @@ 1 + + quote + 0 + 4 + + 1 + post 0 @@ -107,6 +191,13 @@ 1 + + quote + 0 + 5 + + 1 + post 0 @@ -114,6 +205,13 @@ 1 + + quote + 0 + 6 + + 0 + post 0 diff --git a/tests/notification/submit_post_notifications_test.php b/tests/notification/submit_post_type_post_test.php similarity index 98% rename from tests/notification/submit_post_notifications_test.php rename to tests/notification/submit_post_type_post_test.php index 6b61624481..b1e4b86b15 100644 --- a/tests/notification/submit_post_notifications_test.php +++ b/tests/notification/submit_post_type_post_test.php @@ -12,7 +12,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; -class phpbb_notification_submit_post_notifications_test extends phpbb_database_test_case +class phpbb_notification_submit_post_type_post_test extends phpbb_database_test_case { protected $notifications, $db, $container, $user, $config, $auth, $cache; diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php new file mode 100644 index 0000000000..82f4eaf189 --- /dev/null +++ b/tests/notification/submit_post_type_quote_test.php @@ -0,0 +1,180 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); + } + + public function setUp() + { + parent::setUp(); + + global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; + + // Database + $this->db = $this->new_dbal(); + $db = $this->db; + + // Cache + $cache = new phpbb_mock_cache(); + + // Auth + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap(array( + array('f_noapprove', 1, true), + array('f_postcount', 1, true), + array('m_edit', 1, false), + ))); + + $auth->expects($this->any()) + ->method('acl_get_list') + ->with($this->anything(), + $this->stringContains('_'), + $this->greaterThan(0)) + ->will($this->returnValueMap(array( + array( + array('3', '4', '5', '6', '7'), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 5, 6, 7), + ), + ), + ), + ))); + + // Config + $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); + set_config(null, null, null, $config); + set_config_count(null, null, null, $config); + + // Event dispatcher + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + + // User + $user = $this->getMock('phpbb_user'); + $user->ip = ''; + $user->data = array( + 'user_id' => 2, + 'username' => 'user-name', + 'is_registered' => true, + 'user_colour' => '', + ); + + // Request + $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); + $request = $this->getMock('phpbb_request'); + + // Container + $phpbb_container = new phpbb_mock_container_builder(); + + $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); + + // Notification Manager + $phpbb_notifications = new phpbb_notification_manager(array(), array(), + $phpbb_container, $user_loader, $db, $user, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); + $phpbb_container->set('notification_manager', $phpbb_notifications); + + // Notification Types + $notification_types = array('quote', 'bookmark', 'post'); + foreach ($notification_types as $type) + { + $class_name = 'phpbb_notification_type_' . $type; + $phpbb_container->set('notification.type.' . $type, new $class_name( + $user_loader, $db, $cache, $user, $auth, $config, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); + } + } + + /** + * submit_post() Notifications test + * + * submit_post() $mode = 'reply' + * Notification item_type = 'quote' + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => Quoted, should receive a notification + * 4 => Quoted, but unauthed to read, should NOT receive a notification + * 5 => Quoted, but already notified, should NOT receive a new notification + * 6 => Quoted, but option disabled, should NOT receive a notification + * 7 => Quoted, option set to default, should receive a notification + */ + public function test_type_quote() + { + $sql = 'SELECT user_id, item_id, item_parent_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = 'quote' + ORDER BY user_id, item_id ASC"; + $result = $this->db->sql_query($sql); + $this->assertEquals(array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + ), $this->db->sql_fetchrowset($result)); + $this->db->sql_freeresult($result); + + $poll = array(); + $data = array( + 'forum_id' => 1, + 'topic_id' => 1, + 'topic_title' => 'topic_title', + 'icon_id' => 0, + 'enable_bbcode' => 0, + 'enable_smilies' => 0, + 'enable_urls' => 0, + 'enable_sig' => 0, + 'message' => implode(' ', array( + '[quote="poster":uid]poster should not be notified[/quote:uid]', + '[quote="test":uid]test should be notified[/quote:uid]', + '[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]', + '[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]', + '[quote="disabled":uid]option disabled, should not receive a notification[/quote:uid]', + '[quote="default":uid]option set to default, should receive a notification[/quote:uid]', + '[quote="doesn\'t exist":uid]user does not exist, should not receive a notification[/quote:uid]', + )), + 'message_md5' => '', + 'attachment_data' => array(), + 'bbcode_bitfield' => '', + 'bbcode_uid' => 'uid', + 'post_edit_locked' => false, + //'force_approved_state' => 1, + ); + + submit_post('reply', '', 'poster-name', POST_NORMAL, $poll, $data, false, false); + + $sql = 'SELECT user_id, item_id, item_parent_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = 'quote' + ORDER BY user_id ASC, item_id ASC"; + $result = $this->db->sql_query($sql); + $this->assertEquals(array( + array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1), + ), $this->db->sql_fetchrowset($result)); + $this->db->sql_freeresult($result); + } +} From 1259117d213d9364ec7eaeb637f9a3fd8838e816 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Mar 2013 14:41:31 +0100 Subject: [PATCH 05/16] [ticket/11405] Sort $users array in order to prevent issues on postgres PHPBB3-11405 --- phpBB/includes/notification/type/quote.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 5453b267c8..e9eb7bea21 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -108,6 +108,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post { return array(); } + sort($users); $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); From 060876e627db127c72a953d37e83f5176a085e5d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Mar 2013 15:16:29 +0100 Subject: [PATCH 06/16] [ticket/11405] Add a base class to avoid duplicated setUp() code PHPBB3-11405 --- tests/notification/submit_post_base.php | 94 +++++++++++++++++++ .../submit_post_type_post_test.php | 81 +--------------- .../submit_post_type_quote_test.php | 81 +--------------- 3 files changed, 102 insertions(+), 154 deletions(-) create mode 100644 tests/notification/submit_post_base.php diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php new file mode 100644 index 0000000000..60d0e798cb --- /dev/null +++ b/tests/notification/submit_post_base.php @@ -0,0 +1,94 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); + } + + public function setUp() + { + parent::setUp(); + + global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; + + // Database + $this->db = $this->new_dbal(); + $db = $this->db; + + // Cache + $cache = new phpbb_mock_cache(); + + // Auth + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap(array( + array('f_noapprove', 1, true), + array('f_postcount', 1, true), + array('m_edit', 1, false), + ))); + + // Config + $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); + set_config(null, null, null, $config); + set_config_count(null, null, null, $config); + + // Event dispatcher + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + + // User + $user = $this->getMock('phpbb_user'); + $user->ip = ''; + $user->data = array( + 'user_id' => 2, + 'username' => 'user-name', + 'is_registered' => true, + 'user_colour' => '', + ); + + // Request + $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); + $request = $this->getMock('phpbb_request'); + + // Container + $phpbb_container = new phpbb_mock_container_builder(); + + $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); + + // Notification Manager + $phpbb_notifications = new phpbb_notification_manager(array(), array(), + $phpbb_container, $user_loader, $db, $user, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); + $phpbb_container->set('notification_manager', $phpbb_notifications); + + // Notification Types + $notification_types = array('quote', 'bookmark', 'post'); + foreach ($notification_types as $type) + { + $class_name = 'phpbb_notification_type_' . $type; + $phpbb_container->set('notification.type.' . $type, new $class_name( + $user_loader, $db, $cache, $user, $auth, $config, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); + } + } +} diff --git a/tests/notification/submit_post_type_post_test.php b/tests/notification/submit_post_type_post_test.php index b1e4b86b15..2e269ff080 100644 --- a/tests/notification/submit_post_type_post_test.php +++ b/tests/notification/submit_post_type_post_test.php @@ -7,45 +7,17 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; +require_once dirname(__FILE__) . '/submit_post_base.php'; -class phpbb_notification_submit_post_type_post_test extends phpbb_database_test_case +class phpbb_notification_submit_post_type_post_test extends phpbb_notification_submit_post_base { - protected $notifications, $db, $container, $user, $config, $auth, $cache; - - public function getDataSet() - { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); - } - public function setUp() { parent::setUp(); - global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; - - // Database - $this->db = $this->new_dbal(); - $db = $this->db; - - // Cache - $cache = new phpbb_mock_cache(); - - // Auth - $auth = $this->getMock('phpbb_auth'); - $auth->expects($this->any()) - ->method('acl_get') - ->with($this->stringContains('_'), - $this->anything()) - ->will($this->returnValueMap(array( - array('f_noapprove', 1, true), - array('f_postcount', 1, true), - array('m_edit', 1, false), - ))); + global $auth; + // Add additional permissions $auth->expects($this->any()) ->method('acl_get_list') ->with($this->anything(), @@ -63,51 +35,6 @@ class phpbb_notification_submit_post_type_post_test extends phpbb_database_test_ ), ), ))); - - // Config - $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); - set_config(null, null, null, $config); - set_config_count(null, null, null, $config); - - // Event dispatcher - $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - - // User - $user = $this->getMock('phpbb_user'); - $user->ip = ''; - $user->data = array( - 'user_id' => 2, - 'username' => 'user-name', - 'is_registered' => true, - 'user_colour' => '', - ); - - // Request - $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); - $request = $this->getMock('phpbb_request'); - - // Container - $phpbb_container = new phpbb_mock_container_builder(); - - $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); - - // Notification Manager - $phpbb_notifications = new phpbb_notification_manager(array(), array(), - $phpbb_container, $user_loader, $db, $user, - $phpbb_root_path, '.' . $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); - $phpbb_container->set('notification_manager', $phpbb_notifications); - - // Notification Types - $notification_types = array('quote', 'bookmark', 'post'); - foreach ($notification_types as $type) - { - $class_name = 'phpbb_notification_type_' . $type; - $phpbb_container->set('notification.type.' . $type, new $class_name( - $user_loader, $db, $cache, $user, $auth, $config, - $phpbb_root_path, '.' . $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); - } } /** diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php index 82f4eaf189..603f7b2020 100644 --- a/tests/notification/submit_post_type_quote_test.php +++ b/tests/notification/submit_post_type_quote_test.php @@ -7,45 +7,17 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; +require_once dirname(__FILE__) . '/submit_post_base.php'; -class phpbb_notification_submit_post_type_quote_test extends phpbb_database_test_case +class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_submit_post_base { - protected $notifications, $db, $container, $user, $config, $auth, $cache; - - public function getDataSet() - { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); - } - public function setUp() { parent::setUp(); - global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; - - // Database - $this->db = $this->new_dbal(); - $db = $this->db; - - // Cache - $cache = new phpbb_mock_cache(); - - // Auth - $auth = $this->getMock('phpbb_auth'); - $auth->expects($this->any()) - ->method('acl_get') - ->with($this->stringContains('_'), - $this->anything()) - ->will($this->returnValueMap(array( - array('f_noapprove', 1, true), - array('f_postcount', 1, true), - array('m_edit', 1, false), - ))); + global $auth; + // Add additional permissions $auth->expects($this->any()) ->method('acl_get_list') ->with($this->anything(), @@ -63,51 +35,6 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_database_test ), ), ))); - - // Config - $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); - set_config(null, null, null, $config); - set_config_count(null, null, null, $config); - - // Event dispatcher - $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - - // User - $user = $this->getMock('phpbb_user'); - $user->ip = ''; - $user->data = array( - 'user_id' => 2, - 'username' => 'user-name', - 'is_registered' => true, - 'user_colour' => '', - ); - - // Request - $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); - $request = $this->getMock('phpbb_request'); - - // Container - $phpbb_container = new phpbb_mock_container_builder(); - - $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); - - // Notification Manager - $phpbb_notifications = new phpbb_notification_manager(array(), array(), - $phpbb_container, $user_loader, $db, $user, - $phpbb_root_path, '.' . $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); - $phpbb_container->set('notification_manager', $phpbb_notifications); - - // Notification Types - $notification_types = array('quote', 'bookmark', 'post'); - foreach ($notification_types as $type) - { - $class_name = 'phpbb_notification_type_' . $type; - $phpbb_container->set('notification.type.' . $type, new $class_name( - $user_loader, $db, $cache, $user, $auth, $config, - $phpbb_root_path, '.' . $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); - } } /** From 053c75543de4c8e5d787a2e344b837f867842f8d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Mar 2013 15:34:18 +0100 Subject: [PATCH 07/16] [ticket/11405] Correctly prefill the tables (missed the posts and not-types) PHPBB3-11405 --- .../fixtures/submit_post_notification.xml | 34 +++++++++++++++++++ .../submit_post_type_post_test.php | 6 ++-- .../submit_post_type_quote_test.php | 4 +-- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/tests/notification/fixtures/submit_post_notification.xml b/tests/notification/fixtures/submit_post_notification.xml index 5c59edf073..51dd2f8dbd 100644 --- a/tests/notification/fixtures/submit_post_notification.xml +++ b/tests/notification/fixtures/submit_post_notification.xml @@ -25,12 +25,14 @@ user_id item_id item_parent_id + notification_read notification_data post 5 1 1 + 0 @@ -38,6 +40,7 @@ 5 1 1 + 0 @@ -45,10 +48,41 @@ 8 1 1 + 0
+ + notification_type + notification_type_enabled + + post + 1 + + + quote + 1 + +
+ post_id + topic_id + forum_id + post_text + + 1 + 1 + 1 + + +
+ + topic_id + forum_id + + 1 + 1 +
topic_id diff --git a/tests/notification/submit_post_type_post_test.php b/tests/notification/submit_post_type_post_test.php index 2e269ff080..f439c49167 100644 --- a/tests/notification/submit_post_type_post_test.php +++ b/tests/notification/submit_post_type_post_test.php @@ -92,10 +92,10 @@ class phpbb_notification_submit_post_type_post_test extends phpbb_notification_s ORDER BY user_id ASC, item_id ASC"; $result = $this->db->sql_query($sql); $this->assertEquals(array( - array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 6, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), ), $this->db->sql_fetchrowset($result)); $this->db->sql_freeresult($result); diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php index 603f7b2020..9b2323f770 100644 --- a/tests/notification/submit_post_type_quote_test.php +++ b/tests/notification/submit_post_type_quote_test.php @@ -98,9 +98,9 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_ ORDER BY user_id ASC, item_id ASC"; $result = $this->db->sql_query($sql); $this->assertEquals(array( - array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), ), $this->db->sql_fetchrowset($result)); $this->db->sql_freeresult($result); } From cdd45cb8ba4d420bfc44a9bb7a4c43662ec78156 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Mar 2013 12:58:14 +0100 Subject: [PATCH 08/16] [ticket/11405] Move test to submit_post_base.php and use data sets for testing PHPBB3-11405 --- tests/notification/submit_post_base.php | 47 ++++++- .../submit_post_type_post_test.php | 99 +++++++-------- .../submit_post_type_quote_test.php | 120 +++++++++--------- 3 files changed, 155 insertions(+), 111 deletions(-) diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index 60d0e798cb..f458a4896a 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -16,6 +16,27 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case { protected $notifications, $db, $container, $user, $config, $auth, $cache; + protected $item_type = ''; + + protected $poll_data = array(); + protected $post_data = array( + 'forum_id' => 1, + 'topic_id' => 1, + 'topic_title' => 'topic_title', + 'icon_id' => 0, + 'enable_bbcode' => 0, + 'enable_smilies' => 0, + 'enable_urls' => 0, + 'enable_sig' => 0, + 'message' => '', + 'message_md5' => '', + 'attachment_data' => array(), + 'bbcode_bitfield' => '', + 'bbcode_uid' => '', + 'post_edit_locked' => false, + //'force_approved_state' => 1, + ); + public function getDataSet() { return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); @@ -81,7 +102,7 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case $phpbb_container->set('notification_manager', $phpbb_notifications); // Notification Types - $notification_types = array('quote', 'bookmark', 'post'); + $notification_types = array('quote', 'bookmark', 'post', 'post_in_queue'); foreach ($notification_types as $type) { $class_name = 'phpbb_notification_type_' . $type; @@ -91,4 +112,28 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); } } + + /** + * @dataProvider submit_post_data + */ + public function test_submit_post($additional_post_data, $expected_before, $expected_after) + { + $sql = 'SELECT user_id, item_id, item_parent_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->item_type . "' + ORDER BY user_id, item_id ASC"; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_before, $this->db->sql_fetchrowset($result)); + $this->db->sql_freeresult($result); + + submit_post('reply', '', 'poster-name', POST_NORMAL, $this->poll_data, array_merge($this->post_data, $additional_post_data), false, false); + + $sql = 'SELECT user_id, item_id, item_parent_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->item_type . "' + ORDER BY user_id ASC, item_id ASC"; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_after, $this->db->sql_fetchrowset($result)); + $this->db->sql_freeresult($result); + } } diff --git a/tests/notification/submit_post_type_post_test.php b/tests/notification/submit_post_type_post_test.php index f439c49167..473247a764 100644 --- a/tests/notification/submit_post_type_post_test.php +++ b/tests/notification/submit_post_type_post_test.php @@ -11,6 +11,8 @@ require_once dirname(__FILE__) . '/submit_post_base.php'; class phpbb_notification_submit_post_type_post_test extends phpbb_notification_submit_post_base { + protected $item_type = 'post'; + public function setUp() { parent::setUp(); @@ -42,62 +44,53 @@ class phpbb_notification_submit_post_type_post_test extends phpbb_notification_s * * submit_post() $mode = 'reply' * Notification item_type = 'post' - * - * User => State description - * 2 => Poster, should NOT receive a notification - * 3 => Topic subscribed, should receive a notification - * 4 => Topic subscribed, but unauthed to read, should NOT receive a notification - * 5 => Topic subscribed, but already notified, should NOT receive a new notification - * 6 => Topic and forum subscribed, should receive ONE notification - * 7 => Forum subscribed, should receive a notification - * 8 => Forum subscribed, but already notified, should NOT receive a new notification */ - public function test_type_post() + public function submit_post_data() { - $sql = 'SELECT user_id, item_id, item_parent_id - FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = 'post' - ORDER BY user_id, item_id ASC"; - $result = $this->db->sql_query($sql); - $this->assertEquals(array( - array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), - ), $this->db->sql_fetchrowset($result)); - $this->db->sql_freeresult($result); + return array( + /** + * Normal post + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => Topic subscribed, should receive a notification + * 4 => Topic subscribed, but unauthed to read, should NOT receive a notification + * 5 => Topic subscribed, but already notified, should NOT receive a new notification + * 6 => Topic and forum subscribed, should receive ONE notification + * 7 => Forum subscribed, should receive a notification + * 8 => Forum subscribed, but already notified, should NOT receive a new notification + */ + array( + array(), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 6, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), + ), + ), - $poll = array(); - $data = array( - 'forum_id' => 1, - 'topic_id' => 1, - 'topic_title' => 'topic_title', - 'icon_id' => 0, - 'enable_bbcode' => 0, - 'enable_smilies' => 0, - 'enable_urls' => 0, - 'enable_sig' => 0, - 'message' => '', - 'message_md5' => '', - 'attachment_data' => array(), - 'bbcode_bitfield' => '', - 'bbcode_uid' => '', - 'post_edit_locked' => false, - //'force_approved_state' => 1, + /** + * Unapproved post + * + * No new notifications + */ + array( + array('force_approved_state' => false), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), + ), + ), ); - - submit_post('reply', '', 'poster-name', POST_NORMAL, $poll, $data, false, false); - - $sql = 'SELECT user_id, item_id, item_parent_id - FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = 'post' - ORDER BY user_id ASC, item_id ASC"; - $result = $this->db->sql_query($sql); - $this->assertEquals(array( - array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), - array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 6, 'item_id' => 2, 'item_parent_id' => 1), - array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), - array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), - ), $this->db->sql_fetchrowset($result)); - $this->db->sql_freeresult($result); } } diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php index 9b2323f770..2b66d9c6a1 100644 --- a/tests/notification/submit_post_type_quote_test.php +++ b/tests/notification/submit_post_type_quote_test.php @@ -11,6 +11,8 @@ require_once dirname(__FILE__) . '/submit_post_base.php'; class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_submit_post_base { + protected $item_type = 'quote'; + public function setUp() { parent::setUp(); @@ -42,66 +44,70 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_ * * submit_post() $mode = 'reply' * Notification item_type = 'quote' - * - * User => State description - * 2 => Poster, should NOT receive a notification - * 3 => Quoted, should receive a notification - * 4 => Quoted, but unauthed to read, should NOT receive a notification - * 5 => Quoted, but already notified, should NOT receive a new notification - * 6 => Quoted, but option disabled, should NOT receive a notification - * 7 => Quoted, option set to default, should receive a notification */ - public function test_type_quote() + public function submit_post_data() { - $sql = 'SELECT user_id, item_id, item_parent_id - FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = 'quote' - ORDER BY user_id, item_id ASC"; - $result = $this->db->sql_query($sql); - $this->assertEquals(array( - array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), - ), $this->db->sql_fetchrowset($result)); - $this->db->sql_freeresult($result); + return array( + /** + * Normal post + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => Quoted, should receive a notification + * 4 => Quoted, but unauthed to read, should NOT receive a notification + * 5 => Quoted, but already notified, should NOT receive a new notification + * 6 => Quoted, but option disabled, should NOT receive a notification + * 7 => Quoted, option set to default, should receive a notification + */ + array( + array( + 'message' => implode(' ', array( + '[quote="poster":uid]poster should not be notified[/quote:uid]', + '[quote="test":uid]test should be notified[/quote:uid]', + '[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]', + '[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]', + '[quote="disabled":uid]option disabled, should not receive a notification[/quote:uid]', + '[quote="default":uid]option set to default, should receive a notification[/quote:uid]', + '[quote="doesn\'t exist":uid]user does not exist, should not receive a notification[/quote:uid]', + )), + 'bbcode_uid' => 'uid', + ), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), + ), + ), - $poll = array(); - $data = array( - 'forum_id' => 1, - 'topic_id' => 1, - 'topic_title' => 'topic_title', - 'icon_id' => 0, - 'enable_bbcode' => 0, - 'enable_smilies' => 0, - 'enable_urls' => 0, - 'enable_sig' => 0, - 'message' => implode(' ', array( - '[quote="poster":uid]poster should not be notified[/quote:uid]', - '[quote="test":uid]test should be notified[/quote:uid]', - '[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]', - '[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]', - '[quote="disabled":uid]option disabled, should not receive a notification[/quote:uid]', - '[quote="default":uid]option set to default, should receive a notification[/quote:uid]', - '[quote="doesn\'t exist":uid]user does not exist, should not receive a notification[/quote:uid]', - )), - 'message_md5' => '', - 'attachment_data' => array(), - 'bbcode_bitfield' => '', - 'bbcode_uid' => 'uid', - 'post_edit_locked' => false, - //'force_approved_state' => 1, + /** + * Unapproved post + * + * No new notifications + */ + array( + array( + 'message' => implode(' ', array( + '[quote="poster":uid]poster should not be notified[/quote:uid]', + '[quote="test":uid]test should be notified[/quote:uid]', + '[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]', + '[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]', + '[quote="disabled":uid]option disabled, should not receive a notification[/quote:uid]', + '[quote="default":uid]option set to default, should receive a notification[/quote:uid]', + '[quote="doesn\'t exist":uid]user does not exist, should not receive a notification[/quote:uid]', + )), + 'bbcode_uid' => 'uid', + 'force_approved_state' => false, + ), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + ), + ), ); - - submit_post('reply', '', 'poster-name', POST_NORMAL, $poll, $data, false, false); - - $sql = 'SELECT user_id, item_id, item_parent_id - FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = 'quote' - ORDER BY user_id ASC, item_id ASC"; - $result = $this->db->sql_query($sql); - $this->assertEquals(array( - array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), - array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), - ), $this->db->sql_fetchrowset($result)); - $this->db->sql_freeresult($result); } } From 7e2f80ec0ab69c512383602c42b84db1c767180e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Mar 2013 12:59:35 +0100 Subject: [PATCH 09/16] [ticket/11405] Add unit tests for bookmarking PHPBB3-11405 --- .../fixtures/submit_post_notification.xml | 75 ++++++++++++++++ .../submit_post_type_bookmark_test.php | 90 +++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 tests/notification/submit_post_type_bookmark_test.php diff --git a/tests/notification/fixtures/submit_post_notification.xml b/tests/notification/fixtures/submit_post_notification.xml index 51dd2f8dbd..3f46bc2962 100644 --- a/tests/notification/fixtures/submit_post_notification.xml +++ b/tests/notification/fixtures/submit_post_notification.xml @@ -1,5 +1,33 @@ +
+ topic_id + user_id + + 1 + 2 + + + 1 + 3 + + + 1 + 4 + + + 1 + 5 + + + 1 + 6 + + + 1 + 7 + +
forum_iduser_id @@ -43,6 +71,14 @@ 0 + + bookmark + 5 + 1 + 1 + 0 + + post 8 @@ -63,6 +99,10 @@ quote 1 + + bookmark + 1 +
post_id @@ -190,6 +230,13 @@ 1 + + bookmark + 0 + 2 + + 1 + post 0 @@ -204,6 +251,13 @@ 1 + + bookmark + 0 + 3 + + 1 + post 0 @@ -218,6 +272,13 @@ 1 + + bookmark + 0 + 4 + + 1 + post 0 @@ -232,6 +293,13 @@ 1 + + bookmark + 0 + 5 + + 1 + post 0 @@ -246,6 +314,13 @@ 0 + + bookmark + 0 + 6 + + 0 + post 0 diff --git a/tests/notification/submit_post_type_bookmark_test.php b/tests/notification/submit_post_type_bookmark_test.php new file mode 100644 index 0000000000..861017ff5f --- /dev/null +++ b/tests/notification/submit_post_type_bookmark_test.php @@ -0,0 +1,90 @@ +expects($this->any()) + ->method('acl_get_list') + ->with($this->anything(), + $this->stringContains('_'), + $this->greaterThan(0)) + ->will($this->returnValueMap(array( + array( + array('3', '4', '5', '6', '7'), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 5, 6, 7), + ), + ), + ), + ))); + } + + /** + * submit_post() Notifications test + * + * submit_post() $mode = 'reply' + * Notification item_type = 'bookmark' + */ + public function submit_post_data() + { + return array( + /** + * Normal post + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => Bookmarked, should receive a notification + * 4 => Bookmarked, but unauthed to read, should NOT receive a notification + * 5 => Bookmarked, but already notified, should NOT receive a new notification + * 6 => Bookmarked, but option disabled, should NOT receive a notification + * 7 => Bookmarked, option set to default, should receive a notification + */ + array( + array(), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), + ), + ), + + /** + * Unapproved post + * + * No new notifications + */ + array( + array('force_approved_state' => false), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + ), + ), + ); + } +} From e20b0a423474eb6f4dce362283ae2ebb3d3e0f8d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Mar 2013 13:06:04 +0100 Subject: [PATCH 10/16] [ticket/11405] Use different fixtures so it's not a total mess PHPBB3-11405 --- .../fixtures/submit_post_bookmark.xml | 173 ++++++++++++++++++ ..._notification.xml => submit_post_post.xml} | 122 ------------ .../fixtures/submit_post_quote.xml | 145 +++++++++++++++ tests/notification/submit_post_base.php | 2 +- 4 files changed, 319 insertions(+), 123 deletions(-) create mode 100644 tests/notification/fixtures/submit_post_bookmark.xml rename tests/notification/fixtures/{submit_post_notification.xml => submit_post_post.xml} (66%) create mode 100644 tests/notification/fixtures/submit_post_quote.xml diff --git a/tests/notification/fixtures/submit_post_bookmark.xml b/tests/notification/fixtures/submit_post_bookmark.xml new file mode 100644 index 0000000000..b669d4c1b6 --- /dev/null +++ b/tests/notification/fixtures/submit_post_bookmark.xml @@ -0,0 +1,173 @@ + + +
+ topic_id + user_id + + 1 + 2 + + + 1 + 3 + + + 1 + 4 + + + 1 + 5 + + + 1 + 6 + + + 1 + 7 + +
+ + item_type + user_id + item_id + item_parent_id + notification_read + notification_data + + bookmark + 5 + 1 + 1 + 0 + + +
+ + notification_type + notification_type_enabled + + bookmark + 1 + +
+ + post_id + topic_id + forum_id + post_text + + 1 + 1 + 1 + + +
+ + topic_id + forum_id + + 1 + 1 + +
+ + user_id + username_clean + user_permissions + user_sig + user_occ + user_interests + + 2 + poster + + + + + + + 3 + test + + + + + + + 4 + unauthorized + + + + + + + 5 + notified + + + + + + + 6 + disabled + + + + + + + 7 + default + + + + + +
+ + item_type + item_id + user_id + method + notify + + bookmark + 0 + 2 + + 1 + + + bookmark + 0 + 3 + + 1 + + + bookmark + 0 + 4 + + 1 + + + bookmark + 0 + 5 + + 1 + + + bookmark + 0 + 6 + + 0 + +
+ diff --git a/tests/notification/fixtures/submit_post_notification.xml b/tests/notification/fixtures/submit_post_post.xml similarity index 66% rename from tests/notification/fixtures/submit_post_notification.xml rename to tests/notification/fixtures/submit_post_post.xml index 3f46bc2962..cead4f7c26 100644 --- a/tests/notification/fixtures/submit_post_notification.xml +++ b/tests/notification/fixtures/submit_post_post.xml @@ -1,33 +1,5 @@ - - topic_id - user_id - - 1 - 2 - - - 1 - 3 - - - 1 - 4 - - - 1 - 5 - - - 1 - 6 - - - 1 - 7 - -
forum_iduser_id @@ -63,22 +35,6 @@ 0 - - quote - 5 - 1 - 1 - 0 - - - - bookmark - 5 - 1 - 1 - 0 - - post 8 @@ -95,14 +51,6 @@ post 1 - - quote - 1 - - - bookmark - 1 -
post_id @@ -223,20 +171,6 @@ 1 - - quote - 0 - 2 - - 1 - - - bookmark - 0 - 2 - - 1 - post 0 @@ -244,20 +178,6 @@ 1 - - quote - 0 - 3 - - 1 - - - bookmark - 0 - 3 - - 1 - post 0 @@ -265,20 +185,6 @@ 1 - - quote - 0 - 4 - - 1 - - - bookmark - 0 - 4 - - 1 - post 0 @@ -286,20 +192,6 @@ 1 - - quote - 0 - 5 - - 1 - - - bookmark - 0 - 5 - - 1 - post 0 @@ -307,20 +199,6 @@ 1 - - quote - 0 - 6 - - 0 - - - bookmark - 0 - 6 - - 0 - post 0 diff --git a/tests/notification/fixtures/submit_post_quote.xml b/tests/notification/fixtures/submit_post_quote.xml new file mode 100644 index 0000000000..884a84af4a --- /dev/null +++ b/tests/notification/fixtures/submit_post_quote.xml @@ -0,0 +1,145 @@ + + +
+ item_type + user_id + item_id + item_parent_id + notification_read + notification_data + + quote + 5 + 1 + 1 + 0 + + +
+ + notification_type + notification_type_enabled + + quote + 1 + +
+ + post_id + topic_id + forum_id + post_text + + 1 + 1 + 1 + + +
+ + topic_id + forum_id + + 1 + 1 + +
+ + user_id + username_clean + user_permissions + user_sig + user_occ + user_interests + + 2 + poster + + + + + + + 3 + test + + + + + + + 4 + unauthorized + + + + + + + 5 + notified + + + + + + + 6 + disabled + + + + + + + 7 + default + + + + + +
+ + item_type + item_id + user_id + method + notify + + quote + 0 + 2 + + 1 + + + quote + 0 + 3 + + 1 + + + quote + 0 + 4 + + 1 + + + quote + 0 + 5 + + 1 + + + quote + 0 + 6 + + 0 + +
+
diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index f458a4896a..d306e3f381 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -39,7 +39,7 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_' . $this->item_type . '.xml'); } public function setUp() From 81cf02e057080dda384716022b6cc4c9cc1ff461 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Mar 2013 13:34:20 +0100 Subject: [PATCH 11/16] [ticket/11405] Order users in bookmark, in order to pass postgres tests PHPBB3-11405 --- phpBB/includes/notification/type/bookmark.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 4e48a967d0..946cb9b4ed 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -89,6 +89,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post { return array(); } + sort($users); $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); From 0f204595d9b69c29716e8cf0ccf5033e66f5294f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Mar 2013 14:09:35 +0100 Subject: [PATCH 12/16] [ticket/11405] Fix "only variables should be passed by reference" PHPBB3-11405 --- tests/notification/submit_post_base.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index d306e3f381..c5b2450e1c 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -126,7 +126,9 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case $this->assertEquals($expected_before, $this->db->sql_fetchrowset($result)); $this->db->sql_freeresult($result); - submit_post('reply', '', 'poster-name', POST_NORMAL, $this->poll_data, array_merge($this->post_data, $additional_post_data), false, false); + $poll_data = $this->poll_data; + $post_data = array_merge($this->post_data, $additional_post_data); + submit_post('reply', '', 'poster-name', POST_NORMAL, $poll_data, $post_data, false, false); $sql = 'SELECT user_id, item_id, item_parent_id FROM ' . NOTIFICATIONS_TABLE . " From 8a94e08e3009fece3f9de2d28c8f873dc4471b52 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Mar 2013 13:33:32 +0100 Subject: [PATCH 13/16] [ticket/11405] Add unit tests for post_in_queue PHPBB3-11405 --- .../fixtures/submit_post_post_in_queue.xml | 160 ++++++++++++++++++ .../submit_post_type_post_in_queue_test.php | 102 +++++++++++ 2 files changed, 262 insertions(+) create mode 100644 tests/notification/fixtures/submit_post_post_in_queue.xml create mode 100644 tests/notification/submit_post_type_post_in_queue_test.php diff --git a/tests/notification/fixtures/submit_post_post_in_queue.xml b/tests/notification/fixtures/submit_post_post_in_queue.xml new file mode 100644 index 0000000000..4162d01d7f --- /dev/null +++ b/tests/notification/fixtures/submit_post_post_in_queue.xml @@ -0,0 +1,160 @@ + + + + item_type + user_id + item_id + item_parent_id + notification_read + notification_data + + post_in_queue + 6 + 1 + 1 + 0 + + +
+ + notification_type + notification_type_enabled + + post_in_queue + 1 + +
+ + post_id + topic_id + forum_id + post_text + + 1 + 1 + 1 + + +
+ + topic_id + forum_id + + 1 + 1 + +
+ + user_id + username_clean + user_permissions + user_sig + user_occ + user_interests + + 2 + poster + + + + + + + 3 + test + + + + + + + 4 + unauthorized-mod + + + + + + + 5 + unauthorized-read + + + + + + + 6 + notified + + + + + + + 7 + disabled + + + + + + + 8 + default + + + + + +
+ + item_type + item_id + user_id + method + notify + + needs_approval + 0 + 2 + + 1 + + + needs_approval + 0 + 3 + + 1 + + + needs_approval + 0 + 4 + + 1 + + + needs_approval + 0 + 5 + + 1 + + + needs_approval + 0 + 6 + + 1 + + + needs_approval + 0 + 7 + + 0 + +
+
diff --git a/tests/notification/submit_post_type_post_in_queue_test.php b/tests/notification/submit_post_type_post_in_queue_test.php new file mode 100644 index 0000000000..375ee3fbef --- /dev/null +++ b/tests/notification/submit_post_type_post_in_queue_test.php @@ -0,0 +1,102 @@ +expects($this->any()) + ->method('acl_get_list') + ->with($this->anything(), + $this->stringContains('_'), + $this->greaterThan(0)) + ->will($this->returnValueMap(array( + array( + false, + 'm_approve', + array(1, 0), + array( + 1 => array( + 'm_approve' => array(3, 4, 6, 7, 8), + ), + ), + ), + array( + array(3, 4, 6, 7, 8), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 6, 7, 8), + ), + ), + ), + ))); + } + + /** + * submit_post() Notifications test + * + * submit_post() $mode = 'reply' + * Notification item_type = 'post_in_queue' + */ + public function submit_post_data() + { + return array( + /** + * Normal post + * + * No new notifications + */ + array( + array(), + array( + array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), + ), + ), + + /** + * Unapproved post + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => Moderator, should receive a notification + * 4 => Moderator, but unauthed to read, should NOT receive a notification + * 5 => Moderator, but unauthed to approve, should NOT receive a notification + * 6 => Moderator, but already notified, should STILL receive a new notification + * 7 => Moderator, but option disabled, should NOT receive a notification + * 8 => Moderator, option set to default, should receive a notification + */ + array( + array('force_approved_state' => false), + array( + array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 6, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 2, 'item_parent_id' => 1), + ), + ), + ); + } +} From 1af89968dda7270de73d21bfb5285f25ddee9963 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Mar 2013 20:14:40 +0100 Subject: [PATCH 14/16] [ticket/11474] Check read permission before sending *_in_queue notifications PHPBB3-11405 PHPBB3-11474 --- phpBB/includes/notification/type/post_in_queue.php | 9 ++++++++- phpBB/includes/notification/type/topic_in_queue.php | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 9c719205e6..a167dc2faf 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -101,8 +101,15 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post { $has_permission = array_unique(array_merge($has_permission, $auth_approve[0][$this->permission])); } + sort($has_permission); - return $this->check_user_notification_options($has_permission, array_merge($options, array( + $auth_read = $this->auth->acl_get_list($has_permission, 'f_read', $post['forum_id']); + if (empty($auth_read)) + { + return array(); + } + + return $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], array_merge($options, array( 'item_type' => self::$notification_option['id'], ))); } diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index c501434c43..4fe4325118 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -101,8 +101,15 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top { $has_permission = array_unique(array_merge($has_permission, $auth_approve[0][$this->permission])); } + sort($has_permission); - return $this->check_user_notification_options($has_permission, array_merge($options, array( + $auth_read = $this->auth->acl_get_list($has_permission, 'f_read', $topic['forum_id']); + if (empty($auth_read)) + { + return array(); + } + + return $this->check_user_notification_options($auth_read[$topic['forum_id']]['f_read'], array_merge($options, array( 'item_type' => self::$notification_option['id'], ))); } From d8a63047aaef2d8839baf32bbb8df724e1e46b02 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Mar 2013 20:16:07 +0100 Subject: [PATCH 15/16] [ticket/11474] Clarify comment with "global" and forum_id = 0 Forum ID 0 in permission checks, checks the global moderator permission. PHPBB3-11405 PHPBB3-11474 --- phpBB/includes/notification/type/post_in_queue.php | 2 +- phpBB/includes/notification/type/topic_in_queue.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index a167dc2faf..bc4b15cdc3 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -82,7 +82,7 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post 'ignore_users' => array(), ), $options); - // 0 is for global + // 0 is for global moderator permissions $auth_approve = $this->auth->acl_get_list(false, $this->permission, array($post['forum_id'], 0)); if (empty($auth_approve)) diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 4fe4325118..f735e10c00 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -82,7 +82,7 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top 'ignore_users' => array(), ), $options); - // 0 is for global + // 0 is for global moderator permissions $auth_approve = $this->auth->acl_get_list(false, 'm_approve', array($topic['forum_id'], 0)); if (empty($auth_approve)) From bdd2062a667fdf9acde75946c7a9d5d84e84b092 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Mar 2013 11:12:33 +0100 Subject: [PATCH 16/16] [ticket/11474] Add test user with only global m_approve permissions PHPBB3-11405 PHPBB3-11474 --- .../fixtures/submit_post_post_in_queue.xml | 15 +++++++++++++++ .../submit_post_type_post_in_queue_test.php | 9 +++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/notification/fixtures/submit_post_post_in_queue.xml b/tests/notification/fixtures/submit_post_post_in_queue.xml index 4162d01d7f..eedcebf71d 100644 --- a/tests/notification/fixtures/submit_post_post_in_queue.xml +++ b/tests/notification/fixtures/submit_post_post_in_queue.xml @@ -107,6 +107,14 @@ + + 9 + test glboal-permissions + + + + + item_type @@ -156,5 +164,12 @@ 0 + + needs_approval + 0 + 9 + + 1 +
diff --git a/tests/notification/submit_post_type_post_in_queue_test.php b/tests/notification/submit_post_type_post_in_queue_test.php index 375ee3fbef..6a7ac44e39 100644 --- a/tests/notification/submit_post_type_post_in_queue_test.php +++ b/tests/notification/submit_post_type_post_in_queue_test.php @@ -31,18 +31,21 @@ class phpbb_notification_submit_post_type_post_in_queue_test extends phpbb_notif 'm_approve', array(1, 0), array( + 0 => array( + 'm_approve' => array(9), + ), 1 => array( 'm_approve' => array(3, 4, 6, 7, 8), ), ), ), array( - array(3, 4, 6, 7, 8), + array(3, 4, 6, 7, 8, 9), 'f_read', 1, array( 1 => array( - 'f_read' => array(3, 6, 7, 8), + 'f_read' => array(3, 6, 7, 8, 9), ), ), ), @@ -84,6 +87,7 @@ class phpbb_notification_submit_post_type_post_in_queue_test extends phpbb_notif * 6 => Moderator, but already notified, should STILL receive a new notification * 7 => Moderator, but option disabled, should NOT receive a notification * 8 => Moderator, option set to default, should receive a notification + * 9 => Moderator, has only global mod permissions, should receive a notification */ array( array('force_approved_state' => false), @@ -95,6 +99,7 @@ class phpbb_notification_submit_post_type_post_in_queue_test extends phpbb_notif array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), array('user_id' => 6, 'item_id' => 2, 'item_parent_id' => 1), array('user_id' => 8, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 9, 'item_id' => 2, 'item_parent_id' => 1), ), ), );