From 02f54ef2196dda61b2b507dd2a09ac097672a551 Mon Sep 17 00:00:00 2001 From: rxu Date: Wed, 1 Jul 2020 21:12:35 +0700 Subject: [PATCH] [ticket/16544] Fix notifications tests PHPBB3-16544 --- tests/notification/base.php | 1 + .../fixtures/email_notification.type.post.xml | 54 ++++ .../submit_post_notification.type.forum.xml | 262 ++++++++++++++++++ .../submit_post_notification.type.post.xml | 54 ++++ .../notification_method_email_test.php | 58 +++- tests/notification/notification_test.php | 1 + .../submit_post_type_forum_test.php | 109 ++++++++ .../submit_post_type_post_test.php | 15 +- 8 files changed, 545 insertions(+), 9 deletions(-) create mode 100644 tests/notification/fixtures/submit_post_notification.type.forum.xml create mode 100644 tests/notification/submit_post_type_forum_test.php diff --git a/tests/notification/base.php b/tests/notification/base.php index 1cc5893ebd..1622d12363 100644 --- a/tests/notification/base.php +++ b/tests/notification/base.php @@ -32,6 +32,7 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case 'notification.type.bookmark', 'notification.type.disapprove_post', 'notification.type.disapprove_topic', + 'notification.type.forum', 'notification.type.pm', 'notification.type.post', 'notification.type.post_in_queue', diff --git a/tests/notification/fixtures/email_notification.type.post.xml b/tests/notification/fixtures/email_notification.type.post.xml index 8787f5bbe5..6d064141b7 100644 --- a/tests/notification/fixtures/email_notification.type.post.xml +++ b/tests/notification/fixtures/email_notification.type.post.xml @@ -56,6 +56,11 @@ notification.type.post 1 + + 2 + notification.type.forum + 1 + post_id @@ -213,5 +218,54 @@ notification.method.email1 + + notification.type.forum + 0 + 2 + notification.method.email + 1 + + + notification.type.forum + 0 + 3 + notification.method.email + 1 + + + notification.type.forum + 0 + 4 + notification.method.email + 1 + + + notification.type.forum + 0 + 5 + notification.method.email + 1 + + + notification.type.forum + 0 + 6 + notification.method.email + 1 + + + notification.type.forum + 0 + 7 + notification.method.email + 1 + + + notification.type.forum + 0 + 8 + notification.method.email + 1 +
diff --git a/tests/notification/fixtures/submit_post_notification.type.forum.xml b/tests/notification/fixtures/submit_post_notification.type.forum.xml new file mode 100644 index 0000000000..b8df34bedc --- /dev/null +++ b/tests/notification/fixtures/submit_post_notification.type.forum.xml @@ -0,0 +1,262 @@ + + + + forum_id + user_id + notify_status + + 1 + 2 + 0 + + + 1 + 3 + 0 + + + 1 + 4 + 0 + + + 1 + 5 + 0 + + + 1 + 6 + 0 + +
+ + notification_id + notification_type_id + user_id + item_id + item_parent_id + notification_read + notification_data + + 1 + 1 + 5 + 1 + 1 + 0 + + + + 2 + 1 + 8 + 1 + 1 + 0 + + +
+ + notification_type_id + notification_type_name + notification_type_enabled + + 1 + notification.type.forum + 1 + + + 2 + notification.type.post + 1 + +
+ + post_id + topic_id + forum_id + post_text + + 1 + 1 + 1 + + +
+ + topic_id + forum_id + + 1 + 1 + +
+ + topic_id + user_id + notify_status + + 1 + 6 + 0 + + + 1 + 7 + 0 + + + 1 + 8 + 0 + +
+ + user_id + username_clean + user_permissions + user_sig + + 2 + poster + + + + + 3 + test + + + + + 4 + unauthorized + + + + + 5 + notified + + + + + 6 + disabled + + + + + 7 + default + + + +
+ + item_type + item_id + user_id + method + notify + + notification.type.post + 0 + 2 + notification.method.board + 1 + + + notification.type.post + 0 + 3 + notification.method.board + 1 + + + notification.type.post + 0 + 4 + notification.method.board + 1 + + + notification.type.post + 0 + 5 + notification.method.board + 1 + + + notification.type.post + 0 + 6 + notification.method.board + 1 + + + notification.type.post + 0 + 7 + notification.method.board + 1 + + + notification.type.post + 0 + 8 + notification.method.board + 1 + + + notification.type.forum + 0 + 2 + notification.method.board + 1 + + + notification.type.forum + 0 + 3 + notification.method.board + 1 + + + notification.type.forum + 0 + 4 + notification.method.board + 1 + + + notification.type.forum + 0 + 5 + notification.method.board + 1 + + + notification.type.forum + 0 + 6 + notification.method.board + 1 + + + notification.type.forum + 0 + 7 + notification.method.board + 1 + + + notification.type.forum + 0 + 8 + notification.method.board + 1 + +
+
diff --git a/tests/notification/fixtures/submit_post_notification.type.post.xml b/tests/notification/fixtures/submit_post_notification.type.post.xml index 920b271525..75bfb03e89 100644 --- a/tests/notification/fixtures/submit_post_notification.type.post.xml +++ b/tests/notification/fixtures/submit_post_notification.type.post.xml @@ -56,6 +56,11 @@ notification.type.post 1 + + 2 + notification.type.forum + 1 + post_id @@ -204,5 +209,54 @@ notification.method.board1 + + notification.type.forum + 0 + 2 + notification.method.board + 1 + + + notification.type.forum + 0 + 3 + notification.method.board + 1 + + + notification.type.forum + 0 + 4 + notification.method.board + 1 + + + notification.type.forum + 0 + 5 + notification.method.board + 1 + + + notification.type.forum + 0 + 6 + notification.method.board + 1 + + + notification.type.forum + 0 + 7 + notification.method.board + 1 + + + notification.type.forum + 0 + 8 + notification.method.board + 1 +
diff --git a/tests/notification/notification_method_email_test.php b/tests/notification/notification_method_email_test.php index b4734c872d..cf84ddc795 100644 --- a/tests/notification/notification_method_email_test.php +++ b/tests/notification/notification_method_email_test.php @@ -157,7 +157,20 @@ class notification_method_email_test extends phpbb_tests_notification_base public function data_notification_email() { return [ + /** + * Normal post + * + * User => State description + * 2 => Topic id=1 and id=2 subscribed, should receive a new topics post notification + * 3 => Topic id=1 subscribed, should receive a new topic post notification + * 4 => Topic id=1 subscribed, should receive a new topic post notification + * 5 => Topic id=1 subscribed, post id=1 already notified, should receive a new topic post notification + * 6 => Topic id=1 and forum id=1 subscribed, should receive a new topic/forum post notification + * 7 => Forum id=1 subscribed, should NOT receive a new topic post but a forum post notification + * 8 => Forum id=1 subscribed, post id=1 already notified, should NOT receive a new topic post but a forum post notification + */ [ + 'notification.type.post', [ 'forum_id' => '1', 'post_id' => '2', @@ -169,11 +182,23 @@ class notification_method_email_test extends phpbb_tests_notification_base 4 => ['user_id' => '4'], 5 => ['user_id' => '5'], 6 => ['user_id' => '6'], + ], + ], + [ + 'notification.type.forum', + [ + 'forum_id' => '1', + 'post_id' => '3', + 'topic_id' => '1', + ], + [ + 6 => ['user_id' => '6'], 7 => ['user_id' => '7'], 8 => ['user_id' => '8'] ], ], [ + 'notification.type.post', [ 'forum_id' => '1', 'post_id' => '4', @@ -181,12 +206,33 @@ class notification_method_email_test extends phpbb_tests_notification_base ], [ 2 => ['user_id' => '2'], + ], + ], + [ + 'notification.type.forum', + [ + 'forum_id' => '1', + 'post_id' => '5', + 'topic_id' => '2', + ], + [ 6 => ['user_id' => '6'], 7 => ['user_id' => '7'], 8 => ['user_id' => '8'], ], ], [ + 'notification.type.post', + [ + 'forum_id' => '2', + 'post_id' => '6', + 'topic_id' => '3', + ], + [ + ], + ], + [ + 'notification.type.forum', [ 'forum_id' => '2', 'post_id' => '6', @@ -201,7 +247,7 @@ class notification_method_email_test extends phpbb_tests_notification_base /** * @dataProvider data_notification_email */ - public function test_notification_email($post_data, $expected_users) + public function test_notification_email($notification_type, $post_data, $expected_users) { $post_data = array_merge(['post_time' => 1349413322], $post_data); $notification_options = [ @@ -209,21 +255,21 @@ class notification_method_email_test extends phpbb_tests_notification_base 'item_parent_id' => $post_data['topic_id'], ]; - $notified_users = $this->notification_method_email->get_notified_users($this->notifications->get_notification_type_id('notification.type.post'), $notification_options); + $notified_users = $this->notification_method_email->get_notified_users($this->notifications->get_notification_type_id($notification_type), $notification_options); $this->assertEquals(0, count($notified_users), 'Assert no user has been notified yet'); - $this->notifications->add_notifications('notification.type.post', $post_data); + $this->notifications->add_notifications($notification_type, $post_data); - $notified_users = $this->notification_method_email->get_notified_users($this->notifications->get_notification_type_id('notification.type.post'), $notification_options); + $notified_users = $this->notification_method_email->get_notified_users($this->notifications->get_notification_type_id($notification_type), $notification_options); $this->assertEquals($expected_users, $notified_users, 'Assert that expected users have been notified'); $post_data['post_id']++; $notification_options['item_id'] = $post_data['post_id']; $post_data['post_time'] = 1349413323; - $this->notifications->add_notifications('notification.type.post', $post_data); + $this->notifications->add_notifications($notification_type, $post_data); - $notified_users2 = $this->notification_method_email->get_notified_users($this->notifications->get_notification_type_id('notification.type.post'), $notification_options); + $notified_users2 = $this->notification_method_email->get_notified_users($this->notifications->get_notification_type_id($notification_type), $notification_options); $this->assertEquals($expected_users, $notified_users2, 'Assert that expected users stay the same after replying to same topic'); } } diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index 6bbabfc602..24a9d2e686 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -72,6 +72,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base public function test_subscriptions() { $expected_subscriptions = array( + 'notification.type.forum' => array('notification.method.board'), 'notification.type.post' => array('notification.method.board'), 'notification.type.topic' => array('notification.method.board'), 'notification.type.quote' => array('notification.method.board'), diff --git a/tests/notification/submit_post_type_forum_test.php b/tests/notification/submit_post_type_forum_test.php new file mode 100644 index 0000000000..1635f65863 --- /dev/null +++ b/tests/notification/submit_post_type_forum_test.php @@ -0,0 +1,109 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/submit_post_base.php'; + +class phpbb_notification_submit_post_type_forum_test extends phpbb_notification_submit_post_base +{ + protected $item_type = 'notification.type.forum'; + + public function setUp(): void + { + parent::setUp(); + + global $auth; + + // Add additional permissions + $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), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 5, 6), + ), + ), + ), + array( + array(3, 4, 5, 6, 7, 8), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 5, 6, 7, 8), + ), + ), + ), + ))); + } + + /** + * submit_post() Notifications test + * + * submit_post() $mode = 'reply' + * Notification item_type = 'notification.type.forum' + */ + public function submit_post_data() + { + return array( + /** + * Normal post + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => Forum subscribed, should receive a notification + * 4 => Forum subscribed, but unauthed to read, should NOT receive a notification + * 5 => Forum subscribed, but already notified, should NOT receive a new notification + * 6 => Topic and forum subscribed, should receive ONE notification + * 7 => Topic subscribed, should NOT receive a notification + * 8 => Topic subscribed, and 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' => 8, 'item_id' => 1, '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('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), + ), + ), + ); + } +} diff --git a/tests/notification/submit_post_type_post_test.php b/tests/notification/submit_post_type_post_test.php index 5580d0924e..9d94358f99 100644 --- a/tests/notification/submit_post_type_post_test.php +++ b/tests/notification/submit_post_type_post_test.php @@ -30,6 +30,16 @@ class phpbb_notification_submit_post_type_post_test extends phpbb_notification_s $this->stringContains('_'), $this->greaterThan(0)) ->will($this->returnValueMap(array( + array( + array(3, 4, 5, 6), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 5, 6), + ), + ), + ), array( array(3, 4, 5, 6, 7, 8), 'f_read', @@ -61,8 +71,8 @@ class phpbb_notification_submit_post_type_post_test extends phpbb_notification_s * 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 + * 7 => Forum subscribed, should NOT receive a notification + * 8 => Forum subscribed, and already notified, should NOT receive a new notification */ array( array(), @@ -74,7 +84,6 @@ class phpbb_notification_submit_post_type_post_test extends phpbb_notification_s 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), ), ),