From 0fd78c5c872c758e38d3563402c634a0c0aff3a7 Mon Sep 17 00:00:00 2001 From: lavigor Date: Sun, 29 Jul 2018 04:13:37 +0300 Subject: [PATCH] [ticket/13713] Introduce tests for user notifications PHPBB3-13713 --- tests/notification/base.php | 1 + .../submit_post_notification.type.mention.xml | 135 ++++++++++++++++++ tests/notification/notification_test.php | 2 + tests/notification/submit_post_base.php | 3 + .../submit_post_type_mention_test.php | 121 ++++++++++++++++ 5 files changed, 262 insertions(+) create mode 100644 tests/notification/fixtures/submit_post_notification.type.mention.xml create mode 100644 tests/notification/submit_post_type_mention_test.php diff --git a/tests/notification/base.php b/tests/notification/base.php index d1861245bb..a22596f926 100644 --- a/tests/notification/base.php +++ b/tests/notification/base.php @@ -74,6 +74,7 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case 'allow_topic_notify' => true, 'allow_forum_notify' => true, 'allow_board_notifications' => true, + 'allow_mentions' => true, )); $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); $lang = new \phpbb\language\language($lang_loader); diff --git a/tests/notification/fixtures/submit_post_notification.type.mention.xml b/tests/notification/fixtures/submit_post_notification.type.mention.xml new file mode 100644 index 0000000000..0b47241b2a --- /dev/null +++ b/tests/notification/fixtures/submit_post_notification.type.mention.xml @@ -0,0 +1,135 @@ + + + + notification_id + notification_type_id + user_id + item_id + item_parent_id + notification_read + notification_data + + 1 + 1 + 5 + 1 + 1 + 0 + + +
+ + notification_type_id + notification_type_name + notification_type_enabled + + 1 + notification.type.mention + 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 + + 2 + poster + + + + + 3 + test + + + + + 4 + unauthorized + + + + + 5 + notified + + + + + 6 + disabled + + + + + 7 + default + + + +
+ + item_type + item_id + user_id + method + notify + + notification.type.mention + 0 + 2 + notification.method.board + 1 + + + notification.type.mention + 0 + 3 + notification.method.board + 1 + + + notification.type.mention + 0 + 4 + notification.method.board + 1 + + + notification.type.mention + 0 + 5 + notification.method.board + 1 + + + notification.type.mention + 0 + 6 + notification.method.board + 0 + +
+
diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index 08eabaa12a..4658f4c39a 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -59,6 +59,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base self::assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types); self::assertArrayHasKey('notification.type.bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']); + self::assertArrayHasKey('notification.type.mention', $subscription_types['NOTIFICATION_GROUP_POSTING']); self::assertArrayHasKey('notification.type.post', $subscription_types['NOTIFICATION_GROUP_POSTING']); self::assertArrayHasKey('notification.type.quote', $subscription_types['NOTIFICATION_GROUP_POSTING']); self::assertArrayHasKey('notification.type.topic', $subscription_types['NOTIFICATION_GROUP_POSTING']); @@ -73,6 +74,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base { $expected_subscriptions = array( 'notification.type.forum' => array('notification.method.board'), + 'notification.type.mention' => 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_base.php b/tests/notification/submit_post_base.php index 1e348f4529..98733b0fcd 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -70,6 +70,8 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c array('f_noapprove', 1, true), array('f_postcount', 1, true), array('m_edit', 1, false), + array('f_mention', 1, true), + array('u_mention', 0, true), ))); // Config @@ -77,6 +79,7 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c 'num_topics' => 1, 'num_posts' => 1, 'allow_board_notifications' => true, + 'allow_mentions' => true, )); $cache_driver = new \phpbb\cache\driver\dummy(); diff --git a/tests/notification/submit_post_type_mention_test.php b/tests/notification/submit_post_type_mention_test.php new file mode 100644 index 0000000000..14cd18e3bd --- /dev/null +++ b/tests/notification/submit_post_type_mention_test.php @@ -0,0 +1,121 @@ + +* @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_mention_test extends phpbb_notification_submit_post_base +{ + protected $item_type = 'notification.type.mention'; + + public function setUp() + { + 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, 7, 8), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 5, 6, 7), + ), + ), + ), + ))); + } + + /** + * submit_post() Notifications test + * + * submit_post() $mode = 'reply' + * Notification item_type = 'mention' + */ + public function submit_post_data() + { + // The new mock container is needed because the data providers may be executed before phpunit call setUp() + $parser = $this->get_test_case_helpers()->set_s9e_services(new phpbb_mock_container_builder())->get('text_formatter.parser'); + + return array( + /** + * Normal post + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => mentioned, should receive a notification + * 4 => mentioned, but unauthed to read, should NOT receive a notification + * 5 => mentioned, but already notified, should STILL receive a new notification + * 6 => mentioned, but option disabled, should NOT receive a notification + * 7 => mentioned, option set to default, should receive a notification + */ + array( + array( + 'message' => $parser->parse(implode(' ', array( + '[mention=u:2]poster[/mention] poster should not be notified', + '[mention=u:3]test[/mention] test should be notified', + '[mention=u:4]unauthorized[/mention] unauthorized to read, should not receive a notification', + '[mention=u:5]notified[/mention] already notified, should not receive a new notification', + '[mention=u:6]disabled[/mention] option disabled, should not receive a notification', + '[mention=u:7]default[/mention] option set to default, should receive a notification', + '[mention=u:8]doesn\'t exist[/mention] user does not exist, should not receive a notification', + ))), + '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' => 5, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), + ), + ), + + /** + * Unapproved post + * + * No new notifications + */ + array( + array( + 'message' => $parser->parse(implode(' ', array( + '[mention=u:2]poster[/mention] poster should not be notified', + '[mention=u:3]test[/mention] test should be notified', + '[mention=u:4]unauthorized[/mention] unauthorized to read, should not receive a notification', + '[mention=u:5]notified[/mention] already notified, should not receive a new notification', + '[mention=u:6]disabled[/mention] option disabled, should not receive a notification', + '[mention=u:7]default[/mention] option set to default, should receive a notification', + '[mention=u:8]doesn\'t exist[/mention] user does not exist, should not receive a notification', + ))), + '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), + ), + ), + ); + } +}