Merge PR #1140 branch 'EXreaction/ticket/8610' into develop-olympus

* EXreaction/ticket/8610:
  [ticket/8610] Update comment
  [ticket/8610] Do not use requests to submit posts except in posting_test.php
  [ticket/8610] Move posting helpers to separate file
  [ticket/8610] Create helper functions to create topic/post in functional tests
  [ticket/8610] Use phpbb_update_rows_avoiding_duplicates
  [ticket/8610] Revert some funky merging I did from rebase
  [ticket/8610] Add some comments
  [ticket/8610] Update Bookmarks and Subscriptions when splitting topics
  [ticket/8610] Update Bookmarks when merging posts into another topic
  [ticket/8610] Update Bookmarks when forking topics
  [ticket/8610] Update Bookmarks when merging topics
This commit is contained in:
Oleg Pudeyev 2012-12-16 16:24:48 -05:00
commit a288c4b66b
4 changed files with 171 additions and 61 deletions

View file

@ -414,13 +414,17 @@ function merge_topics($forum_id, $topic_ids, $to_topic_id)
// Message and return links // Message and return links
$success_msg = 'POSTS_MERGED_SUCCESS'; $success_msg = 'POSTS_MERGED_SUCCESS';
// Update the topic watch table.
if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status')) if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status'))
{ {
include($phpbb_root_path . 'includes/functions_database_helper.' . $phpEx); include($phpbb_root_path . 'includes/functions_database_helper.' . $phpEx);
} }
// Update the topic watch table.
phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id); phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id);
// Update the bookmarks table.
phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', $topic_ids, $to_topic_id);
// Link to the new topic // Link to the new topic
$return_link .= (($return_link) ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>'); $return_link .= (($return_link) ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>');
} }

View file

@ -1231,6 +1231,7 @@ function mcp_fork_topic($topic_ids)
} }
} }
// Copy topic subscriptions to new topic
$sql = 'SELECT user_id, notify_status $sql = 'SELECT user_id, notify_status
FROM ' . TOPICS_WATCH_TABLE . ' FROM ' . TOPICS_WATCH_TABLE . '
WHERE topic_id = ' . $topic_id; WHERE topic_id = ' . $topic_id;
@ -1251,6 +1252,27 @@ function mcp_fork_topic($topic_ids)
{ {
$db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary); $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
} }
// Copy bookmarks to new topic
$sql = 'SELECT user_id
FROM ' . BOOKMARKS_TABLE . '
WHERE topic_id = ' . $topic_id;
$result = $db->sql_query($sql);
$sql_ary = array();
while ($row = $db->sql_fetchrow($result))
{
$sql_ary[] = array(
'topic_id' => (int) $new_topic_id,
'user_id' => (int) $row['user_id'],
);
}
$db->sql_freeresult($result);
if (sizeof($sql_ary))
{
$db->sql_multi_insert(BOOKMARKS_TABLE, $sql_ary);
}
} }
// Sync new topics, parent forums and board stats // Sync new topics, parent forums and board stats

View file

@ -517,6 +517,49 @@ function split_topic($action, $topic_id, $to_forum_id, $subject)
WHERE post_id = {$post_id_list[0]}"; WHERE post_id = {$post_id_list[0]}";
$db->sql_query($sql); $db->sql_query($sql);
// Copy topic subscriptions to new topic
$sql = 'SELECT user_id, notify_status
FROM ' . TOPICS_WATCH_TABLE . '
WHERE topic_id = ' . $topic_id;
$result = $db->sql_query($sql);
$sql_ary = array();
while ($row = $db->sql_fetchrow($result))
{
$sql_ary[] = array(
'topic_id' => (int) $to_topic_id,
'user_id' => (int) $row['user_id'],
'notify_status' => (int) $row['notify_status'],
);
}
$db->sql_freeresult($result);
if (sizeof($sql_ary))
{
$db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
}
// Copy bookmarks to new topic
$sql = 'SELECT user_id
FROM ' . BOOKMARKS_TABLE . '
WHERE topic_id = ' . $topic_id;
$result = $db->sql_query($sql);
$sql_ary = array();
while ($row = $db->sql_fetchrow($result))
{
$sql_ary[] = array(
'topic_id' => (int) $to_topic_id,
'user_id' => (int) $row['user_id'],
);
}
$db->sql_freeresult($result);
if (sizeof($sql_ary))
{
$db->sql_multi_insert(BOOKMARKS_TABLE, $sql_ary);
}
$success_msg = 'TOPIC_SPLIT_SUCCESS'; $success_msg = 'TOPIC_SPLIT_SUCCESS';
// Update forum statistics // Update forum statistics
@ -619,12 +662,16 @@ function merge_posts($topic_id, $to_topic_id)
} }
else else
{ {
// If the topic no longer exist, we will update the topic watch table.
if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status')) if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status'))
{ {
include($phpbb_root_path . 'includes/functions_database_helper.' . $phpEx); include($phpbb_root_path . 'includes/functions_database_helper.' . $phpEx);
} }
// If the topic no longer exist, we will update the topic watch table.
phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id); phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id);
// If the topic no longer exist, we will update the bookmarks table.
phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', $topic_id, $to_topic_id);
} }
// Link to the new topic // Link to the new topic

