mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 12:28:52 +00:00
Merge pull request #6526 from marc1706/ticket/17029
[ticket/17029] Update post count when changing post visibility
This commit is contained in:
commit
42bf5778d5
5 changed files with 188 additions and 23 deletions
|
@ -1345,7 +1345,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $
|
||||||
{
|
{
|
||||||
$post_mode = 'delete_first_post';
|
$post_mode = 'delete_first_post';
|
||||||
}
|
}
|
||||||
else if ($data['topic_last_post_id'] == $post_id)
|
else if ($data['topic_last_post_id'] <= $post_id)
|
||||||
{
|
{
|
||||||
$post_mode = 'delete_last_post';
|
$post_mode = 'delete_last_post';
|
||||||
}
|
}
|
||||||
|
@ -2872,7 +2872,14 @@ function phpbb_handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $
|
||||||
$delete_reason
|
$delete_reason
|
||||||
));
|
));
|
||||||
|
|
||||||
|
if ($next_post_id > 0)
|
||||||
|
{
|
||||||
$meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "p=$next_post_id") . "#p$next_post_id";
|
$meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "p=$next_post_id") . "#p$next_post_id";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t=$topic_id");
|
||||||
|
}
|
||||||
$message = $user->lang['POST_DELETED'];
|
$message = $user->lang['POST_DELETED'];
|
||||||
|
|
||||||
if (!$request->is_ajax())
|
if (!$request->is_ajax())
|
||||||
|
|
|
@ -501,11 +501,15 @@ class content_visibility
|
||||||
$postcounts[$num_posts][] = $poster_id;
|
$postcounts[$num_posts][] = $poster_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$postcount_change = 0;
|
||||||
|
|
||||||
// Update users postcounts
|
// Update users postcounts
|
||||||
foreach ($postcounts as $num_posts => $poster_ids)
|
foreach ($postcounts as $num_posts => $poster_ids)
|
||||||
{
|
{
|
||||||
if (in_array($visibility, array(ITEM_REAPPROVE, ITEM_DELETED)))
|
if (in_array($visibility, array(ITEM_REAPPROVE, ITEM_DELETED)))
|
||||||
{
|
{
|
||||||
|
$postcount_change -= $num_posts;
|
||||||
|
|
||||||
$sql = 'UPDATE ' . $this->users_table . '
|
$sql = 'UPDATE ' . $this->users_table . '
|
||||||
SET user_posts = 0
|
SET user_posts = 0
|
||||||
WHERE ' . $this->db->sql_in_set('user_id', $poster_ids) . '
|
WHERE ' . $this->db->sql_in_set('user_id', $poster_ids) . '
|
||||||
|
@ -520,6 +524,8 @@ class content_visibility
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$postcount_change += $num_posts;
|
||||||
|
|
||||||
$sql = 'UPDATE ' . $this->users_table . '
|
$sql = 'UPDATE ' . $this->users_table . '
|
||||||
SET user_posts = user_posts + ' . $num_posts . '
|
SET user_posts = user_posts + ' . $num_posts . '
|
||||||
WHERE ' . $this->db->sql_in_set('user_id', $poster_ids);
|
WHERE ' . $this->db->sql_in_set('user_id', $poster_ids);
|
||||||
|
@ -527,6 +533,11 @@ class content_visibility
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($postcount_change != 0)
|
||||||
|
{
|
||||||
|
$this->config->increment('num_posts', $postcount_change, false);
|
||||||
|
}
|
||||||
|
|
||||||
$update_topic_postcount = true;
|
$update_topic_postcount = true;
|
||||||
|
|
||||||
// Sync the first/last topic information if needed
|
// Sync the first/last topic information if needed
|
||||||
|
|
|
@ -45,6 +45,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||||
'post_time' => 2,
|
'post_time' => 2,
|
||||||
)),
|
)),
|
||||||
false, 'harddelete',
|
false, 'harddelete',
|
||||||
|
3, // expected next post id
|
||||||
array(
|
array(
|
||||||
array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
//array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
//array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
|
@ -74,6 +75,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||||
'post_time' => 1,
|
'post_time' => 1,
|
||||||
)),
|
)),
|
||||||
false, 'harddelete',
|
false, 'harddelete',
|
||||||
|
2, // expected next post id
|
||||||
array(
|
array(
|
||||||
//array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
//array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
|
@ -103,6 +105,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||||
'post_time' => 3,
|
'post_time' => 3,
|
||||||
)),
|
)),
|
||||||
false, 'harddelete',
|
false, 'harddelete',
|
||||||
|
2, // expected next post id
|
||||||
array(
|
array(
|
||||||
array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
|
@ -132,6 +135,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||||
'post_time' => 2,
|
'post_time' => 2,
|
||||||
)),
|
)),
|
||||||
true, 'soft delete',
|
true, 'soft delete',
|
||||||
|
3, // expected next post id
|
||||||
array(
|
array(
|
||||||
array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
array('post_id' => 2, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'soft delete'),
|
array('post_id' => 2, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'soft delete'),
|
||||||
|
@ -161,6 +165,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||||
'post_time' => 1,
|
'post_time' => 1,
|
||||||
)),
|
)),
|
||||||
true, 'soft delete',
|
true, 'soft delete',
|
||||||
|
2, // expected next post id
|
||||||
array(
|
array(
|
||||||
array('post_id' => 1, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'soft delete'),
|
array('post_id' => 1, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'soft delete'),
|
||||||
array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
|
@ -190,6 +195,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||||
'post_time' => 3,
|
'post_time' => 3,
|
||||||
)),
|
)),
|
||||||
true, 'soft delete',
|
true, 'soft delete',
|
||||||
|
3, // expected next post id
|
||||||
array(
|
array(
|
||||||
array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
|
@ -230,6 +236,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||||
'post_reported' => false,
|
'post_reported' => false,
|
||||||
),
|
),
|
||||||
false, 'harddelete',
|
false, 'harddelete',
|
||||||
|
false, // expected next post id
|
||||||
array(
|
array(
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
@ -258,6 +265,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||||
'post_reported' => false,
|
'post_reported' => false,
|
||||||
),
|
),
|
||||||
true, 'soft delete',
|
true, 'soft delete',
|
||||||
|
false, // expected next post id
|
||||||
array(
|
array(
|
||||||
array('post_id' => 4, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => ''),
|
array('post_id' => 4, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => ''),
|
||||||
),
|
),
|
||||||
|
@ -279,13 +287,93 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||||
array('user_posts' => 3),
|
array('user_posts' => 3),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
// Delete actual last post that is unapproved
|
||||||
|
array(
|
||||||
|
3, 3, 6,
|
||||||
|
array(
|
||||||
|
'topic_first_post_id' => 5,
|
||||||
|
'topic_last_post_id' => 5,
|
||||||
|
'topic_posts_approved' => 1,
|
||||||
|
'topic_posts_unapproved' => 1,
|
||||||
|
'topic_posts_softdeleted' => 0,
|
||||||
|
'topic_visibility' => ITEM_APPROVED,
|
||||||
|
'post_time' => 4,
|
||||||
|
'post_visibility' => ITEM_UNAPPROVED,
|
||||||
|
'post_postcount' => true,
|
||||||
|
'poster_id' => 1,
|
||||||
|
'post_reported' => false,
|
||||||
|
),
|
||||||
|
false, 'harddelete',
|
||||||
|
5, // expected next post id
|
||||||
|
array(
|
||||||
|
array('post_id' => 5, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
|
// array('post_id' => 6, 'post_visibility' => ITEM_UNAPPROVED, 'post_delete_reason' => ''),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'topic_visibility' => ITEM_APPROVED,
|
||||||
|
'topic_first_post_id' => 5,
|
||||||
|
'topic_last_post_id' => 5,
|
||||||
|
'topic_posts_approved' => 1,
|
||||||
|
'topic_posts_unapproved' => 0,
|
||||||
|
'topic_posts_softdeleted' => 0,
|
||||||
|
'topic_delete_reason' => '',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
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' => 5),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('user_posts' => 4),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Hard delete last approved post
|
||||||
|
array(
|
||||||
|
3, 3, 5,
|
||||||
|
array(
|
||||||
|
'topic_first_post_id' => 5,
|
||||||
|
'topic_last_post_id' => 5,
|
||||||
|
'topic_posts_approved' => 1,
|
||||||
|
'topic_posts_unapproved' => 1,
|
||||||
|
'topic_posts_softdeleted' => 0,
|
||||||
|
'topic_visibility' => ITEM_APPROVED,
|
||||||
|
'post_time' => 4,
|
||||||
|
'post_visibility' => ITEM_APPROVED,
|
||||||
|
'post_postcount' => true,
|
||||||
|
'poster_id' => 1,
|
||||||
|
'post_reported' => false,
|
||||||
|
),
|
||||||
|
false, 'harddelete',
|
||||||
|
6, // expected next post id
|
||||||
|
array(
|
||||||
|
//array('post_id' => 5, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
|
array('post_id' => 6, 'post_visibility' => ITEM_UNAPPROVED, 'post_delete_reason' => ''),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'topic_visibility' => ITEM_APPROVED,
|
||||||
|
'topic_first_post_id' => 6,
|
||||||
|
'topic_last_post_id' => 5, // can't be updated with no valid data
|
||||||
|
'topic_posts_approved' => 0,
|
||||||
|
'topic_posts_unapproved' => 1,
|
||||||
|
'topic_posts_softdeleted' => 0,
|
||||||
|
'topic_delete_reason' => '',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('forum_posts_approved' => 0, 'forum_posts_unapproved' => 1, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 5),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('user_posts' => 3),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider delete_post_data
|
* @dataProvider delete_post_data
|
||||||
*/
|
*/
|
||||||
public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason, $expected_posts, $expected_topic, $expected_forum, $expected_user)
|
public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason, $expected_next_post_id, $expected_posts, $expected_topic, $expected_forum, $expected_user)
|
||||||
{
|
{
|
||||||
global $auth, $cache, $config, $db, $user, $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
|
global $auth, $cache, $config, $db, $user, $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
|
||||||
|
|
||||||
|
@ -321,7 +409,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||||
// Works as a workaround for tests
|
// Works as a workaround for tests
|
||||||
$phpbb_container->set('attachment.manager', $attachment_delete);
|
$phpbb_container->set('attachment.manager', $attachment_delete);
|
||||||
|
|
||||||
delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason);
|
$this->assertSame($expected_next_post_id, delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason));
|
||||||
|
|
||||||
$result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason
|
$result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason
|
||||||
FROM phpbb_posts
|
FROM phpbb_posts
|
||||||
|
|
|
@ -39,6 +39,19 @@
|
||||||
<value></value>
|
<value></value>
|
||||||
<value></value>
|
<value></value>
|
||||||
</row>
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>3</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>5</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
</table>
|
</table>
|
||||||
<table name="phpbb_topics">
|
<table name="phpbb_topics">
|
||||||
<column>topic_id</column>
|
<column>topic_id</column>
|
||||||
|
@ -82,6 +95,20 @@
|
||||||
<value>0</value>
|
<value>0</value>
|
||||||
<value>0</value>
|
<value>0</value>
|
||||||
</row>
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>3</value>
|
||||||
|
<value>3</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>Approved</value>
|
||||||
|
<value>5</value>
|
||||||
|
<value>5</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value></value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>0</value>
|
||||||
|
</row>
|
||||||
</table>
|
</table>
|
||||||
<table name="phpbb_posts">
|
<table name="phpbb_posts">
|
||||||
<column>post_id</column>
|
<column>post_id</column>
|
||||||
|
@ -130,7 +157,6 @@
|
||||||
<value>0</value>
|
<value>0</value>
|
||||||
<value></value>
|
<value></value>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<value>4</value>
|
<value>4</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
|
@ -143,6 +169,30 @@
|
||||||
<value>0</value>
|
<value>0</value>
|
||||||
<value></value>
|
<value></value>
|
||||||
</row>
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>5</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>3</value>
|
||||||
|
<value>3</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>4</value>
|
||||||
|
<value>Approved</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>6</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>3</value>
|
||||||
|
<value>3</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>4</value>
|
||||||
|
<value>Unpproved</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
</table>
|
</table>
|
||||||
<table name="phpbb_users">
|
<table name="phpbb_users">
|
||||||
<column>user_id</column>
|
<column>user_id</column>
|
||||||
|
|
|
@ -30,8 +30,8 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t
|
||||||
2, time(), 'approve',
|
2, time(), 'approve',
|
||||||
true, false,
|
true, false,
|
||||||
array(
|
array(
|
||||||
array('post_id' => 1, 'post_visibility' => 1, 'post_delete_reason' => 'approve'),
|
array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => 'approve'),
|
||||||
array('post_id' => 2, 'post_visibility' => 1, 'post_delete_reason' => ''),
|
array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''),
|
array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
@ -44,9 +44,9 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t
|
||||||
2, time(), 'approve',
|
2, time(), 'approve',
|
||||||
false, true,
|
false, true,
|
||||||
array(
|
array(
|
||||||
array('post_id' => 1, 'post_visibility' => 0, 'post_delete_reason' => ''),
|
array('post_id' => 1, 'post_visibility' => ITEM_UNAPPROVED, 'post_delete_reason' => ''),
|
||||||
array('post_id' => 2, 'post_visibility' => 1, 'post_delete_reason' => ''),
|
array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
array('post_id' => 3, 'post_visibility' => 1, 'post_delete_reason' => 'approve'),
|
array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => 'approve'),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array('topic_visibility' => 1, 'topic_first_post_id' => 2, 'topic_last_post_id' => 3),
|
array('topic_visibility' => 1, 'topic_first_post_id' => 2, 'topic_last_post_id' => 3),
|
||||||
|
@ -58,7 +58,7 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t
|
||||||
2, time(), 'deleted',
|
2, time(), 'deleted',
|
||||||
true, true,
|
true, true,
|
||||||
array(
|
array(
|
||||||
array('post_id' => 1, 'post_visibility' => 0, 'post_delete_reason' => ''),
|
array('post_id' => 1, 'post_visibility' => ITEM_UNAPPROVED, 'post_delete_reason' => ''),
|
||||||
array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'),
|
array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'),
|
||||||
array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''),
|
array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''),
|
||||||
),
|
),
|
||||||
|
@ -72,10 +72,10 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t
|
||||||
2, time(), 'deleted',
|
2, time(), 'deleted',
|
||||||
true, false,
|
true, false,
|
||||||
array(
|
array(
|
||||||
array('post_id' => 4, 'post_visibility' => 0, 'post_delete_reason' => ''),
|
array('post_id' => 4, 'post_visibility' => ITEM_UNAPPROVED, 'post_delete_reason' => ''),
|
||||||
array('post_id' => 5, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'),
|
array('post_id' => 5, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'deleted'),
|
||||||
array('post_id' => 6, 'post_visibility' => 1, 'post_delete_reason' => ''),
|
array('post_id' => 6, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
array('post_id' => 7, 'post_visibility' => 2, 'post_delete_reason' => ''),
|
array('post_id' => 7, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => ''),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array('topic_visibility' => 1, 'topic_first_post_id' => 6, 'topic_last_post_id' => 6),
|
array('topic_visibility' => 1, 'topic_first_post_id' => 6, 'topic_last_post_id' => 6),
|
||||||
|
@ -87,10 +87,10 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t
|
||||||
2, time(), 'deleted',
|
2, time(), 'deleted',
|
||||||
false, true,
|
false, true,
|
||||||
array(
|
array(
|
||||||
array('post_id' => 4, 'post_visibility' => 0, 'post_delete_reason' => ''),
|
array('post_id' => 4, 'post_visibility' => ITEM_UNAPPROVED, 'post_delete_reason' => ''),
|
||||||
array('post_id' => 5, 'post_visibility' => 1, 'post_delete_reason' => ''),
|
array('post_id' => 5, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||||
array('post_id' => 6, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'),
|
array('post_id' => 6, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'deleted'),
|
||||||
array('post_id' => 7, 'post_visibility' => 2, 'post_delete_reason' => ''),
|
array('post_id' => 7, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => ''),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array('topic_visibility' => 1, 'topic_first_post_id' => 5, 'topic_last_post_id' => 5),
|
array('topic_visibility' => 1, 'topic_first_post_id' => 5, 'topic_last_post_id' => 5),
|
||||||
|
@ -102,7 +102,7 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t
|
||||||
2, time(), 'deleted',
|
2, time(), 'deleted',
|
||||||
true, true,
|
true, true,
|
||||||
array(
|
array(
|
||||||
array('post_id' => 8, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'),
|
array('post_id' => 8, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'deleted'),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array('topic_visibility' => 2, 'topic_first_post_id' => 8, 'topic_last_post_id' => 8),
|
array('topic_visibility' => 2, 'topic_first_post_id' => 8, 'topic_last_post_id' => 8),
|
||||||
|
@ -116,7 +116,7 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t
|
||||||
*/
|
*/
|
||||||
public function test_set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $expected, $expected_topic)
|
public function test_set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $expected, $expected_topic)
|
||||||
{
|
{
|
||||||
global $cache, $db, $auth, $phpbb_root_path, $phpEx;
|
global $cache, $db, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
|
||||||
|
|
||||||
$cache = new phpbb_mock_cache;
|
$cache = new phpbb_mock_cache;
|
||||||
$db = $this->new_dbal();
|
$db = $this->new_dbal();
|
||||||
|
@ -124,7 +124,8 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t
|
||||||
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
|
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
|
||||||
$lang = new \phpbb\language\language($lang_loader);
|
$lang = new \phpbb\language\language($lang_loader);
|
||||||
$user = new \phpbb\user($lang, '\phpbb\datetime');
|
$user = new \phpbb\user($lang, '\phpbb\datetime');
|
||||||
$config = new phpbb\config\config(array());
|
$before_posts = 5;
|
||||||
|
$config = new phpbb\config\config(['num_posts' => $before_posts]);
|
||||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
$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);
|
$content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
||||||
|
|
||||||
|
@ -144,6 +145,14 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t
|
||||||
|
|
||||||
$this->assertEquals($expected_topic, $db->sql_fetchrowset($result));
|
$this->assertEquals($expected_topic, $db->sql_fetchrowset($result));
|
||||||
$db->sql_freeresult($result);
|
$db->sql_freeresult($result);
|
||||||
|
if ($visibility == ITEM_APPROVED)
|
||||||
|
{
|
||||||
|
$this->assertEquals($before_posts + 1, $config['num_posts'], 'Number of posts did not increment as expected');
|
||||||
|
}
|
||||||
|
else if ($visibility == ITEM_DELETED)
|
||||||
|
{
|
||||||
|
$this->assertEquals($before_posts - 1, $config['num_posts'], 'Number of posts did not increment as expected');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_post_soft_deleted_data()
|
public function set_post_soft_deleted_data()
|
||||||
|
@ -169,7 +178,7 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t
|
||||||
*/
|
*/
|
||||||
public function test_set_post_soft_deleted($post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $expected)
|
public function test_set_post_soft_deleted($post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $expected)
|
||||||
{
|
{
|
||||||
global $cache, $db, $auth, $phpbb_root_path, $phpEx;
|
global $cache, $db, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
|
||||||
|
|
||||||
$cache = new phpbb_mock_cache;
|
$cache = new phpbb_mock_cache;
|
||||||
$db = $this->new_dbal();
|
$db = $this->new_dbal();
|
||||||
|
|
Loading…
Add table
Reference in a new issue