mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[feature/soft-delete] Add unit tests for get_forums_visibility_sql()
PHPBB3-9657
This commit is contained in:
parent
280619eea9
commit
4a65940e62
6 changed files with 288 additions and 10 deletions
|
@ -755,7 +755,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base
|
||||||
$sql = 'SELECT topic_id, topic_last_post_time
|
$sql = 'SELECT topic_id, topic_last_post_time
|
||||||
FROM ' . TOPICS_TABLE . '
|
FROM ' . TOPICS_TABLE . '
|
||||||
WHERE topic_moved_id = 0
|
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';
|
ORDER BY topic_last_post_time DESC';
|
||||||
$result = $db->sql_query_limit($sql, $this->num_items);
|
$result = $db->sql_query_limit($sql, $this->num_items);
|
||||||
|
|
||||||
|
|
|
@ -82,12 +82,13 @@ class phpbb_content_visibility
|
||||||
* @param $table_alias string - Table alias to prefix in SQL queries
|
* @param $table_alias string - Table alias to prefix in SQL queries
|
||||||
* @return string with the appropriate combination SQL logic for topic/post_visibility
|
* @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;
|
global $auth, $db, $user;
|
||||||
|
|
||||||
// users can always see approved posts
|
// 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}
|
// in set notation: {approve_forums} = {m_approve} - {exclude_forums}
|
||||||
$approve_forums = array_intersect($forum_ids, array_keys($auth->acl_getf('m_approve', true)));
|
$approve_forums = array_intersect($forum_ids, array_keys($auth->acl_getf('m_approve', true)));
|
||||||
|
|
|
@ -1003,7 +1003,7 @@ function display_user_activity(&$userdata)
|
||||||
FROM ' . POSTS_TABLE . '
|
FROM ' . POSTS_TABLE . '
|
||||||
WHERE poster_id = ' . $userdata['user_id'] . '
|
WHERE poster_id = ' . $userdata['user_id'] . '
|
||||||
AND post_postcount = 1
|
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
|
GROUP BY forum_id
|
||||||
ORDER BY num_posts DESC';
|
ORDER BY num_posts DESC';
|
||||||
$result = $db->sql_query_limit($sql, 1);
|
$result = $db->sql_query_limit($sql, 1);
|
||||||
|
@ -1029,7 +1029,7 @@ function display_user_activity(&$userdata)
|
||||||
FROM ' . POSTS_TABLE . '
|
FROM ' . POSTS_TABLE . '
|
||||||
WHERE poster_id = ' . $userdata['user_id'] . '
|
WHERE poster_id = ' . $userdata['user_id'] . '
|
||||||
AND post_postcount = 1
|
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
|
GROUP BY topic_id
|
||||||
ORDER BY num_posts DESC';
|
ORDER BY num_posts DESC';
|
||||||
$result = $db->sql_query_limit($sql, 1);
|
$result = $db->sql_query_limit($sql, 1);
|
||||||
|
|
133
tests/content_visibility/fixtures/get_forums_visibility_sql.xml
Normal file
133
tests/content_visibility/fixtures/get_forums_visibility_sql.xml
Normal file
|
@ -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>
|
149
tests/content_visibility/get_forums_visibility_sql_test.php
Normal file
149
tests/content_visibility/get_forums_visibility_sql_test.php
Normal file
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -121,11 +121,6 @@ class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_te
|
||||||
|
|
||||||
// Create auth mock
|
// Create auth mock
|
||||||
$auth = $this->getMock('phpbb_auth');
|
$auth = $this->getMock('phpbb_auth');
|
||||||
$acl_get_map = array(
|
|
||||||
array('f_read', 23, true),
|
|
||||||
array('m_', 23, true),
|
|
||||||
);
|
|
||||||
|
|
||||||
$auth->expects($this->any())
|
$auth->expects($this->any())
|
||||||
->method('acl_get')
|
->method('acl_get')
|
||||||
->with($this->stringContains('_'), $this->anything())
|
->with($this->stringContains('_'), $this->anything())
|
||||||
|
|
Loading…
Add table
Reference in a new issue