mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 21:38:54 +00:00
[feature/soft-delete] Add some unit tests for delete_post()
PHPBB3-9567
This commit is contained in:
parent
009bd698fb
commit
7c09b5b89c
2 changed files with 353 additions and 0 deletions
236
tests/content_visibility/delete_post_test.php
Normal file
236
tests/content_visibility/delete_post_test.php
Normal file
|
@ -0,0 +1,236 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
|
||||
require_once dirname(__FILE__) . '/../mock/search.php';
|
||||
|
||||
class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/delete_post.xml');
|
||||
}
|
||||
|
||||
public function delete_post_data()
|
||||
{
|
||||
$info_data = array(
|
||||
'topic_first_post_id' => 1,
|
||||
'topic_last_post_id' => 3,
|
||||
'topic_replies_real' => 3,
|
||||
'topic_visibility' => ITEM_APPROVED,
|
||||
'post_time' => 2,
|
||||
'post_visibility' => ITEM_APPROVED,
|
||||
'post_postcount' => true,
|
||||
'poster_id' => 1,
|
||||
'post_reported' => false,
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
1, 1, 2,
|
||||
array_merge($info_data, array(
|
||||
'post_time' => 2,
|
||||
)),
|
||||
false, 'harddelete',
|
||||
array(
|
||||
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' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'topic_visibility' => ITEM_APPROVED,
|
||||
'topic_first_post_id' => 1,
|
||||
'topic_last_post_id' => 3,
|
||||
'topic_replies' => 1,
|
||||
'topic_replies_real' => 1,
|
||||
'topic_delete_reason' => '',
|
||||
),
|
||||
),
|
||||
array(
|
||||
array('forum_posts' => 2, 'forum_topics' => 1, 'forum_topics_real' => 1, 'forum_last_post_id' => 3),
|
||||
),
|
||||
),
|
||||
array(
|
||||
1, 1, 1,
|
||||
array_merge($info_data, array(
|
||||
'post_time' => 1,
|
||||
)),
|
||||
false, 'harddelete',
|
||||
array(
|
||||
//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' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'topic_visibility' => ITEM_APPROVED,
|
||||
'topic_first_post_id' => 2,
|
||||
'topic_last_post_id' => 3,
|
||||
'topic_replies' => 1,
|
||||
'topic_replies_real' => 1,
|
||||
'topic_delete_reason' => '',
|
||||
),
|
||||
),
|
||||
array(
|
||||
array('forum_posts' => 2, 'forum_topics' => 1, 'forum_topics_real' => 1, 'forum_last_post_id' => 3),
|
||||
),
|
||||
),
|
||||
array(
|
||||
1, 1, 3,
|
||||
array_merge($info_data, array(
|
||||
'post_time' => 3,
|
||||
)),
|
||||
false, 'harddelete',
|
||||
array(
|
||||
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' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'topic_visibility' => ITEM_APPROVED,
|
||||
'topic_first_post_id' => 1,
|
||||
'topic_last_post_id' => 2,
|
||||
'topic_replies' => 1,
|
||||
'topic_replies_real' => 1,
|
||||
'topic_delete_reason' => '',
|
||||
),
|
||||
),
|
||||
array(
|
||||
array('forum_posts' => 2, 'forum_topics' => 1, 'forum_topics_real' => 1, 'forum_last_post_id' => 2),
|
||||
),
|
||||
),
|
||||
array(
|
||||
1, 1, 2,
|
||||
array_merge($info_data, array(
|
||||
'post_time' => 2,
|
||||
)),
|
||||
true, 'soft delete',
|
||||
array(
|
||||
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' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'topic_visibility' => ITEM_APPROVED,
|
||||
'topic_first_post_id' => 1,
|
||||
'topic_last_post_id' => 3,
|
||||
'topic_replies' => 1,
|
||||
'topic_replies_real' => 2,
|
||||
'topic_delete_reason' => '',
|
||||
),
|
||||
),
|
||||
array(
|
||||
array('forum_posts' => 2, 'forum_topics' => 1, 'forum_topics_real' => 1, 'forum_last_post_id' => 3),
|
||||
),
|
||||
),
|
||||
array(
|
||||
1, 1, 1,
|
||||
array_merge($info_data, array(
|
||||
'post_time' => 1,
|
||||
)),
|
||||
true, 'soft delete',
|
||||
array(
|
||||
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' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'topic_visibility' => ITEM_APPROVED,
|
||||
'topic_first_post_id' => 2,
|
||||
'topic_last_post_id' => 3,
|
||||
'topic_replies' => 1,
|
||||
'topic_replies_real' => 2,
|
||||
'topic_delete_reason' => '',
|
||||
),
|
||||
),
|
||||
array(
|
||||
array('forum_posts' => 2, 'forum_topics' => 1, 'forum_topics_real' => 1, 'forum_last_post_id' => 3),
|
||||
),
|
||||
),
|
||||
array(
|
||||
1, 1, 3,
|
||||
array_merge($info_data, array(
|
||||
'post_time' => 3,
|
||||
)),
|
||||
true, 'soft delete',
|
||||
array(
|
||||
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' => 3, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'soft delete'),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'topic_visibility' => ITEM_APPROVED,
|
||||
'topic_first_post_id' => 1,
|
||||
'topic_last_post_id' => 2,
|
||||
'topic_replies' => 1,
|
||||
'topic_replies_real' => 2,
|
||||
'topic_delete_reason' => '',
|
||||
),
|
||||
),
|
||||
array(
|
||||
array('forum_posts' => 2, 'forum_topics' => 1, 'forum_topics_real' => 1, 'forum_last_post_id' => 2),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
global $auth, $config, $db;
|
||||
|
||||
$config['search_type'] = 'phpbb_mock_search';
|
||||
$db = $this->new_dbal();
|
||||
set_config_count(null, null, null, new phpbb_config(array('num_posts' => 3, 'num_topics' => 1)));
|
||||
|
||||
// Create auth mock
|
||||
$auth = $this->getMock('phpbb_auth');
|
||||
$auth->expects($this->any())
|
||||
->method('acl_get')
|
||||
->with($this->stringContains('_'), $this->anything())
|
||||
->will($this->returnValueMap(array(
|
||||
array('m_approve', 1, true),
|
||||
)));
|
||||
|
||||
delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason);
|
||||
|
||||
$result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason
|
||||
FROM phpbb_posts
|
||||
WHERE topic_id = ' . $topic_id . '
|
||||
ORDER BY post_id ASC');
|
||||
|
||||
$this->assertEquals($expected_posts, $db->sql_fetchrowset($result));
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$result = $db->sql_query('SELECT topic_visibility, topic_first_post_id, topic_last_post_id, topic_replies, topic_replies_real, topic_delete_reason
|
||||
FROM phpbb_topics
|
||||
WHERE topic_id = ' . $topic_id);
|
||||
|
||||
$this->assertEquals($expected_topic, $db->sql_fetchrowset($result));
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$result = $db->sql_query('SELECT forum_posts, forum_topics, forum_topics_real, forum_last_post_id
|
||||
FROM phpbb_forums
|
||||
WHERE forum_id = ' . $forum_id);
|
||||
|
||||
$this->assertEquals($expected_forum, $db->sql_fetchrowset($result));
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
}
|
117
tests/content_visibility/fixtures/delete_post.xml
Normal file
117
tests/content_visibility/fixtures/delete_post.xml
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_forums">
|
||||
<column>forum_id</column>
|
||||
<column>forum_posts</column>
|
||||
<column>forum_topics</column>
|
||||
<column>forum_topics_real</column>
|
||||
<column>forum_last_post_id</column>
|
||||
<column>forum_desc</column>
|
||||
<column>forum_rules</column>
|
||||
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>3</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>3</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_topics">
|
||||
<column>topic_id</column>
|
||||
<column>forum_id</column>
|
||||
<column>topic_visibility</column>
|
||||
<column>topic_title</column>
|
||||
<column>topic_first_post_id</column>
|
||||
<column>topic_last_post_id</column>
|
||||
<column>topic_delete_user</column>
|
||||
<column>topic_delete_time</column>
|
||||
<column>topic_delete_reason</column>
|
||||
<column>topic_replies</column>
|
||||
<column>topic_replies_real</column>
|
||||
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>Approved</value>
|
||||
<value>1</value>
|
||||
<value>3</value>
|
||||
<value>0</value>
|
||||
<value>0</value>
|
||||
<value></value>
|
||||
<value>2</value>
|
||||
<value>2</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_posts">
|
||||
<column>post_id</column>
|
||||
<column>poster_id</column>
|
||||
<column>topic_id</column>
|
||||
<column>forum_id</column>
|
||||
<column>post_visibility</column>
|
||||
<column>post_time</column>
|
||||
<column>post_text</column>
|
||||
<column>post_delete_user</column>
|
||||
<column>post_delete_time</column>
|
||||
<column>post_delete_reason</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>Approved</value>
|
||||
<value>0</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>Approved</value>
|
||||
<value>0</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>3</value>
|
||||
<value>Approved</value>
|
||||
<value>0</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_users">
|
||||
<column>user_id</column>
|
||||
<column>user_posts</column>
|
||||
<column>username</column>
|
||||
<column>username_clean</column>
|
||||
<column>user_permissions</column>
|
||||
<column>user_sig</column>
|
||||
<column>user_occ</column>
|
||||
<column>user_interests</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>user 1</value>
|
||||
<value>user 1</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
Loading…
Add table
Reference in a new issue