diff options
| -rw-r--r-- | phpBB/includes/notification/type/bookmark.php | 1 | ||||
| -rw-r--r-- | phpBB/includes/notification/type/post.php | 15 | ||||
| -rw-r--r-- | phpBB/includes/notification/type/post_in_queue.php | 11 | ||||
| -rw-r--r-- | phpBB/includes/notification/type/quote.php | 1 | ||||
| -rw-r--r-- | phpBB/includes/notification/type/topic_in_queue.php | 11 | ||||
| -rw-r--r-- | tests/notification/fixtures/submit_post_bookmark.xml | 173 | ||||
| -rw-r--r-- | tests/notification/fixtures/submit_post_post.xml | 217 | ||||
| -rw-r--r-- | tests/notification/fixtures/submit_post_post_in_queue.xml | 175 | ||||
| -rw-r--r-- | tests/notification/fixtures/submit_post_quote.xml | 145 | ||||
| -rw-r--r-- | tests/notification/submit_post_base.php | 141 | ||||
| -rw-r--r-- | tests/notification/submit_post_type_bookmark_test.php | 90 | ||||
| -rw-r--r-- | tests/notification/submit_post_type_post_in_queue_test.php | 107 | ||||
| -rw-r--r-- | tests/notification/submit_post_type_post_test.php | 96 | ||||
| -rw-r--r-- | tests/notification/submit_post_type_quote_test.php | 113 | 
14 files changed, 1292 insertions, 4 deletions
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']); 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/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 9c719205e6..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)) @@ -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/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']); diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index c501434c43..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)) @@ -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'],  		)));  	} 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 @@ +<?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>item_type</column> +		<column>user_id</column> +		<column>item_id</column> +		<column>item_parent_id</column> +		<column>notification_read</column> +		<column>notification_data</column> +		<row> +			<value>bookmark</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</column> +		<column>notification_type_enabled</column> +		<row> +			<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..cead4f7c26 --- /dev/null +++ b/tests/notification/fixtures/submit_post_post.xml @@ -0,0 +1,217 @@ +<?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>item_type</column> +		<column>user_id</column> +		<column>item_id</column> +		<column>item_parent_id</column> +		<column>notification_read</column> +		<column>notification_data</column> +		<row> +			<value>post</value> +			<value>5</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value></value> +		</row> +		<row> +			<value>post</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</column> +		<column>notification_type_enabled</column> +		<row> +			<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..eedcebf71d --- /dev/null +++ b/tests/notification/fixtures/submit_post_post_in_queue.xml @@ -0,0 +1,175 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_notifications"> +		<column>item_type</column> +		<column>user_id</column> +		<column>item_id</column> +		<column>item_parent_id</column> +		<column>notification_read</column> +		<column>notification_data</column> +		<row> +			<value>post_in_queue</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</column> +		<column>notification_type_enabled</column> +		<row> +			<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..884a84af4a --- /dev/null +++ b/tests/notification/fixtures/submit_post_quote.xml @@ -0,0 +1,145 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_notifications"> +		<column>item_type</column> +		<column>user_id</column> +		<column>item_id</column> +		<column>item_parent_id</column> +		<column>notification_read</column> +		<column>notification_data</column> +		<row> +			<value>quote</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</column> +		<column>notification_type_enabled</column> +		<row> +			<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/submit_post_base.php b/tests/notification/submit_post_base.php new file mode 100644 index 0000000000..c5b2450e1c --- /dev/null +++ b/tests/notification/submit_post_base.php @@ -0,0 +1,141 @@ +<?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; + +		// 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', 'post_in_queue'); +		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)); +		} +	} + +	/** +	* @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); + +		$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 . " +			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_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="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), +				), +			), + +			/** +			* 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), +				), +			), +		); +	} +}  | 
