mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-20 23:51:28 +01:00
[ticket/9837] Display unapproved posts to posters
Add tests and improve style template PHPBB3-9837
This commit is contained in:
parent
63b7518a0f
commit
78a913581c
@ -614,7 +614,7 @@ $lang = array_merge($lang, array(
|
||||
'POST_TIME' => 'Post time',
|
||||
'POST_TOPIC' => 'Post a new topic',
|
||||
'POST_UNAPPROVED_ACTION' => 'Post awaiting approval:',
|
||||
'POST_UNAPPROVED' => 'This post has not been approved.',
|
||||
'POST_UNAPPROVED' => 'This post is not visible to other users until it has been approved',
|
||||
'POWERED_BY' => 'Powered by %s',
|
||||
'PREVIEW' => 'Preview',
|
||||
'PREVIOUS' => 'Previous', // Used in pagination
|
||||
|
@ -76,7 +76,7 @@ class content_visibility
|
||||
* @param string $topics_table Topics table name
|
||||
* @param string $users_table Users table name
|
||||
*/
|
||||
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbb\db\driver\driver_interface $db, \phpbb\user $user, $phpbb_root_path, $php_ext, $forums_table, $posts_table, $topics_table, $users_table)
|
||||
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbb\db\driver\driver_interface $db, \phpbb\user $user, $phpbb_root_path, $php_ext, $forums_table, $posts_table, $topics_table, $users_table)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->config = $config;
|
||||
@ -198,8 +198,8 @@ class content_visibility
|
||||
* @var array forum_id The forum id in which the search is made.
|
||||
* @var string table_alias Table alias to prefix in SQL queries
|
||||
* @var mixed get_visibility_sql_overwrite If a string, forces the function to return get_forums_visibility_sql_overwrite after executing the event
|
||||
* If false, get_visibility_sql continues normally
|
||||
* It must be either boolean or string
|
||||
* If false, get_visibility_sql continues normally
|
||||
* It must be either boolean or string
|
||||
* @since 3.1.4-RC1
|
||||
*/
|
||||
$vars = array(
|
||||
@ -225,10 +225,10 @@ class content_visibility
|
||||
$visibility_query = $table_alias . $mode . '_visibility = ';
|
||||
|
||||
$where_sql .= '(' . $visibility_query . ITEM_APPROVED . ')';
|
||||
if ($this->config['display_unapproved_posts'] && ($this->user->data['user_id'] <> ANONYMOUS))
|
||||
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;
|
||||
$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']) . ')';
|
||||
}
|
||||
}
|
||||
@ -268,8 +268,8 @@ class content_visibility
|
||||
* @var string table_alias Table alias to prefix in SQL queries
|
||||
* @var array approve_forums Array of forums where the user has m_approve permissions
|
||||
* @var mixed get_forums_visibility_sql_overwrite If a string, forces the function to return get_forums_visibility_sql_overwrite after executing the event
|
||||
* If false, get_forums_visibility_sql continues normally
|
||||
* It must be either boolean or string
|
||||
* If false, get_forums_visibility_sql continues normally
|
||||
* It must be either boolean or string
|
||||
* @since 3.1.3-RC1
|
||||
*/
|
||||
$vars = array(
|
||||
|
@ -306,8 +306,9 @@
|
||||
</p>
|
||||
</form>
|
||||
<!-- ELSE -->
|
||||
<p class="post-notice information">
|
||||
{L_POST_UNAPPROVED}
|
||||
<p class="post-notice unapproved">
|
||||
<span><i class="icon fa-exclamation icon-red fa-fw" aria-hidden="true"></i></span>
|
||||
<strong>{L_POST_UNAPPROVED}</strong>
|
||||
</p>
|
||||
<!-- ENDIF -->
|
||||
<!-- ELSEIF postrow.S_POST_DELETED -->
|
||||
|
360
tests/functional/visibility_unapproved_posts_test.php
Normal file
360
tests/functional/visibility_unapproved_posts_test.php
Normal file
@ -0,0 +1,360 @@
|
||||
<?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 = array();
|
||||
|
||||
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(array(
|
||||
'forum_name' => 'Unapproved Posts Test #1',
|
||||
));
|
||||
$crawler = self::submit($form);
|
||||
$form = $crawler->selectButton('update')->form(array(
|
||||
'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(array(
|
||||
'forums' => array(
|
||||
'Unapproved Posts Test #1',
|
||||
),
|
||||
));
|
||||
|
||||
$this->assert_forum_details($this->data['forums']['Unapproved Posts Test #1'], array(
|
||||
'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'], array(
|
||||
'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', array('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.', array(), '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'], array(
|
||||
'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.', array(), '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'], array(
|
||||
'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(array(
|
||||
'forums' => array(
|
||||
'Unapproved Posts Test #1',
|
||||
),
|
||||
'topics' => array(
|
||||
'Unapproved Posts Test Topic #1',
|
||||
'Unapproved Posts Test Topic #2',
|
||||
),
|
||||
'posts' => array(
|
||||
'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'], array(
|
||||
'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');
|
||||
$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());
|
||||
}
|
||||
|
||||
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(array(
|
||||
'forums' => array(
|
||||
'Unapproved Posts Test #1',
|
||||
),
|
||||
'topics' => array(
|
||||
'Unapproved Posts Test Topic #1',
|
||||
'Unapproved Posts Test Topic #2',
|
||||
),
|
||||
'posts' => array(
|
||||
'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'], array(
|
||||
'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();
|
||||
|
||||
// revert the configuration
|
||||
$this->config_display_unapproved_posts_state(false);
|
||||
}
|
||||
|
||||
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 *
|
||||
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