1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-01-19 15:17:16 +01:00

Merge remote-tracking branch 'github-nickvergessen/ticket/11352' into develop-ascraeus

* github-nickvergessen/ticket/11352:
  [ticket/11352] Add functional tests for disapproving a post/topic
  [ticket/11352] Redirect the user back to view*.php after disapproving
This commit is contained in:
Nils Adermann 2014-04-10 13:56:30 -07:00
commit 79fe781629
2 changed files with 335 additions and 0 deletions

View File

@ -1163,6 +1163,22 @@ class mcp_queue
$success_msg .= '_DELETED_SUCCESS';
}
// If we came from viewtopic, we try to go back to it.
if (strpos($redirect, $phpbb_root_path . 'viewtopic.' . $phpEx) === 0)
{
if ($num_disapproved_topics == 0)
{
// So we need to remove the post id part from the Url
$redirect = str_replace("&p={$post_id_list[0]}#p{$post_id_list[0]}", '', $redirect);
}
else
{
// However this is only possible if the topic still exists,
// Otherwise we go back to the viewforum page
$redirect = append_sid($phpbb_root_path . 'viewforum.' . $phpEx, 'f=' . $request->variable('f', 0));
}
}
meta_refresh(3, $redirect);
$message = $user->lang[$success_msg];

View File

@ -0,0 +1,319 @@
<?php
/**
*
* @package testing
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @group functional
*/
class phpbb_functional_disapprove_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' => 'Disapprove 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(
'Disapprove Test #1',
),
));
$this->assert_forum_details($this->data['forums']['Disapprove 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']['Disapprove Test #1'], 'Disapprove 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('Disapprove Test Topic #1', $crawler->filter('html')->text());
$this->data['topics']['Disapprove Test Topic #1'] = (int) $post['topic_id'];
$this->data['posts']['Disapprove 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']['Disapprove 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']['Disapprove Test Topic #1'],
), 'after creating topic #1');
$this->logout();
$this->create_user('disapprove_testuser');
$this->add_user_group('NEWLY_REGISTERED', array('disapprove_testuser'));
$this->login('disapprove_testuser');
// Test creating a reply
$post2 = $this->create_post($this->data['forums']['Disapprove Test #1'], $post['topic_id'], 'Re: Disapprove 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']['Disapprove Test Topic #1']}&sid={$this->sid}");
$this->assertNotContains('Re: Disapprove Test Topic #1-#2', $crawler->filter('html')->text());
$this->assert_forum_details($this->data['forums']['Disapprove 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']['Disapprove Test Topic #1'],
), 'after replying');
// Test creating topic #2
$post = $this->create_topic($this->data['forums']['Disapprove Test #1'], 'Disapprove 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']['Disapprove Test #1']}&sid={$this->sid}");
$this->assertNotContains('Disapprove Test Topic #2', $crawler->filter('html')->text());
$this->assert_forum_details($this->data['forums']['Disapprove 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']['Disapprove Test Topic #1'],
), 'after creating topic #2');
$this->logout();
}
public function test_reset_flood_interval()
{
$this->login();
$this->admin_login();
// Set flood interval back to 15
$this->set_flood_interval(15);
}
public function test_disapprove_post()
{
$this->login();
$this->load_ids(array(
'forums' => array(
'Disapprove Test #1',
),
'topics' => array(
'Disapprove Test Topic #1',
'Disapprove Test Topic #2',
),
'posts' => array(
'Disapprove Test Topic #1',
'Re: Disapprove Test Topic #1-#2',
'Disapprove Test Topic #2',
),
));
$this->assert_forum_details($this->data['forums']['Disapprove 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']['Disapprove Test Topic #1'],
), 'before disapproving post');
$this->add_lang('posting');
$this->add_lang('viewtopic');
$this->add_lang('mcp');
$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #1']}&sid={$this->sid}");
$this->assertContains('Disapprove Test Topic #1', $crawler->filter('html')->text());
$this->assertContains('Re: Disapprove Test Topic #1-#2', $crawler->filter('html')->text());
$form = $crawler->selectButton($this->lang('DISAPPROVE'))->form();
$crawler = self::submit($form);
$form = $crawler->selectButton($this->lang('YES'))->form();
$crawler = self::submit($form);
$this->assertContainsLang('POST_DISAPPROVED_SUCCESS', $crawler->text());
$this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array(
'forum_posts_approved' => 1,
'forum_posts_unapproved' => 1,
'forum_posts_softdeleted' => 0,
'forum_topics_approved' => 1,
'forum_topics_unapproved' => 1,
'forum_topics_softdeleted' => 0,
'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'],
), 'after disapproving post');
$link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link();
$link_url = $link->getUri();
$this->assertContains('viewtopic.php?f=' . $this->data['forums']['Disapprove Test #1'] . '&t=' . $this->data['topics']['Disapprove Test Topic #1'], $link_url);
$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #1']}&sid={$this->sid}");
$this->assertContains('Disapprove Test Topic #1', $crawler->filter('html')->text());
$this->assertNotContains('Re: Disapprove Test Topic #1-#2', $crawler->filter('html')->text());
}
public function test_disapprove_topic()
{
$this->login();
$this->load_ids(array(
'forums' => array(
'Disapprove Test #1',
),
'topics' => array(
'Disapprove Test Topic #1',
'Disapprove Test Topic #2',
),
'posts' => array(
'Disapprove Test Topic #1',
'Disapprove Test Topic #2',
),
));
$this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array(
'forum_posts_approved' => 1,
'forum_posts_unapproved' => 1,
'forum_posts_softdeleted' => 0,
'forum_topics_approved' => 1,
'forum_topics_unapproved' => 1,
'forum_topics_softdeleted' => 0,
'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'],
), 'before disapproving topic');
$this->add_lang('posting');
$this->add_lang('viewtopic');
$this->add_lang('mcp');
$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #2']}&sid={$this->sid}");
$this->assertContains('Disapprove Test Topic #2', $crawler->filter('html')->text());
$form = $crawler->selectButton($this->lang('DISAPPROVE'))->form();
$crawler = self::submit($form);
$form = $crawler->selectButton($this->lang('YES'))->form();
$crawler = self::submit($form);
$this->assertContainsLang('TOPIC_DISAPPROVED_SUCCESS', $crawler->text());
$this->assert_forum_details($this->data['forums']['Disapprove 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']['Disapprove Test Topic #1'],
), 'after disapproving topic');
$link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link();
$link_url = $link->getUri();
$this->assertContains('viewforum.php?f=' . $this->data['forums']['Disapprove Test #1'], $link_url);
$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #2']}&sid={$this->sid}", array(), false);
self::assert_response_html(404);
$this->assertNotContains('Disapprove Test Topic #2', $crawler->filter('html')->text());
}
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);
}
}
}