[feature/soft-delete] Fix unit tests for delete_posts()

PHPBB3-9567
This commit is contained in:
Joas Schilling 2012-10-23 23:37:25 +02:00
parent 3236229188
commit b3d5f2b4e4
3 changed files with 79 additions and 17 deletions

View file

@ -348,34 +348,75 @@ class phpbb_content_visibility
// Update the topic's reply count and the forum's post count
if ($update_topic_postcount)
{
$num_posts = 0;
$cur_posts = $cur_unapproved_posts = $cur_softdeleted_posts = 0;
foreach ($postcount_visibility as $post_visibility => $visibility_posts)
{
// If we soft delete, we need to substract approved posts from the counters ...
if ($post_visibility == ITEM_APPROVED && $visibility == ITEM_DELETED)
// We need to substract the posts from the counters ...
if ($post_visibility == ITEM_APPROVED)
{
$num_posts += $visibility_posts;
$cur_posts += $visibility_posts;
}
// ... and when we approve/restore, all others.
else if ($post_visibility != ITEM_APPROVED && $visibility == ITEM_APPROVED)
else if ($post_visibility == ITEM_UNAPPROVED)
{
$num_posts += $visibility_posts;
$cur_unapproved_posts += $visibility_posts;
}
else if ($post_visibility == ITEM_DELETED)
{
$cur_softdeleted_posts += $visibility_posts;
}
}
if ($num_posts)
$sql_ary = array();
if ($visibility == ITEM_DELETED)
{
$sql_num_posts = (($visibility == ITEM_DELETED) ? ' - ' : ' + ') . $num_posts;
if ($cur_posts)
{
$sql_ary['posts'] = ' - ' . $cur_posts;
}
if ($cur_unapproved_posts)
{
$sql_ary['posts_unapproved'] = ' - ' . $cur_unapproved_posts;
}
if ($cur_posts + $cur_unapproved_posts)
{
$sql_ary['posts_softdeleted'] = ' + ' . ($cur_posts + $cur_unapproved_posts);
}
}
else
{
if ($cur_unapproved_posts)
{
$sql_ary['posts_unapproved'] = ' - ' . $cur_unapproved_posts;
}
if ($cur_softdeleted_posts)
{
$sql_ary['posts_softdeleted'] = ' - ' . $cur_softdeleted_posts;
}
if ($cur_posts + $cur_unapproved_posts)
{
$sql_ary['posts'] = ' + ' . ($cur_softdeleted_posts + $cur_unapproved_posts);
}
}
if (sizeof($sql_ary))
{
$topic_sql = $forum_sql = array();
foreach ($sql_ary as $field => $value_change)
{
$topic_sql[] = 'topic_' . $field . ' = topic_' . $field . $value_change;
$forum_sql[] = 'forum_' . $field . ' = forum_' . $field . $value_change;
}
// Update the number for replies and posts
$sql = 'UPDATE ' . TOPICS_TABLE . "
SET topic_replies = topic_replies $sql_num_posts
WHERE topic_id = $topic_id";
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET ' . implode(', ', $topic_sql) . '
WHERE topic_id = ' . $topic_id;
$db->sql_query($sql);
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET forum_posts = forum_posts $sql_num_posts
WHERE forum_id = $forum_id";
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET ' . implode(', ', $forum_sql) . '
WHERE forum_id = ' . $forum_id;
$db->sql_query($sql);
}
}

View file

@ -1729,7 +1729,6 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$sql = 'SELECT SUM(t.topic_posts) AS forum_posts, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted
FROM ' . TOPICS_TABLE . ' t
WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . '
AND t.topic_visibility = ' . ITEM_APPROVED . '
AND t.topic_status <> ' . ITEM_MOVED;
}
else
@ -1737,7 +1736,6 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$sql = 'SELECT t.forum_id, SUM(t.topic_posts) AS forum_posts, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted
FROM ' . TOPICS_TABLE . ' t
WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . '
AND t.topic_visibility = ' . ITEM_APPROVED . '
AND t.topic_status <> ' . ITEM_MOVED . '
GROUP BY t.forum_id';
}

23
tests/mock/search.php Normal file
View file

@ -0,0 +1,23 @@
<?php
/**
*
* @package testing
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
*/
class phpbb_mock_search
{
public function __construct($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user)
{
}
public function index_remove($post_ids, $poster_ids, $forum_ids)
{
}
}