aboutsummaryrefslogtreecommitdiffstats
path: root/tests/notification
diff options
context:
space:
mode:
Diffstat (limited to 'tests/notification')
-rw-r--r--tests/notification/convert_test.php108
-rw-r--r--tests/notification/ext/test/notification/type/test.php85
-rw-r--r--tests/notification/fixtures/convert.xml80
-rw-r--r--tests/notification/fixtures/notification.xml13
-rw-r--r--tests/notification/fixtures/submit_post_bookmark.xml175
-rw-r--r--tests/notification/fixtures/submit_post_post.xml219
-rw-r--r--tests/notification/fixtures/submit_post_post_in_queue.xml177
-rw-r--r--tests/notification/fixtures/submit_post_quote.xml147
-rw-r--r--tests/notification/manager_helper.php67
-rw-r--r--tests/notification/notification_test.php432
-rw-r--r--tests/notification/submit_post_base.php154
-rw-r--r--tests/notification/submit_post_type_bookmark_test.php90
-rw-r--r--tests/notification/submit_post_type_post_in_queue_test.php107
-rw-r--r--tests/notification/submit_post_type_post_test.php96
-rw-r--r--tests/notification/submit_post_type_quote_test.php113
15 files changed, 2063 insertions, 0 deletions
diff --git a/tests/notification/convert_test.php b/tests/notification/convert_test.php
new file mode 100644
index 0000000000..c038020385
--- /dev/null
+++ b/tests/notification/convert_test.php
@@ -0,0 +1,108 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+require_once dirname(__FILE__) . '/../mock/sql_insert_buffer.php';
+
+class phpbb_notification_convert_test extends phpbb_database_test_case
+{
+ protected $notifications, $db, $container, $user, $config, $auth, $cache;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/convert.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path, $phpEx;
+
+ $this->db = $this->new_dbal();
+
+ $this->migration = new phpbb_db_migration_data_310_notification_options_reconvert(
+ new phpbb_config(array()),
+ $this->db,
+ new phpbb_db_tools($this->db),
+ $phpbb_root_path,
+ $phpEx,
+ 'phpbb_'
+ );
+ }
+
+ public function test_convert()
+ {
+ $buffer = new phpbb_mock_sql_insert_buffer($this->db, 'phpbb_user_notifications');
+ $this->migration->perform_conversion($buffer, 'phpbb_user_notifications');
+
+ $expected = array_merge(
+ $this->create_expected('post', 1, 'email'),
+ $this->create_expected('topic', 1, 'email'),
+
+ $this->create_expected('post', 2, 'email'),
+ $this->create_expected('topic', 2, 'email'),
+ $this->create_expected('pm', 2, 'email'),
+
+ $this->create_expected('post', 3, 'jabber'),
+ $this->create_expected('topic', 3, 'jabber'),
+
+ $this->create_expected('post', 4, 'jabber'),
+ $this->create_expected('topic', 4, 'jabber'),
+ $this->create_expected('pm', 4, 'jabber'),
+
+ $this->create_expected('post', 5, 'both'),
+ $this->create_expected('topic', 5, 'both'),
+
+ $this->create_expected('post', 6, 'both'),
+ $this->create_expected('topic', 6, 'both'),
+ $this->create_expected('pm', 6, 'both')
+ );
+
+ $this->assertEquals($expected, $buffer->get_buffer());
+ }
+
+ protected function create_expected($type, $user_id, $method = '')
+ {
+ $return = array();
+
+ if ($method !== '')
+ {
+ $return[] = array(
+ 'item_type' => $type,
+ 'item_id' => 0,
+ 'user_id' => $user_id,
+ 'method' => '',
+ 'notify' => 1,
+ );
+ }
+
+ if ($method === 'email' || $method === 'both')
+ {
+ $return[] = array(
+ 'item_type' => $type,
+ 'item_id' => 0,
+ 'user_id' => $user_id,
+ 'method' => 'email',
+ 'notify' => 1,
+ );
+ }
+
+ if ($method === 'jabber' || $method === 'both')
+ {
+ $return[] = array(
+ 'item_type' => $type,
+ 'item_id' => 0,
+ 'user_id' => $user_id,
+ 'method' => 'jabber',
+ 'notify' => 1,
+ );
+ }
+
+ return $return;
+ }
+}
diff --git a/tests/notification/ext/test/notification/type/test.php b/tests/notification/ext/test/notification/type/test.php
new file mode 100644
index 0000000000..0d0c584e0d
--- /dev/null
+++ b/tests/notification/ext/test/notification/type/test.php
@@ -0,0 +1,85 @@
+<?php
+/**
+*
+* @package notifications
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+class phpbb_notification_type_test extends phpbb_notification_type_base
+{
+ public function get_type()
+ {
+ return 'test';
+ }
+
+ public static function get_item_id($post)
+ {
+ return (int) $post['post_id'];
+ }
+
+ public static function get_item_parent_id($post)
+ {
+ return (int) $post['topic_id'];
+ }
+
+ public function find_users_for_notification($post, $options = array())
+ {
+ return $this->check_user_notification_options(array(0), $options);
+ }
+
+ public function create_insert_array($post, $pre_create_data = array())
+ {
+ $this->notification_time = $post['post_time'];
+
+ return parent::create_insert_array($post, $pre_create_data);
+ }
+
+ public function create_update_array($type_data)
+ {
+ $data = $this->create_insert_array($type_data);
+
+ // Unset data unique to each row
+ unset(
+ $data['notification_id'],
+ $data['notification_read'],
+ $data['user_id']
+ );
+
+ return $data;
+ }
+
+ public function get_title()
+ {
+ return 'test title';
+ }
+
+ public function users_to_query()
+ {
+ return array();
+ }
+
+ public function get_url()
+ {
+ return '';
+ }
+
+ public function get_email_template()
+ {
+ return false;
+ }
+
+ public function get_email_template_variables()
+ {
+ return array();
+ }
+}
diff --git a/tests/notification/fixtures/convert.xml b/tests/notification/fixtures/convert.xml
new file mode 100644
index 0000000000..3f0a065cc4
--- /dev/null
+++ b/tests/notification/fixtures/convert.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_notify_type</column>
+ <column>user_notify_pm</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_occ</column>
+ <column>user_interests</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>2</value>
+ <value>0</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>3</value>
+ <value>3</value>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>4</value>
+ <value>4</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>5</value>
+ <value>5</value>
+ <value>2</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>6</value>
+ <value>6</value>
+ <value>2</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/notification/fixtures/notification.xml b/tests/notification/fixtures/notification.xml
new file mode 100644
index 0000000000..c7b2d03ff1
--- /dev/null
+++ b/tests/notification/fixtures/notification.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_bookmarks">
+ </table>
+ <table name="phpbb_notifications">
+ </table>
+ <table name="phpbb_notification_types">
+ </table>
+ <table name="phpbb_topics_watch">
+ </table>
+ <table name="phpbb_user_notifications">
+ </table>
+</dataset>
diff --git a/tests/notification/fixtures/submit_post_bookmark.xml b/tests/notification/fixtures/submit_post_bookmark.xml
new file mode 100644
index 0000000000..d4bf8df73f
--- /dev/null
+++ b/tests/notification/fixtures/submit_post_bookmark.xml
@@ -0,0 +1,175 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_bookmarks">
+ <column>topic_id</column>
+ <column>user_id</column>
+ <row>
+ <value>1</value>
+ <value>2</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>3</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>4</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>5</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>6</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>7</value>
+ </row>
+ </table>
+ <table name="phpbb_notifications">
+ <column>notification_type_id</column>
+ <column>user_id</column>
+ <column>item_id</column>
+ <column>item_parent_id</column>
+ <column>notification_read</column>
+ <column>notification_data</column>
+ <row>
+ <value>1</value>
+ <value>5</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_notification_types">
+ <column>notification_type_id</column>
+ <column>notification_type_name</column>
+ <column>notification_type_enabled</column>
+ <row>
+ <value>1</value>
+ <value>bookmark</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_text</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_occ</column>
+ <column>user_interests</column>
+ <row>
+ <value>2</value>
+ <value>poster</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>test</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>unauthorized</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>notified</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>disabled</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>default</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_user_notifications">
+ <column>item_type</column>
+ <column>item_id</column>
+ <column>user_id</column>
+ <column>method</column>
+ <column>notify</column>
+ <row>
+ <value>bookmark</value>
+ <value>0</value>
+ <value>2</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>bookmark</value>
+ <value>0</value>
+ <value>3</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>bookmark</value>
+ <value>0</value>
+ <value>4</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>bookmark</value>
+ <value>0</value>
+ <value>5</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>bookmark</value>
+ <value>0</value>
+ <value>6</value>
+ <value></value>
+ <value>0</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/notification/fixtures/submit_post_post.xml b/tests/notification/fixtures/submit_post_post.xml
new file mode 100644
index 0000000000..b0ffa042c5
--- /dev/null
+++ b/tests/notification/fixtures/submit_post_post.xml
@@ -0,0 +1,219 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_forums_watch">
+ <column>forum_id</column>
+ <column>user_id</column>
+ <column>notify_status</column>
+ <row>
+ <value>1</value>
+ <value>6</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>7</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>8</value>
+ <value>0</value>
+ </row>
+ </table>
+ <table name="phpbb_notifications">
+ <column>notification_type_id</column>
+ <column>user_id</column>
+ <column>item_id</column>
+ <column>item_parent_id</column>
+ <column>notification_read</column>
+ <column>notification_data</column>
+ <row>
+ <value>1</value>
+ <value>5</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>8</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_notification_types">
+ <column>notification_type_id</column>
+ <column>notification_type_name</column>
+ <column>notification_type_enabled</column>
+ <row>
+ <value>1</value>
+ <value>post</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_text</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_topics_watch">
+ <column>topic_id</column>
+ <column>user_id</column>
+ <column>notify_status</column>
+ <row>
+ <value>1</value>
+ <value>2</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>3</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>4</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>5</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>6</value>
+ <value>0</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_occ</column>
+ <column>user_interests</column>
+ <row>
+ <value>2</value>
+ <value>poster</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>test</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>unauthorized</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>notified</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>disabled</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>default</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_user_notifications">
+ <column>item_type</column>
+ <column>item_id</column>
+ <column>user_id</column>
+ <column>method</column>
+ <column>notify</column>
+ <row>
+ <value>post</value>
+ <value>0</value>
+ <value>2</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>post</value>
+ <value>0</value>
+ <value>3</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>post</value>
+ <value>0</value>
+ <value>4</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>post</value>
+ <value>0</value>
+ <value>5</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>post</value>
+ <value>0</value>
+ <value>6</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>post</value>
+ <value>0</value>
+ <value>7</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>post</value>
+ <value>0</value>
+ <value>8</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
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..090e90ea49
--- /dev/null
+++ b/tests/notification/fixtures/submit_post_post_in_queue.xml
@@ -0,0 +1,177 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_notifications">
+ <column>notification_type_id</column>
+ <column>user_id</column>
+ <column>item_id</column>
+ <column>item_parent_id</column>
+ <column>notification_read</column>
+ <column>notification_data</column>
+ <row>
+ <value>1</value>
+ <value>6</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_notification_types">
+ <column>notification_type_id</column>
+ <column>notification_type_name</column>
+ <column>notification_type_enabled</column>
+ <row>
+ <value>1</value>
+ <value>post_in_queue</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_text</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_occ</column>
+ <column>user_interests</column>
+ <row>
+ <value>2</value>
+ <value>poster</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>test</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>unauthorized-mod</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>unauthorized-read</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>notified</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>disabled</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>8</value>
+ <value>default</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>9</value>
+ <value>test glboal-permissions</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_user_notifications">
+ <column>item_type</column>
+ <column>item_id</column>
+ <column>user_id</column>
+ <column>method</column>
+ <column>notify</column>
+ <row>
+ <value>needs_approval</value>
+ <value>0</value>
+ <value>2</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>needs_approval</value>
+ <value>0</value>
+ <value>3</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>needs_approval</value>
+ <value>0</value>
+ <value>4</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>needs_approval</value>
+ <value>0</value>
+ <value>5</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>needs_approval</value>
+ <value>0</value>
+ <value>6</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>needs_approval</value>
+ <value>0</value>
+ <value>7</value>
+ <value></value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>needs_approval</value>
+ <value>0</value>
+ <value>9</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/notification/fixtures/submit_post_quote.xml b/tests/notification/fixtures/submit_post_quote.xml
new file mode 100644
index 0000000000..f22ed97d91
--- /dev/null
+++ b/tests/notification/fixtures/submit_post_quote.xml
@@ -0,0 +1,147 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_notifications">
+ <column>notification_type_id</column>
+ <column>user_id</column>
+ <column>item_id</column>
+ <column>item_parent_id</column>
+ <column>notification_read</column>
+ <column>notification_data</column>
+ <row>
+ <value>1</value>
+ <value>5</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_notification_types">
+ <column>notification_type_id</column>
+ <column>notification_type_name</column>
+ <column>notification_type_enabled</column>
+ <row>
+ <value>1</value>
+ <value>quote</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_text</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_occ</column>
+ <column>user_interests</column>
+ <row>
+ <value>2</value>
+ <value>poster</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>test</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>unauthorized</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>notified</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>disabled</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>default</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_user_notifications">
+ <column>item_type</column>
+ <column>item_id</column>
+ <column>user_id</column>
+ <column>method</column>
+ <column>notify</column>
+ <row>
+ <value>quote</value>
+ <value>0</value>
+ <value>2</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>quote</value>
+ <value>0</value>
+ <value>3</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>quote</value>
+ <value>0</value>
+ <value>4</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>quote</value>
+ <value>0</value>
+ <value>5</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>quote</value>
+ <value>0</value>
+ <value>6</value>
+ <value></value>
+ <value>0</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/notification/manager_helper.php b/tests/notification/manager_helper.php
new file mode 100644
index 0000000000..7a794f922f
--- /dev/null
+++ b/tests/notification/manager_helper.php
@@ -0,0 +1,67 @@
+<?php
+/**
+*
+* @package notifications
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Notifications service class
+* @package notifications
+*/
+class phpbb_notification_manager_helper extends phpbb_notification_manager
+{
+ public function set_var($name, $value)
+ {
+ $this->$name = $value;
+ }
+
+ // Extra dependencies for get_*_class functions
+ protected $auth = null;
+ protected $config = null;
+ public function setDependencies($auth, $config)
+ {
+ $this->auth = $auth;
+ $this->config = $config;
+ }
+
+ /**
+ * Helper to get the notifications item type class and set it up
+ */
+ public function get_item_type_class($item_type, $data = array())
+ {
+ $item_type = 'phpbb_notification_type_' . $item_type;
+
+ $item = new $item_type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
+
+ $item->set_notification_manager($this);
+
+ $item->set_initial_data($data);
+
+ return $item;
+ }
+
+ /**
+ * Helper to get the notifications method class and set it up
+ */
+ public function get_method_class($method_name)
+ {
+ $method_name = 'phpbb_notification_method_' . $method_name;
+
+ $method = new $method_name($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
+
+ $method->set_notification_manager($this);
+
+ return $method;
+ }
+}
diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php
new file mode 100644
index 0000000000..8f7eb3b8a8
--- /dev/null
+++ b/tests/notification/notification_test.php
@@ -0,0 +1,432 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/manager_helper.php';
+
+class phpbb_notification_test extends phpbb_database_test_case
+{
+ protected $notifications, $db, $container, $user, $config, $auth, $cache;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/notification.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path, $phpEx;
+
+ include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx);
+
+ $this->db = $this->new_dbal();
+ $this->config = new phpbb_config(array(
+ 'allow_privmsg' => true,
+ 'allow_bookmarks' => true,
+ 'allow_topic_notify' => true,
+ 'allow_forum_notify' => true,
+ ));
+ $this->user = new phpbb_user();
+ $this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users');
+ $this->auth = new phpbb_mock_notifications_auth();
+ $this->cache = new phpbb_cache_service(
+ new phpbb_cache_driver_null(),
+ $this->config,
+ $this->db,
+ $phpbb_root_path,
+ $phpEx
+ );
+
+ $this->container = new phpbb_mock_container_builder();
+
+ $this->notifications = new phpbb_notification_manager_helper(
+ array(),
+ array(),
+ $this->container,
+ $this->user_loader,
+ $this->db,
+ $this->cache,
+ $this->user,
+ $phpbb_root_path,
+ $phpEx,
+ 'phpbb_notification_types',
+ 'phpbb_notifications',
+ 'phpbb_user_notifications'
+ );
+
+ $this->notifications->setDependencies($this->auth, $this->config);
+
+ $types = array();
+ foreach (array(
+ 'test',
+ 'approve_post',
+ 'approve_topic',
+ 'bookmark',
+ 'disapprove_post',
+ 'disapprove_topic',
+ 'pm',
+ 'post',
+ 'post_in_queue',
+ 'quote',
+ 'report_pm',
+ 'report_pm_closed',
+ 'report_post',
+ 'report_post_closed',
+ 'topic',
+ 'topic_in_queue',
+ ) as $type)
+ {
+ $class = $this->build_type('phpbb_notification_type_' . $type);
+
+ $types[$type] = $class;
+ $this->container->set('notification.type.' . $type, $class);
+ }
+
+ $this->notifications->set_var('notification_types', $types);
+ }
+
+ protected function build_type($type)
+ {
+ global $phpbb_root_path, $phpEx;
+
+ return new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications');
+ }
+
+ public function test_get_notification_type_id()
+ {
+ // They should be inserted the first time
+ $this->assertEquals(1, $this->notifications->get_notification_type_id('post'));
+ $this->assertEquals(2, $this->notifications->get_notification_type_id('quote'));
+ $this->assertEquals(3, $this->notifications->get_notification_type_id('test'));
+
+ $this->assertEquals(array(
+ 'test' => 3,
+ 'quote' => 2,
+ 'post' => 1,
+ ),
+ $this->notifications->get_notification_type_ids(array(
+ 'test',
+ 'quote',
+ 'post',
+ )
+ ));
+ $this->assertEquals(2, $this->notifications->get_notification_type_id('quote'));
+
+ try
+ {
+ $this->assertEquals(3, $this->notifications->get_notification_type_id('fail'));
+
+ $this->fail('Non-existent type should throw an exception');
+ }
+ catch (Exception $e) {}
+ }
+
+ public function test_get_subscription_types()
+ {
+ $subscription_types = $this->notifications->get_subscription_types();
+
+ $this->assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types);
+ $this->assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types);
+
+ $this->assertArrayHasKey('bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+ $this->assertArrayHasKey('post', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+ $this->assertArrayHasKey('quote', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+ $this->assertArrayHasKey('topic', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+
+ $this->assertArrayHasKey('pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
+
+ //get_subscription_types
+ //get_subscription_methods
+ }
+
+ public function test_subscriptions()
+ {
+ $this->notifications->delete_subscription('post', 0, '', 2);
+
+ $this->assertArrayNotHasKey('post', $this->notifications->get_global_subscriptions(2));
+
+ $this->notifications->add_subscription('post', 0, '', 2);
+
+ $this->assertArrayHasKey('post', $this->notifications->get_global_subscriptions(2));
+ }
+
+ public function test_notifications()
+ {
+ $this->db->sql_query('DELETE FROM phpbb_notification_types');
+
+ $types = array('quote', 'bookmark', 'post', 'test');
+ foreach ($types as $id => $type)
+ {
+ $this->db->sql_query('INSERT INTO phpbb_notification_types ' .
+ $this->db->sql_build_array('INSERT', array(
+ 'notification_type_id' => ($id + 1),
+ 'notification_type_name' => $type,
+ 'notification_type_enabled' => 1,
+ ))
+ );
+ }
+
+ // Used to test post notifications later
+ $this->db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
+ 'topic_id' => 2,
+ 'notify_status' => NOTIFY_YES,
+ 'user_id' => 0,
+ )));
+
+ $this->assertEquals(array(
+ 'notifications' => array(),
+ 'unread_count' => 0,
+ 'total_count' => 0,
+ ), $this->notifications->load_notifications(array(
+ 'count_unread' => true,
+ )));
+
+ $this->notifications->add_notifications('test', array(
+ 'post_id' => '1',
+ 'topic_id' => '1',
+ 'post_time' => 1349413321,
+ ));
+
+ $this->notifications->add_notifications('test', array(
+ 'post_id' => '2',
+ 'topic_id' => '2',
+ 'post_time' => 1349413322,
+ ));
+
+ $this->notifications->add_notifications('test', array(
+ 'post_id' => '3',
+ 'topic_id' => '2',
+ 'post_time' => 1349413323,
+ ));
+
+ $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array(
+ 'post_id' => '4',
+ 'topic_id' => '2',
+ 'post_time' => 1349413324,
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title',
+ 'post_subject' => 'Re: test-title',
+ 'forum_id' => 2,
+ 'forum_name' => 'Your first forum',
+ ));
+
+ $this->db->sql_query('INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
+ 'topic_id' => 2,
+ 'user_id' => 0,
+ )));
+
+ $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array(
+ 'post_id' => '5',
+ 'topic_id' => '2',
+ 'post_time' => 1349413325,
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title',
+ 'post_subject' => 'Re: test-title',
+ 'forum_id' => 2,
+ 'forum_name' => 'Your first forum',
+ ));
+
+ $this->notifications->delete_subscription('test');
+
+ $this->notifications->add_notifications('test', array(
+ 'post_id' => '6',
+ 'topic_id' => '2',
+ 'post_time' => 1349413326,
+ ));
+
+ $notifications = $this->notifications->load_notifications(array(
+ 'count_unread' => true,
+ ));
+
+ $expected = array(
+ 1 => array(
+ 'notification_type_id' => 4,
+ 'item_id' => 1,
+ 'item_parent_id' => 1,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413321,
+ 'notification_data' => array(),
+ ),
+ 2 => array(
+ 'notification_type_id' => 4,
+ 'item_id' => 2,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413322,
+ 'notification_data' => array(),
+ ),
+ 3 => array(
+ 'notification_type_id' => 4,
+ 'item_id' => 3,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413323,
+ 'notification_data' => array(),
+ ),
+ 4 => array(
+ 'notification_type_id' => 3,
+ 'item_id' => 4,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413324,
+ 'notification_data' => array(
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title',
+ 'post_subject' => 'Re: test-title',
+ 'post_username' => '',
+ 'forum_id' => 2,
+ 'forum_name' => 'Your first forum',
+ ),
+ ),
+ 5 => array(
+ 'notification_type_id' => 2,
+ 'item_id' => 5,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413325,
+ 'notification_data' => array(
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title',
+ 'post_subject' => 'Re: test-title',
+ 'post_username' => '',
+ 'forum_id' => 2,
+ 'forum_name' => 'Your first forum',
+ ),
+ ),
+ );
+
+ $this->assertEquals(sizeof($expected), $notifications['unread_count']);
+
+ $notifications = $notifications['notifications'];
+
+ foreach ($expected as $notification_id => $notification_data)
+ {
+ //echo $notifications[$notification_id];
+
+ $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id');
+
+ foreach ($notification_data as $key => $value)
+ {
+ $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id);
+ }
+ }
+
+ // Now test updating -------------------------------
+
+ $this->notifications->update_notifications('test', array(
+ 'post_id' => '1',
+ 'topic_id' => '2', // change parent_id
+ 'post_time' => 1349413321,
+ ));
+
+ $this->notifications->update_notifications('test', array(
+ 'post_id' => '3',
+ 'topic_id' => '2',
+ 'post_time' => 1234, // change time
+ ));
+
+ $this->notifications->update_notifications(array('quote', 'bookmark', 'post', 'test'), array(
+ 'post_id' => '5',
+ 'topic_id' => '2',
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title2', // change topic_title
+ 'post_subject' => 'Re: test-title2', // change post_subject
+ 'forum_id' => 3, // change forum_id
+ 'forum_name' => 'Your second forum', // change forum_name
+ ));
+
+ $notifications = $this->notifications->load_notifications(array(
+ 'count_unread' => true,
+ ));
+
+ $expected = array(
+ 1 => array(
+ 'notification_type_id' => 4,
+ 'item_id' => 1,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413321,
+ 'notification_data' => array(),
+ ),
+ 2 => array(
+ 'notification_type_id' => 4,
+ 'item_id' => 2,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413322,
+ 'notification_data' => array(),
+ ),
+ 3 => array(
+ 'notification_type_id' => 4,
+ 'item_id' => 3,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1234,
+ 'notification_data' => array(),
+ ),
+ 4 => array(
+ 'notification_type_id' => 3,
+ 'item_id' => 4,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413324,
+ 'notification_data' => array(
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title',
+ 'post_subject' => 'Re: test-title',
+ 'post_username' => '',
+ 'forum_id' => 2,
+ 'forum_name' => 'Your first forum',
+ ),
+ ),
+ 5 => array(
+ 'notification_type_id' => 2,
+ 'item_id' => 5,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413325,
+ 'notification_data' => array(
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title2',
+ 'post_subject' => 'Re: test-title2',
+ 'post_username' => '',
+ 'forum_id' => 3,
+ 'forum_name' => 'Your second forum',
+ ),
+ ),
+ );
+
+ $this->assertEquals(sizeof($expected), $notifications['unread_count']);
+
+ $notifications = $notifications['notifications'];
+
+ foreach ($expected as $notification_id => $notification_data)
+ {
+ //echo $notifications[$notification_id];
+
+ $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id');
+
+ foreach ($notification_data as $key => $value)
+ {
+ $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id);
+ }
+ }
+ }
+}
diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php
new file mode 100644
index 0000000000..4e564ce23c
--- /dev/null
+++ b/tests/notification/submit_post_base.php
@@ -0,0 +1,154 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+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';
+
+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_' . $this->item_type . '.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;
+
+ // 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);
+
+ $cache = new phpbb_cache_service(
+ new phpbb_cache_driver_null(),
+ $config,
+ $db,
+ $phpbb_root_path,
+ $phpEx
+ );
+
+ // 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();
+ $phpbb_container->set('content.visibility', new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE));
+
+ $user_loader = new phpbb_user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
+
+ // Notification Types
+ $notification_types = array('quote', 'bookmark', 'post', 'post_in_queue', 'topic', 'approve_topic', 'approve_post');
+ $notification_types_array = array();
+ foreach ($notification_types as $type)
+ {
+ $class_name = 'phpbb_notification_type_' . $type;
+ $class = new $class_name(
+ $user_loader, $db, $cache->get_driver(), $user, $auth, $config,
+ $phpbb_root_path, $phpEx,
+ NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE);
+
+ $phpbb_container->set('notification.type.' . $type, $class);
+
+ $notification_types_array['notification.type.' . $type] = $class;
+ }
+
+ // Notification Manager
+ $phpbb_notifications = new phpbb_notification_manager($notification_types_array, array(),
+ $phpbb_container, $user_loader, $db, $cache, $user,
+ $phpbb_root_path, $phpEx,
+ NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE);
+ $phpbb_container->set('notification_manager', $phpbb_notifications);
+ }
+
+ /**
+ * @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 . ' n, ' . NOTIFICATION_TYPES_TABLE . " nt
+ WHERE nt.notification_type_name = '" . $this->item_type . "'
+ AND n.notification_type_id = nt.notification_type_id
+ 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);
+
+ $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 . ' n, ' . NOTIFICATION_TYPES_TABLE . " nt
+ WHERE nt.notification_type_name = '" . $this->item_type . "'
+ AND n.notification_type_id = nt.notification_type_id
+ 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_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 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/submit_post_base.php';
+
+class phpbb_notification_submit_post_type_bookmark_test extends phpbb_notification_submit_post_base
+{
+ protected $item_type = 'bookmark';
+
+ 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'),
+ '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),
+ ),
+ ),
+ );
+ }
+}
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..6a7ac44e39
--- /dev/null
+++ b/tests/notification/submit_post_type_post_in_queue_test.php
@@ -0,0 +1,107 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/submit_post_base.php';
+
+class phpbb_notification_submit_post_type_post_in_queue_test extends phpbb_notification_submit_post_base
+{
+ protected $item_type = 'post_in_queue';
+
+ 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(
+ false,
+ '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, 9),
+ 'f_read',
+ 1,
+ array(
+ 1 => array(
+ 'f_read' => array(3, 6, 7, 8, 9),
+ ),
+ ),
+ ),
+ )));
+ }
+
+ /**
+ * 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
+ * 9 => Moderator, has only global mod permissions, 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),
+ array('user_id' => 9, 'item_id' => 2, 'item_parent_id' => 1),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/notification/submit_post_type_post_test.php b/tests/notification/submit_post_type_post_test.php
new file mode 100644
index 0000000000..473247a764
--- /dev/null
+++ b/tests/notification/submit_post_type_post_test.php
@@ -0,0 +1,96 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+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();
+
+ 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, 8),
+ ),
+ ),
+ ),
+ )));
+ }
+
+ /**
+ * submit_post() Notifications test
+ *
+ * submit_post() $mode = 'reply'
+ * Notification item_type = 'post'
+ */
+ public function submit_post_data()
+ {
+ 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),
+ ),
+ ),
+
+ /**
+ * 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_quote_test.php b/tests/notification/submit_post_type_quote_test.php
new file mode 100644
index 0000000000..2b66d9c6a1
--- /dev/null
+++ b/tests/notification/submit_post_type_quote_test.php
@@ -0,0 +1,113 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+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();
+
+ 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'),
+ 'f_read',
+ 1,
+ array(
+ 1 => array(
+ 'f_read' => array(3, 5, 6, 7),
+ ),
+ ),
+ ),
+ )));
+ }
+
+ /**
+ * submit_post() Notifications test
+ *
+ * submit_post() $mode = 'reply'
+ * Notification item_type = 'quote'
+ */
+ public function submit_post_data()
+ {
+ 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=&quot;poster&quot;:uid]poster should not be notified[/quote:uid]',
+ '[quote=&quot;test&quot;:uid]test should be notified[/quote:uid]',
+ '[quote=&quot;unauthorized&quot;:uid]unauthorized to read, should not receive a notification[/quote:uid]',
+ '[quote=&quot;notified&quot;:uid]already notified, should not receive a new notification[/quote:uid]',
+ '[quote=&quot;disabled&quot;:uid]option disabled, should not receive a notification[/quote:uid]',
+ '[quote=&quot;default&quot;:uid]option set to default, should receive a notification[/quote:uid]',
+ '[quote=&quot;doesn\'t exist&quot;: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),
+ ),
+ ),
+
+ /**
+ * Unapproved post
+ *
+ * No new notifications
+ */
+ array(
+ array(
+ 'message' => implode(' ', array(
+ '[quote=&quot;poster&quot;:uid]poster should not be notified[/quote:uid]',
+ '[quote=&quot;test&quot;:uid]test should be notified[/quote:uid]',
+ '[quote=&quot;unauthorized&quot;:uid]unauthorized to read, should not receive a notification[/quote:uid]',
+ '[quote=&quot;notified&quot;:uid]already notified, should not receive a new notification[/quote:uid]',
+ '[quote=&quot;disabled&quot;:uid]option disabled, should not receive a notification[/quote:uid]',
+ '[quote=&quot;default&quot;:uid]option set to default, should receive a notification[/quote:uid]',
+ '[quote=&quot;doesn\'t exist&quot;: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),
+ ),
+ ),
+ );
+ }
+}