diff options
| -rw-r--r-- | phpBB/feed.php | 2 | ||||
| -rw-r--r-- | phpBB/includes/content_visibility.php | 5 | ||||
| -rw-r--r-- | phpBB/includes/functions_display.php | 4 | ||||
| -rw-r--r-- | tests/content_visibility/fixtures/get_forums_visibility_sql.xml | 133 | ||||
| -rw-r--r-- | tests/content_visibility/get_forums_visibility_sql_test.php | 149 | ||||
| -rw-r--r-- | tests/content_visibility/get_visibility_sql_test.php | 5 | 
6 files changed, 288 insertions, 10 deletions
diff --git a/phpBB/feed.php b/phpBB/feed.php index 2e1589d999..aeb5abcc83 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -755,7 +755,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base  		$sql = 'SELECT topic_id, topic_last_post_time  			FROM ' . TOPICS_TABLE . '  			WHERE topic_moved_id = 0 -				AND ' . phpbb_content_visibility::get_visibility_sql_forums('topic', $forum_ids) . ' +				AND ' . phpbb_content_visibility::get_forums_visibility_sql('topic', $forum_ids) . '  			ORDER BY topic_last_post_time DESC';  		$result = $db->sql_query_limit($sql, $this->num_items); diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 9d2bf34370..a598d863a4 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -82,12 +82,13 @@ class phpbb_content_visibility  	* @param $table_alias string - Table alias to prefix in SQL queries  	* @return string with the appropriate combination SQL logic for topic/post_visibility  	*/ -	static public function get_visibility_sql_forums($mode, $forum_ids = array(), $table_alias = '') +	static public function get_forums_visibility_sql($mode, $forum_ids = array(), $table_alias = '')  	{  		global $auth, $db, $user;  		// users can always see approved posts -		$where_sql = "($table_alias{$mode}_visibility = " . ITEM_APPROVED; +		$where_sql = "(($table_alias{$mode}_visibility = " . ITEM_APPROVED . ' +				AND ' . $db->sql_in_set($table_alias . 'forum_id', $forum_ids) . ')';  		// in set notation: {approve_forums} = {m_approve} - {exclude_forums}  		$approve_forums = array_intersect($forum_ids, array_keys($auth->acl_getf('m_approve', true))); diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 2781f1a7bb..5849f5cf4c 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1003,7 +1003,7 @@ function display_user_activity(&$userdata)  		FROM ' . POSTS_TABLE . '  		WHERE poster_id = ' . $userdata['user_id'] . '  			AND post_postcount = 1 -			AND ' . phpbb_content_visibility::get_visibility_sql_forums('post', $forum_ary) . ' +			AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . '  		GROUP BY forum_id  		ORDER BY num_posts DESC';  	$result = $db->sql_query_limit($sql, 1); @@ -1029,7 +1029,7 @@ function display_user_activity(&$userdata)  		FROM ' . POSTS_TABLE . '  		WHERE poster_id = ' . $userdata['user_id'] . '  			AND post_postcount = 1 -			AND ' . phpbb_content_visibility::get_visibility_sql_forums('post', $forum_ary) . ' +			AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . '  		GROUP BY topic_id  		ORDER BY num_posts DESC';  	$result = $db->sql_query_limit($sql, 1); diff --git a/tests/content_visibility/fixtures/get_forums_visibility_sql.xml b/tests/content_visibility/fixtures/get_forums_visibility_sql.xml new file mode 100644 index 0000000000..658d34398f --- /dev/null +++ b/tests/content_visibility/fixtures/get_forums_visibility_sql.xml @@ -0,0 +1,133 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_topics"> +		<column>topic_id</column> +		<column>forum_id</column> +		<column>topic_visibility</column> +		<column>topic_title</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>2</value> +			<value>1</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>3</value> +			<value>1</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +		<row> +			<value>4</value> +			<value>2</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>5</value> +			<value>2</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>6</value> +			<value>2</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +		<row> +			<value>7</value> +			<value>3</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>8</value> +			<value>3</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>9</value> +			<value>3</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +	</table> +	<table name="phpbb_posts"> +		<column>post_id</column> +		<column>topic_id</column> +		<column>forum_id</column> +		<column>post_visibility</column> +		<column>post_text</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>2</value> +			<value>2</value> +			<value>1</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>3</value> +			<value>3</value> +			<value>1</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +		<row> +			<value>4</value> +			<value>4</value> +			<value>2</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>5</value> +			<value>5</value> +			<value>2</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>6</value> +			<value>6</value> +			<value>2</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +		<row> +			<value>7</value> +			<value>7</value> +			<value>3</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>8</value> +			<value>8</value> +			<value>3</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>9</value> +			<value>9</value> +			<value>3</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +	</table> +</dataset> diff --git a/tests/content_visibility/get_forums_visibility_sql_test.php b/tests/content_visibility/get_forums_visibility_sql_test.php new file mode 100644 index 0000000000..62e1c8187d --- /dev/null +++ b/tests/content_visibility/get_forums_visibility_sql_test.php @@ -0,0 +1,149 @@ +<?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__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; + +class phpbb_content_visibility_get_forums_visibility_sql_test extends phpbb_database_test_case +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/get_forums_visibility_sql.xml'); +	} + +	public function get_forums_visibility_sql_data() +	{ +		return array( +			array( +				'phpbb_topics', +				'topic', array(1, 2, 3), '', +				array( +					array('m_approve', true, array(1 => true, 2 => true, 3 => true)), +					array('m_restore', true, array(1 => true, 2 => true, 3 => true)), +				), +				array( +					array('topic_id' => 1), +					array('topic_id' => 2), +					array('topic_id' => 3), +					array('topic_id' => 4), +					array('topic_id' => 5), +					array('topic_id' => 6), +					array('topic_id' => 7), +					array('topic_id' => 8), +					array('topic_id' => 9), +				), +			), +			array( +				'phpbb_topics', +				'topic', array(1, 2), '', +				array( +					array('m_approve', true, array(1 => true, 2 => true)), +					array('m_restore', true, array(1 => true, 2 => true)), +				), +				array( +					array('topic_id' => 1), +					array('topic_id' => 2), +					array('topic_id' => 3), +					array('topic_id' => 4), +					array('topic_id' => 5), +					array('topic_id' => 6), +				), +			), +			array( +				'phpbb_topics', +				'topic', array(1, 2, 3), '', +				array( +					array('m_approve', true, array(2 => true)), +					array('m_restore', true, array(1 => true)), +				), +				array( +					array('topic_id' => 2), +					array('topic_id' => 3), +					array('topic_id' => 4), +					array('topic_id' => 5), +					array('topic_id' => 8), +				), +			), +			array( +				'phpbb_posts', +				'post', array(1, 2, 3), '', +				array( +					array('m_approve', true, array(1 => true, 2 => true, 3 => true)), +					array('m_restore', true, array(1 => true, 2 => true, 3 => true)), +				), +				array( +					array('post_id' => 1), +					array('post_id' => 2), +					array('post_id' => 3), +					array('post_id' => 4), +					array('post_id' => 5), +					array('post_id' => 6), +					array('post_id' => 7), +					array('post_id' => 8), +					array('post_id' => 9), +				), +			), +			array( +				'phpbb_posts', +				'post', array(1, 2), '', +				array( +					array('m_approve', true, array(1 => true, 2 => true)), +					array('m_restore', true, array(1 => true, 2 => true)), +				), +				array( +					array('post_id' => 1), +					array('post_id' => 2), +					array('post_id' => 3), +					array('post_id' => 4), +					array('post_id' => 5), +					array('post_id' => 6), +				), +			), +			array( +				'phpbb_posts', +				'post', array(1, 2, 3), '', +				array( +					array('m_approve', true, array(2 => true)), +					array('m_restore', true, array(1 => true)), +				), +				array( +					array('post_id' => 2), +					array('post_id' => 3), +					array('post_id' => 4), +					array('post_id' => 5), +					array('post_id' => 8), +				), +			), +		); +	} + +	/** +	* @dataProvider get_forums_visibility_sql_data +	*/ +	public function test_get_forums_visibility_sql($table, $mode, $forum_ids, $table_alias, $permissions, $expected) +	{ +		global $db, $auth; + +		$db = $this->new_dbal(); + +		// Create auth mock +		$auth = $this->getMock('phpbb_auth'); +		$auth->expects($this->any()) +			->method('acl_getf') +			->with($this->stringContains('_'), $this->anything()) +			->will($this->returnValueMap($permissions)); + +		$result = $db->sql_query('SELECT ' . $mode . '_id +			FROM ' . $table . ' +			WHERE ' . phpbb_content_visibility::get_forums_visibility_sql($mode, $forum_ids, $table_alias) . ' +			ORDER BY ' . $mode . '_id ASC'); + +		$this->assertEquals($expected, $db->sql_fetchrowset($result)); +	} +} diff --git a/tests/content_visibility/get_visibility_sql_test.php b/tests/content_visibility/get_visibility_sql_test.php index 415a33d17f..55396aaba5 100644 --- a/tests/content_visibility/get_visibility_sql_test.php +++ b/tests/content_visibility/get_visibility_sql_test.php @@ -121,11 +121,6 @@ class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_te  		// Create auth mock  		$auth = $this->getMock('phpbb_auth'); -		$acl_get_map = array( -			array('f_read', 23, true), -			array('m_', 23, true), -		); -  		$auth->expects($this->any())  			->method('acl_get')  			->with($this->stringContains('_'), $this->anything())  | 
