mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-20 23:51:28 +01:00
Merge pull request #5686 from v12mike/ticket/9837
[ticket/9837] Display unapproved posts to their authors
This commit is contained in:
commit
896b31272b
@ -101,6 +101,7 @@ class acp_board
|
||||
'allow_bookmarks' => array('lang' => 'ALLOW_BOOKMARKS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
|
||||
'allow_birthdays' => array('lang' => 'ALLOW_BIRTHDAYS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
|
||||
'display_last_subject' => array('lang' => 'DISPLAY_LAST_SUBJECT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
|
||||
'display_unapproved_posts' => array('lang' => 'DISPLAY_UNAPPROVED_POSTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
|
||||
'allow_quick_reply' => array('lang' => 'ALLOW_QUICK_REPLY', 'validate' => 'bool', 'type' => 'custom', 'method' => 'quick_reply', 'explain' => true),
|
||||
|
||||
'legend2' => 'ACP_SUBMIT_CHANGES',
|
||||
|
@ -52,6 +52,8 @@ $lang = array_merge($lang, array(
|
||||
'DISABLE_BOARD_EXPLAIN' => 'This will make the board unavailable to users who are neither administrators nor moderators. You can also enter a short (255 character) message to display if you wish.',
|
||||
'DISPLAY_LAST_SUBJECT' => 'Display subject of last added post on forum list',
|
||||
'DISPLAY_LAST_SUBJECT_EXPLAIN' => 'The subject of the last added post will be displayed in the forum list with a hyperlink to the post. Subjects from password protected forums and forums in which user doesn’t have read access are not shown.',
|
||||
'DISPLAY_UNAPPROVED_POSTS' => 'Display unapproved posts to the author',
|
||||
'DISPLAY_UNAPPROVED_POSTS_EXPLAIN' => 'Unapproved posts can be viewed by the author. Does not apply to Guest posts.',
|
||||
'GUEST_STYLE' => 'Guest style',
|
||||
'GUEST_STYLE_EXPLAIN' => 'The board style for guests.',
|
||||
'OVERRIDE_STYLE' => 'Override user style',
|
||||
|
@ -616,6 +616,7 @@ $lang = array_merge($lang, array(
|
||||
'POST_TOPIC' => 'Post a new topic',
|
||||
'POST_UNAPPROVED_ACTION' => 'Post awaiting approval:',
|
||||
'POST_UNAPPROVED' => 'This post has not been approved.',
|
||||
'POST_UNAPPROVED_EXPLAIN' => 'This post is not visible to other users until it has been approved by a moderator.',
|
||||
'POWERED_BY' => 'Powered by %s',
|
||||
'PREVIEW' => 'Preview',
|
||||
'PREVIOUS' => 'Previous', // Used in pagination
|
||||
|
@ -144,7 +144,14 @@ class content_visibility
|
||||
*/
|
||||
public function is_visible($mode, $forum_id, $data)
|
||||
{
|
||||
$is_visible = $this->auth->acl_get('m_approve', $forum_id) || $data[$mode . '_visibility'] == ITEM_APPROVED;
|
||||
$visibility = $data[$mode . '_visibility'];
|
||||
$poster_key = ($mode === 'topic') ? 'topic_poster' : 'poster_id';
|
||||
$is_visible = ($visibility == ITEM_APPROVED) ||
|
||||
($this->config['display_unapproved_posts'] &&
|
||||
($this->user->data['user_id'] != ANONYMOUS) &&
|
||||
($visibility == ITEM_UNAPPROVED || $visibility == ITEM_REAPPROVE) &&
|
||||
($this->user->data['user_id'] == $data[$poster_key])) ||
|
||||
$this->auth->acl_get('m_approve', $forum_id);
|
||||
|
||||
/**
|
||||
* Allow changing the result of calling is_visible
|
||||
@ -216,9 +223,16 @@ class content_visibility
|
||||
}
|
||||
else
|
||||
{
|
||||
$where_sql .= $table_alias . $mode . '_visibility = ' . ITEM_APPROVED;
|
||||
}
|
||||
$visibility_query = $table_alias . $mode . '_visibility = ';
|
||||
|
||||
$where_sql .= '(' . $visibility_query . ITEM_APPROVED . ')';
|
||||
if ($this->config['display_unapproved_posts'] && ($this->user->data['user_id'] != ANONYMOUS))
|
||||
{
|
||||
$poster_key = ($mode === 'topic') ? 'topic_poster' : 'poster_id';
|
||||
$where_sql .= ' OR ((' . $visibility_query . ITEM_UNAPPROVED . ' OR ' . $visibility_query . ITEM_REAPPROVE .')';
|
||||
$where_sql .= ' AND ' . $table_alias . $poster_key . ' = ' . ((int) $this->user->data['user_id']) . ')';
|
||||
}
|
||||
}
|
||||
return '(' . $where_sql . ')';
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\db\migration\data\v330;
|
||||
|
||||
class add_display_unapproved_posts_config extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function update_data()
|
||||
{
|
||||
return [
|
||||
['config.add', ['display_unapproved_posts', 1]],
|
||||
];
|
||||
}
|
||||
}
|
@ -294,6 +294,7 @@
|
||||
<!-- EVENT viewtopic_body_postrow_post_details_after -->
|
||||
|
||||
<!-- IF postrow.S_POST_UNAPPROVED -->
|
||||
<!-- IF postrow.S_CAN_APPROVE -->
|
||||
<form method="post" class="mcp_approve" action="{postrow.U_APPROVE_ACTION}">
|
||||
<p class="post-notice unapproved">
|
||||
<span><i class="icon fa-question icon-red fa-fw" aria-hidden="true"></i></span>
|
||||
@ -304,6 +305,12 @@
|
||||
{S_FORM_TOKEN}
|
||||
</p>
|
||||
</form>
|
||||
<!-- ELSE -->
|
||||
<p class="post-notice unapproved">
|
||||
<span><i class="icon fa-exclamation icon-red fa-fw" aria-hidden="true"></i></span>
|
||||
<strong>{L_POST_UNAPPROVED_EXPLAIN}</strong>
|
||||
</p>
|
||||
<!-- ENDIF -->
|
||||
<!-- ELSEIF postrow.S_POST_DELETED -->
|
||||
<form method="post" class="mcp_approve" action="{postrow.U_APPROVE_ACTION}">
|
||||
<p class="post-notice deleted">
|
||||
|
@ -899,6 +899,11 @@ if (count($topic_list))
|
||||
|
||||
// Replies
|
||||
$replies = $phpbb_content_visibility->get_count('topic_posts', $row, $topic_forum_id) - 1;
|
||||
// Correction for case of unapproved topic visible to poster
|
||||
if ($replies < 0)
|
||||
{
|
||||
$replies = 0;
|
||||
}
|
||||
|
||||
if ($row['topic_status'] == ITEM_MOVED)
|
||||
{
|
||||
|
@ -2092,6 +2092,7 @@ for ($i = 0, $end = count($post_list); $i < $end; ++$i)
|
||||
'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false,
|
||||
'S_MULTIPLE_ATTACHMENTS' => !empty($attachments[$row['post_id']]) && count($attachments[$row['post_id']]) > 1,
|
||||
'S_POST_UNAPPROVED' => ($row['post_visibility'] == ITEM_UNAPPROVED || $row['post_visibility'] == ITEM_REAPPROVE) ? true : false,
|
||||
'S_CAN_APPROVE' => $auth->acl_get('m_approve', $forum_id),
|
||||
'S_POST_DELETED' => ($row['post_visibility'] == ITEM_DELETED) ? true : false,
|
||||
'L_POST_DELETED_MESSAGE' => $l_deleted_message,
|
||||
'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $forum_id)) ? true : false,
|
||||
|
@ -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>
|
||||
|
@ -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,15 +145,20 @@ 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);
|
||||
|
||||
$result = $db->sql_query('SELECT ' . $mode . '_id
|
||||
$sql = 'SELECT ' . $mode . '_id
|
||||
FROM ' . $table . '
|
||||
WHERE ' . $content_visibility->get_visibility_sql($mode, $forum_id, $table_alias) . '
|
||||
ORDER BY ' . $mode . '_id ASC');
|
||||
ORDER BY ' . $mode . '_id ASC';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$this->assertEquals($expected, $db->sql_fetchrowset($result));
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
}
|
||||
|
356
tests/functional/visibility_unapproved_posts_test.php
Normal file
356
tests/functional/visibility_unapproved_posts_test.php
Normal file
@ -0,0 +1,356 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group functional
|
||||
*/
|
||||
class phpbb_functional_visibility_unapproved_test extends phpbb_functional_test_case
|
||||
{
|
||||
protected $data = [];
|
||||
|
||||
public function test_setup_forums()
|
||||
{
|
||||
$this->login();
|
||||
$this->admin_login();
|
||||
|
||||
$crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
|
||||
$form = $crawler->selectButton('addforum')->form([
|
||||
'forum_name' => 'Unapproved Posts Test #1',
|
||||
]);
|
||||
$crawler = self::submit($form);
|
||||
$form = $crawler->selectButton('update')->form([
|
||||
'forum_perm_from' => 2,
|
||||
]);
|
||||
$crawler = self::submit($form);
|
||||
|
||||
// Set flood interval to 0
|
||||
$this->set_flood_interval(0);
|
||||
}
|
||||
|
||||
public function test_create_posts()
|
||||
{
|
||||
$this->login();
|
||||
$this->load_ids([
|
||||
'forums' => [
|
||||
'Unapproved Posts Test #1',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assert_forum_details($this->data['forums']['Unapproved Posts Test #1'], [
|
||||
'forum_posts_approved' => 0,
|
||||
'forum_posts_unapproved' => 0,
|
||||
'forum_posts_softdeleted' => 0,
|
||||
'forum_topics_approved' => 0,
|
||||
'forum_topics_unapproved' => 0,
|
||||
'forum_topics_softdeleted' => 0,
|
||||
'forum_last_post_id' => 0,
|
||||
], 'initial comparison');
|
||||
|
||||
// Test creating topic #1
|
||||
$post = $this->create_topic($this->data['forums']['Unapproved Posts Test #1'], 'Unapproved Posts Test Topic #1', 'This is a test topic posted by the testing framework.');
|
||||
$crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
|
||||
|
||||
$this->assertContains('Unapproved Posts Test Topic #1', $crawler->filter('h2')->text());
|
||||
$this->data['topics']['Unapproved Posts Test Topic #1'] = (int) $post['topic_id'];
|
||||
$this->data['posts']['Unapproved Posts Test Topic #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p');
|
||||
|
||||
$this->assert_forum_details($this->data['forums']['Unapproved Posts Test #1'], [
|
||||
'forum_posts_approved' => 1,
|
||||
'forum_posts_unapproved' => 0,
|
||||
'forum_posts_softdeleted' => 0,
|
||||
'forum_topics_approved' => 1,
|
||||
'forum_topics_unapproved' => 0,
|
||||
'forum_topics_softdeleted' => 0,
|
||||
'forum_last_post_id' => $this->data['posts']['Unapproved Posts Test Topic #1'],
|
||||
], 'after creating topic #1');
|
||||
|
||||
$this->logout();
|
||||
$this->create_user('unapproved_posts_test_user#1');
|
||||
$this->add_user_group('NEWLY_REGISTERED', ['unapproved_posts_test_user#1']);
|
||||
$this->login('unapproved_posts_test_user#1');
|
||||
|
||||
// Test creating a reply
|
||||
$post2 = $this->create_post($this->data['forums']['Unapproved Posts Test #1'], $post['topic_id'], 'Re: Unapproved Posts Test Topic #1-#2', 'This is a test post posted by the testing framework.', [], 'POST_STORED_MOD');
|
||||
|
||||
$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Unapproved Posts Test Topic #1']}&sid={$this->sid}");
|
||||
$this->assertNotContains('Re: Unapproved Posts Test Topic #1-#2', $crawler->filter('#page-body')->text());
|
||||
|
||||
$this->assert_forum_details($this->data['forums']['Unapproved Posts Test #1'], [
|
||||
'forum_posts_approved' => 1,
|
||||
'forum_posts_unapproved' => 1,
|
||||
'forum_posts_softdeleted' => 0,
|
||||
'forum_topics_approved' => 1,
|
||||
'forum_topics_unapproved' => 0,
|
||||
'forum_topics_softdeleted' => 0,
|
||||
'forum_last_post_id' => $this->data['posts']['Unapproved Posts Test Topic #1'],
|
||||
], 'after replying');
|
||||
|
||||
// Test creating topic #2
|
||||
$post = $this->create_topic($this->data['forums']['Unapproved Posts Test #1'], 'Unapproved Posts Test Topic #2', 'This is a test topic posted by the testing framework.', [], 'POST_STORED_MOD');
|
||||
$crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Unapproved Posts Test #1']}&sid={$this->sid}");
|
||||
|
||||
$this->assertNotContains('Unapproved Posts Test Topic #2', $crawler->filter('html')->text());
|
||||
|
||||
$this->assert_forum_details($this->data['forums']['Unapproved Posts Test #1'], [
|
||||
'forum_posts_approved' => 1,
|
||||
'forum_posts_unapproved' => 2,
|
||||
'forum_posts_softdeleted' => 0,
|
||||
'forum_topics_approved' => 1,
|
||||
'forum_topics_unapproved' => 1,
|
||||
'forum_topics_softdeleted' => 0,
|
||||
'forum_last_post_id' => $this->data['posts']['Unapproved Posts Test Topic #1'],
|
||||
], 'after creating topic #2');
|
||||
|
||||
$this->logout();
|
||||
}
|
||||
|
||||
public function test_view_unapproved_post_disabled()
|
||||
{
|
||||
// user who created post
|
||||
$this->login('unapproved_posts_test_user#1');
|
||||
$this->load_ids([
|
||||
'forums' => [
|
||||
'Unapproved Posts Test #1',
|
||||
],
|
||||
'topics' => [
|
||||
'Unapproved Posts Test Topic #1',
|
||||
'Unapproved Posts Test Topic #2',
|
||||
],
|
||||
'posts' => [
|
||||
'Unapproved Posts Test Topic #1',
|
||||
'Re: Unapproved Posts Test Topic #1-#2',
|
||||
'Unapproved Posts Test Topic #2',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assert_forum_details($this->data['forums']['Unapproved Posts Test #1'], [
|
||||
'forum_posts_approved' => 1,
|
||||
'forum_posts_unapproved' => 2,
|
||||
'forum_posts_softdeleted' => 0,
|
||||
'forum_topics_approved' => 1,
|
||||
'forum_topics_unapproved' => 1,
|
||||
'forum_topics_softdeleted' => 0,
|
||||
'forum_last_post_id' => $this->data['posts']['Unapproved Posts Test Topic #1'],
|
||||
], 'before approving post');
|
||||
|
||||
$this->add_lang('posting');
|
||||
$this->add_lang('viewtopic');
|
||||
$this->add_lang('mcp');
|
||||
|
||||
// should be able to see topic 1 but not unapproved post
|
||||
$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Unapproved Posts Test Topic #1']}&sid={$this->sid}");
|
||||
$this->assertContains('Unapproved Posts Test Topic #1', $crawler->filter('h2')->text());
|
||||
$this->assertNotContains('Re: Unapproved Posts Test Topic #1-#2', $crawler->filter('#page-body')->text());
|
||||
$this->assertNotContains('This post is not visible to other users until it has been approved', $crawler->filter('#page-body')->text());
|
||||
|
||||
// should not be able to see topic 2
|
||||
$crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Unapproved Posts Test #1']}&sid={$this->sid}");
|
||||
$this->assertNotContains('Unapproved Posts Test Topic #2', $crawler->filter('html')->text());
|
||||
$this->logout();
|
||||
|
||||
// another user
|
||||
$this->create_user('unapproved_posts_test_user#2');
|
||||
$this->login('unapproved_posts_test_user#2');
|
||||
|
||||
$this->add_lang('posting', 'viewtopic', 'mcp');
|
||||
|
||||
// should be able to see topic 1 but not unapproved post
|
||||
$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Unapproved Posts Test Topic #1']}&sid={$this->sid}");
|
||||
$this->assertContains('Unapproved Posts Test Topic #1', $crawler->filter('h2')->text());
|
||||
$this->assertNotContains('Re: Unapproved Posts Test Topic #1-#2', $crawler->filter('#page-body')->text());
|
||||
$this->assertNotContains('This post is not visible to other users until it has been approved', $crawler->filter('#page-body')->text());
|
||||
|
||||
// should not be able to see topic 2
|
||||
$crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Unapproved Posts Test #1']}&sid={$this->sid}");
|
||||
$this->assertNotContains('Unapproved Posts Test Topic #2', $crawler->filter('html')->text());
|
||||
}
|
||||
|
||||
public function test_view_unapproved_post_enabled()
|
||||
{
|
||||
$this->config_display_unapproved_posts_state(true);
|
||||
|
||||
// user who created post
|
||||
$this->login('unapproved_posts_test_user#1');
|
||||
$this->load_ids([
|
||||
'forums' => [
|
||||
'Unapproved Posts Test #1',
|
||||
],
|
||||
'topics' => [
|
||||
'Unapproved Posts Test Topic #1',
|
||||
'Unapproved Posts Test Topic #2',
|
||||
],
|
||||
'posts' => [
|
||||
'Unapproved Posts Test Topic #1',
|
||||
'Re: Unapproved Posts Test Topic #1-#2',
|
||||
'Unapproved Posts Test Topic #2',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assert_forum_details($this->data['forums']['Unapproved Posts Test #1'], [
|
||||
'forum_posts_approved' => 1,
|
||||
'forum_posts_unapproved' => 2,
|
||||
'forum_posts_softdeleted' => 0,
|
||||
'forum_topics_approved' => 1,
|
||||
'forum_topics_unapproved' => 1,
|
||||
'forum_topics_softdeleted' => 0,
|
||||
'forum_last_post_id' => $this->data['posts']['Unapproved Posts Test Topic #1'],
|
||||
], 'before approving post');
|
||||
|
||||
$this->add_lang('posting');
|
||||
$this->add_lang('viewtopic');
|
||||
$this->add_lang('mcp');
|
||||
|
||||
// should be able to see topic 1 and unapproved post
|
||||
$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Unapproved Posts Test Topic #1']}&sid={$this->sid}");
|
||||
$this->assertContains('Unapproved Posts Test Topic #1', $crawler->filter('h2')->text());
|
||||
$this->assertContains('Re: Unapproved Posts Test Topic #1-#2', $crawler->filter('#page-body')->text());
|
||||
$this->assertContains('This post is not visible to other users until it has been approved', $crawler->filter('#page-body')->text());
|
||||
|
||||
// should be able to see topic 2
|
||||
$crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Unapproved Posts Test #1']}&sid={$this->sid}");
|
||||
$this->assertContains('Unapproved Posts Test Topic #2', $crawler->filter('html')->text());
|
||||
|
||||
// should be able to see post in topic 2
|
||||
$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Unapproved Posts Test Topic #2']}&sid={$this->sid}");
|
||||
$this->assertContains('Unapproved Posts Test Topic #2', $crawler->filter('#page-body')->text());
|
||||
$this->assertContains('This post is not visible to other users until it has been approved', $crawler->filter('#page-body')->text());
|
||||
$this->logout();
|
||||
|
||||
// another user
|
||||
$this->login('unapproved_posts_test_user#2');
|
||||
|
||||
$this->add_lang('posting');
|
||||
$this->add_lang('viewtopic');
|
||||
$this->add_lang('mcp');
|
||||
|
||||
// should be able to see topic 1 but not unapproved post
|
||||
$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Unapproved Posts Test Topic #1']}&sid={$this->sid}");
|
||||
$this->assertContains('Unapproved Posts Test Topic #1', $crawler->filter('h2')->text());
|
||||
$this->assertNotContains('Re: Unapproved Posts Test Topic #1-#2', $crawler->filter('#page-body')->text());
|
||||
$this->assertNotContains('This post is not visible to other users until it has been approved', $crawler->filter('#page-body')->text());
|
||||
|
||||
// should not be able to see topic 2
|
||||
$crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Unapproved Posts Test #1']}&sid={$this->sid}");
|
||||
$this->assertNotContains('Unapproved Posts Test Topic #2', $crawler->filter('html')->text());
|
||||
$this->logout();
|
||||
}
|
||||
|
||||
public function test_reset_flood_interval()
|
||||
{
|
||||
$this->login();
|
||||
$this->admin_login();
|
||||
|
||||
// Set flood interval back to 15
|
||||
$this->set_flood_interval(15);
|
||||
}
|
||||
|
||||
protected function assert_forum_details($forum_id, $details, $additional_error_message = '')
|
||||
{
|
||||
$this->db = $this->get_db();
|
||||
|
||||
$sql = 'SELECT ' . implode(', ', array_keys($details)) . '
|
||||
FROM phpbb_forums
|
||||
WHERE forum_id = ' . (int) $forum_id;
|
||||
$result = $this->db->sql_query($sql);
|
||||
$data = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}");
|
||||
}
|
||||
|
||||
protected function set_flood_interval($flood_interval)
|
||||
{
|
||||
$crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=post");
|
||||
|
||||
$form = $crawler->selectButton('Submit')->form();
|
||||
$values = $form->getValues();
|
||||
|
||||
$values['config[flood_interval]'] = $flood_interval;
|
||||
$form->setValues($values);
|
||||
$crawler = self::submit($form);
|
||||
$this->assertGreaterThan(0, $crawler->filter('.successbox')->count());
|
||||
}
|
||||
|
||||
protected function load_ids($data)
|
||||
{
|
||||
$this->db = $this->get_db();
|
||||
|
||||
if (!empty($data['forums']))
|
||||
{
|
||||
$sql = 'SELECT forum_id, forum_name
|
||||
FROM phpbb_forums
|
||||
WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']);
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
if (in_array($row['forum_name'], $data['forums']))
|
||||
{
|
||||
$this->data['forums'][$row['forum_name']] = (int) $row['forum_id'];
|
||||
}
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
if (!empty($data['topics']))
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
FROM phpbb_topics
|
||||
WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']);
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
if (in_array($row['topic_title'], $data['topics']))
|
||||
{
|
||||
$this->data['topics'][$row['topic_title']] = (int) $row['topic_id'];
|
||||
}
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
if (!empty($data['posts']))
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
FROM phpbb_posts
|
||||
WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']);
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
if (in_array($row['post_subject'], $data['posts']))
|
||||
{
|
||||
$this->data['posts'][$row['post_subject']] = (int) $row['post_id'];
|
||||
}
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
}
|
||||
|
||||
protected function config_display_unapproved_posts_state($state)
|
||||
{
|
||||
$this->login();
|
||||
$this->admin_login();
|
||||
|
||||
$crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=features");
|
||||
|
||||
$form = $crawler->selectButton('Submit')->form();
|
||||
$values = $form->getValues();
|
||||
|
||||
// Enable display of unapproved posts to posters
|
||||
$values['config[display_unapproved_posts]'] = $state;
|
||||
|
||||
$form->setValues($values);
|
||||
|
||||
$crawler = self::submit($form);
|
||||
self::assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text());
|
||||
$this->logout();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user