diff options
-rw-r--r-- | tests/notification/submit_post_base.php | 47 | ||||
-rw-r--r-- | tests/notification/submit_post_type_post_test.php | 99 | ||||
-rw-r--r-- | tests/notification/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); } } |