View file

@ -15,24 +15,93 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
public function test_post_new_topic() public function test_post_new_topic()
{ {
$this->login(); $this->login();
// Test creating topic
$post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.');
$crawler = $this->request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
$this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text());
// Test creating a reply
$post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.');
$crawler = $this->request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
$this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text());
// Test quoting a message
$crawler = $this->request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}");
$this->assert_response_success();
$this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text());
}
/**
* Creates a topic
*
* Be sure to login before creating
*
* @param int $forum_id
* @param string $subject
* @param string $message
* @param array $additional_form_data Any additional form data to be sent in the request
* @return array post_id, topic_id
*/
public function create_topic($forum_id, $subject, $message, $additional_form_data = array())
{
$posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}";
$form_data = array_merge(array(
'subject' => $subject,
'message' => $message,
'post' => true,
), $additional_form_data);
return $this->submit_post($posting_url, 'POST_TOPIC', $form_data);
}
/**
* Creates a post
*
* Be sure to login before creating
*
* @param int $forum_id
* @param string $subject
* @param string $message
* @param array $additional_form_data Any additional form data to be sent in the request
* @return array post_id, topic_id
*/
public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array())
{
$posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}";
$form_data = array_merge(array(
'subject' => $subject,
'message' => $message,
'post' => true,
), $additional_form_data);
return $this->submit_post($posting_url, 'POST_REPLY', $form_data);
}
/**
* Helper for submitting posts
*
* @param string $posting_url
* @param string $posting_contains
* @param array $form_data
* @return array post_id, topic_id
*/
protected function submit_post($posting_url, $posting_contains, $form_data)
{
$this->add_lang('posting'); $this->add_lang('posting');
$crawler = $this->request('GET', 'posting.php?mode=post&f=2&sid=' . $this->sid); $crawler = $this->request('GET', $posting_url);
$this->assertContains($this->lang('POST_TOPIC'), $crawler->filter('html')->text()); $this->assert_response_success();
$this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text());
$hidden_fields = array(); $hidden_fields = array(
$hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) { $crawler->filter('[type="hidden"]')->each(function ($node, $i) {
return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value'));
}); }),
$test_message = 'This is a test topic posted by the testing framework.';
$form_data = array(
'subject' => 'Test Topic 1',
'message' => $test_message,
'post' => true,
'f' => 2,
'mode' => 'post',
'sid' => $this->sid,
); );
foreach ($hidden_fields as $fields) foreach ($hidden_fields as $fields)
@ -50,53 +119,21 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
// I use a request because the form submission method does not allow you to send data that is not // I use a request because the form submission method does not allow you to send data that is not
// contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs)
// Instead, I send it as a request with the submit button "post" set to true. // Instead, I send it as a request with the submit button "post" set to true.
$crawler = $this->client->request('POST', 'posting.php', $form_data); $crawler = $this->client->request('POST', $posting_url, $form_data);
$this->assert_response_success();
$this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text());
$crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid); $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri();
$this->assertContains($test_message, $crawler->filter('html')->text());
}
public function test_post_reply() $matches = $topic_id = $post_id = false;
{ preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches);
$this->login();
$this->add_lang('posting');
$crawler = $this->request('GET', 'posting.php?mode=reply&t=2&f=2&sid=' . $this->sid); $topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0;
$this->assertContains($this->lang('POST_REPLY'), $crawler->filter('html')->text()); $post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0;
$hidden_fields = array(); return array(
$hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) { 'topic_id' => $topic_id,
return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); 'post_id' => $post_id,
});
$test_message = 'This is a test post posted by the testing framework.';
$form_data = array(
'subject' => 'Re: Test Topic 1',
'message' => $test_message,
'post' => true,
't' => 2,
'f' => 2,
'mode' => 'reply',
'sid' => $this->sid,
); );
foreach ($hidden_fields as $fields)
{
foreach($fields as $field)
{
$form_data[$field['name']] = $field['value'];
}
}
// For reasoning behind the following command, see the test_post_new_topic() test
$form_data['lastclick'] = 0;
// Submit the post
$crawler = $this->client->request('POST', 'posting.php', $form_data);
$this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text());
$crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid);
$this->assertContains($test_message, $crawler->filter('html')->text());
} }
} }