aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorv12mike <github@ingenious.co.nz>2019-09-11 04:52:07 -0400
committerMarc Alexander <admin@m-a-styles.de>2019-11-21 13:44:20 +0100
commit92362441bd17dd18fb006a7b9f7a05c65ed2b432 (patch)
tree477b0120e42e470f083b9a8835c58ff2e5b653ba /tests
parent78a913581c727801240758c0a8c3bfae86d124ca (diff)
downloadforums-92362441bd17dd18fb006a7b9f7a05c65ed2b432.tar
forums-92362441bd17dd18fb006a7b9f7a05c65ed2b432.tar.gz
forums-92362441bd17dd18fb006a7b9f7a05c65ed2b432.tar.bz2
forums-92362441bd17dd18fb006a7b9f7a05c65ed2b432.tar.xz
forums-92362441bd17dd18fb006a7b9f7a05c65ed2b432.zip
[ticket/9837] Make unapproved posts visible to posters
Add tests Tidy up code Improve user message formatting PHPBB3-9837
Diffstat (limited to 'tests')
-rw-r--r--tests/content_visibility/fixtures/get_visibility_sql.xml23
-rw-r--r--tests/content_visibility/get_visibility_sql_test.php68
2 files changed, 89 insertions, 2 deletions
diff --git a/tests/content_visibility/fixtures/get_visibility_sql.xml b/tests/content_visibility/fixtures/get_visibility_sql.xml
index 146244263e..2128064986 100644
--- a/tests/content_visibility/fixtures/get_visibility_sql.xml
+++ b/tests/content_visibility/fixtures/get_visibility_sql.xml
@@ -3,17 +3,20 @@
<table name="phpbb_topics">
<column>topic_id</column>
<column>forum_id</column>
+ <column>topic_poster</column>
<column>topic_visibility</column>
<column>topic_title</column>
<row>
<value>1</value>
<value>1</value>
<value>0</value>
+ <value>0</value>
<value>Unapproved</value>
</row>
<row>
<value>2</value>
<value>1</value>
+ <value>0</value>
<value>1</value>
<value>Approved</value>
</row>
@@ -21,13 +24,22 @@
<value>3</value>
<value>1</value>
<value>2</value>
+ <value>0</value>
<value>Softdeleted</value>
</row>
+ <row>
+ <value>4</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value>Unapproved</value>
+ </row>
</table>
<table name="phpbb_posts">
<column>post_id</column>
<column>topic_id</column>
<column>forum_id</column>
+ <column>poster_id</column>
<column>post_visibility</column>
<column>post_text</column>
<row>
@@ -35,12 +47,14 @@
<value>1</value>
<value>1</value>
<value>0</value>
+ <value>0</value>
<value>Unapproved</value>
</row>
<row>
<value>2</value>
<value>2</value>
<value>1</value>
+ <value>0</value>
<value>1</value>
<value>Approved</value>
</row>
@@ -48,8 +62,17 @@
<value>3</value>
<value>3</value>
<value>1</value>
+ <value>0</value>
<value>2</value>
<value>Softdeleted</value>
</row>
+ <row>
+ <value>4</value>
+ <value>4</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value>Unapproved</value>
+ </row>
</table>
</dataset>
diff --git a/tests/content_visibility/get_visibility_sql_test.php b/tests/content_visibility/get_visibility_sql_test.php
index 18802fadbc..def4ed3718 100644
--- a/tests/content_visibility/get_visibility_sql_test.php
+++ b/tests/content_visibility/get_visibility_sql_test.php
@@ -21,8 +21,11 @@ class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_te
public function get_visibility_sql_data()
{
return array(
+ // data set 0: display_unapproved_posts=false, moderator, can see all posts
array(
'phpbb_posts',
+ 0,
+ false,
'post', 1, '',
array(
array('m_approve', 1, true),
@@ -31,10 +34,14 @@ class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_te
array('post_id' => 1),
array('post_id' => 2),
array('post_id' => 3),
+ array('post_id' => 4),
),
),
+ // data set 1: display_unapproved_posts=false, normal user, cannot see any unapproved posts
array(
'phpbb_posts',
+ 0,
+ false,
'post', 1, '',
array(
),
@@ -42,8 +49,11 @@ class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_te
array('post_id' => 2),
),
),
+ // data set 2: display_unapproved_posts=false, moderator, can see all topics
array(
'phpbb_topics',
+ 0,
+ false,
'topic', 1, '',
array(
array('m_approve', 1, true),
@@ -52,23 +62,74 @@ class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_te
array('topic_id' => 1),
array('topic_id' => 2),
array('topic_id' => 3),
+ array('topic_id' => 4),
),
),
+ // data set 3: display_unapproved_posts=false, normal user, cannot see unapproved posts topic
array(
'phpbb_topics',
+ 0,
+ false,
'topic', 1, '',
array(),
array(
array('topic_id' => 2),
),
),
+ // data set 4: display_unapproved_posts=true, guest user, cannot see unapproved posts
+ array(
+ 'phpbb_posts',
+ 1,
+ true,
+ 'post', 1, '',
+ array(
+ ),
+ array(
+ array('post_id' => 2),
+ ),
+ ),
+ // data set 5: display_unapproved_posts=true, guest user, cannot see unapproved posts topic
+ array(
+ 'phpbb_topics',
+ 1,
+ true,
+ 'topic', 1, '',
+ array(),
+ array(
+ array('topic_id' => 2),
+ ),
+ ),
+ // data set 6: display_unapproved_posts=true, normal user, can see own unapproved posts
+ array(
+ 'phpbb_posts',
+ 0,
+ true,
+ 'post', 1, '',
+ array(),
+ array(
+ array('post_id' => 1),
+ array('post_id' => 2),
+ ),
+ ),
+ // data set 7: display_unapproved_posts=true, normal user, can see own unapproved posts topic
+ array(
+ 'phpbb_topics',
+ 0,
+ true,
+ 'topic', 1, '',
+ array(),
+ array(
+ array('topic_id' => 1),
+ array('topic_id' => 2),
+ ),
+ ),
);
}
/**
* @dataProvider get_visibility_sql_data
*/
- public function test_get_visibility_sql($table, $mode, $forum_id, $table_alias, $permissions, $expected)
+ public function test_get_visibility_sql($table, $user_id, $display_unapproved, $mode, $forum_id, $table_alias, $permissions, $expected)
{
global $cache, $db, $auth, $phpbb_root_path, $phpEx;
@@ -84,7 +145,10 @@ class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_te
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader);
$user = new \phpbb\user($lang, '\phpbb\datetime');
- $config = new phpbb\config\config(array());
+ $user->data['user_id'] = $user_id;
+ $config = $this->config = new \phpbb\config\config(array(
+ 'display_unapproved_posts' => $display_unapproved,
+ ));
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);