diff options
Diffstat (limited to 'tests/content_visibility')
11 files changed, 1573 insertions, 0 deletions
diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php new file mode 100644 index 0000000000..b2bdcb3b49 --- /dev/null +++ b/tests/content_visibility/delete_post_test.php @@ -0,0 +1,310 @@ +<?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_posts_approved' => 3, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 0, + '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_posts_approved' => 2, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 0, + 'topic_delete_reason' => '', + ), + ), + array( + array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, '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_posts_approved' => 2, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 0, + 'topic_delete_reason' => '', + ), + ), + array( + array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, '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_posts_approved' => 2, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 0, + 'topic_delete_reason' => '', + ), + ), + array( + array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, '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_posts_approved' => 2, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 1, + 'topic_delete_reason' => '', + ), + ), + array( + array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, '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_posts_approved' => 2, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 1, + 'topic_delete_reason' => '', + ), + ), + array( + array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, '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_posts_approved' => 2, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 1, + 'topic_delete_reason' => '', + ), + ), + array( + array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 2), + ), + ), + + array( + 2, 2, 4, + array( + 'topic_first_post_id' => 4, + 'topic_last_post_id' => 4, + 'topic_posts_approved' => 1, + 'topic_posts_unapproved' => 0, + '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', + array( + ), + array( + ), + array( + 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), + ), + ), + + array( + 2, 2, 4, + array( + 'topic_first_post_id' => 4, + 'topic_last_post_id' => 4, + 'topic_posts_approved' => 1, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 0, + 'topic_visibility' => ITEM_APPROVED, + 'post_time' => 4, + 'post_visibility' => ITEM_APPROVED, + 'post_postcount' => true, + 'poster_id' => 1, + 'post_reported' => false, + ), + true, 'soft delete', + array( + array('post_id' => 4, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => ''), + ), + array( + array( + 'topic_visibility' => ITEM_DELETED, + 'topic_first_post_id' => 4, + 'topic_last_post_id' => 4, + 'topic_posts_approved' => 0, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 1, + 'topic_delete_reason' => 'soft delete', + ), + ), + array( + array('forum_posts_approved' => 0, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 0, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 1, 'forum_last_post_id' => 0), + ), + ), + ); + } + + /** + * @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, $cache, $config, $db, $phpbb_container, $phpbb_root_path, $phpEx; + + $config['search_type'] = 'phpbb_mock_search'; + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + set_config_count(null, null, null, new \phpbb\config\config(array('num_posts' => 3, 'num_topics' => 1))); + + // Create auth mock + $auth = $this->getMock('\phpbb\auth\auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), $this->anything()) + ->will($this->returnValueMap(array( + array('m_approve', 1, true), + ))); + $user = $this->getMock('\phpbb\user'); + + $phpbb_container = new phpbb_mock_container_builder(); + $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); + $phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); + + 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_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, 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_approved, forum_posts_unapproved, forum_posts_softdeleted, forum_topics_approved, forum_topics_unapproved, forum_topics_softdeleted, forum_last_post_id + FROM phpbb_forums + WHERE forum_id = ' . $forum_id); + + $this->assertEquals($expected_forum, $db->sql_fetchrowset($result)); + $db->sql_freeresult($result); + } +} diff --git a/tests/content_visibility/fixtures/delete_post.xml b/tests/content_visibility/fixtures/delete_post.xml new file mode 100644 index 0000000000..c29ad23019 --- /dev/null +++ b/tests/content_visibility/fixtures/delete_post.xml @@ -0,0 +1,163 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_forums"> + <column>forum_id</column> + <column>forum_posts_approved</column> + <column>forum_posts_unapproved</column> + <column>forum_posts_softdeleted</column> + <column>forum_topics_approved</column> + <column>forum_topics_unapproved</column> + <column>forum_topics_softdeleted</column> + <column>forum_last_post_id</column> + <column>forum_parents</column> + <column>forum_desc</column> + <column>forum_rules</column> + + <row> + <value>1</value> + <value>3</value> + <value>0</value> + <value>0</value> + <value>1</value> + <value>0</value> + <value>0</value> + <value>3</value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>0</value> + <value>0</value> + <value>1</value> + <value>0</value> + <value>0</value> + <value>4</value> + <value></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_posts_approved</column> + <column>topic_posts_unapproved</column> + <column>topic_posts_softdeleted</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>3</value> + <value>0</value> + <value>0</value> + </row> + <row> + <value>2</value> + <value>2</value> + <value>1</value> + <value>Approved</value> + <value>4</value> + <value>4</value> + <value>0</value> + <value>0</value> + <value></value> + <value>1</value> + <value>0</value> + <value>0</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>0</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>0</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>0</value> + <value></value> + </row> + + <row> + <value>4</value> + <value>1</value> + <value>2</value> + <value>2</value> + <value>1</value> + <value>4</value> + <value>Approved</value> + <value>0</value> + <value>0</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> + <row> + <value>1</value> + <value>4</value> + <value>user 1</value> + <value>user 1</value> + <value></value> + <value></value> + </row> + </table> +</dataset> diff --git a/tests/content_visibility/fixtures/get_forums_visibility_sql.xml b/tests/content_visibility/fixtures/get_forums_visibility_sql.xml new file mode 100644 index 0000000000..658d34398f --- /dev/null +++ b/tests/content_visibility/fixtures/get_forums_visibility_sql.xml @@ -0,0 +1,133 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_topics"> + <column>topic_id</column> + <column>forum_id</column> + <column>topic_visibility</column> + <column>topic_title</column> + <row> + <value>1</value> + <value>1</value> + <value>0</value> + <value>Unapproved</value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>1</value> + <value>Approved</value> + </row> + <row> + <value>3</value> + <value>1</value> + <value>2</value> + <value>Softdeleted</value> + </row> + <row> + <value>4</value> + <value>2</value> + <value>0</value> + <value>Unapproved</value> + </row> + <row> + <value>5</value> + <value>2</value> + <value>1</value> + <value>Approved</value> + </row> + <row> + <value>6</value> + <value>2</value> + <value>2</value> + <value>Softdeleted</value> + </row> + <row> + <value>7</value> + <value>3</value> + <value>0</value> + <value>Unapproved</value> + </row> + <row> + <value>8</value> + <value>3</value> + <value>1</value> + <value>Approved</value> + </row> + <row> + <value>9</value> + <value>3</value> + <value>2</value> + <value>Softdeleted</value> + </row> + </table> + <table name="phpbb_posts"> + <column>post_id</column> + <column>topic_id</column> + <column>forum_id</column> + <column>post_visibility</column> + <column>post_text</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value>Unapproved</value> + </row> + <row> + <value>2</value> + <value>2</value> + <value>1</value> + <value>1</value> + <value>Approved</value> + </row> + <row> + <value>3</value> + <value>3</value> + <value>1</value> + <value>2</value> + <value>Softdeleted</value> + </row> + <row> + <value>4</value> + <value>4</value> + <value>2</value> + <value>0</value> + <value>Unapproved</value> + </row> + <row> + <value>5</value> + <value>5</value> + <value>2</value> + <value>1</value> + <value>Approved</value> + </row> + <row> + <value>6</value> + <value>6</value> + <value>2</value> + <value>2</value> + <value>Softdeleted</value> + </row> + <row> + <value>7</value> + <value>7</value> + <value>3</value> + <value>0</value> + <value>Unapproved</value> + </row> + <row> + <value>8</value> + <value>8</value> + <value>3</value> + <value>1</value> + <value>Approved</value> + </row> + <row> + <value>9</value> + <value>9</value> + <value>3</value> + <value>2</value> + <value>Softdeleted</value> + </row> + </table> +</dataset> diff --git a/tests/content_visibility/fixtures/get_visibility_sql.xml b/tests/content_visibility/fixtures/get_visibility_sql.xml new file mode 100644 index 0000000000..146244263e --- /dev/null +++ b/tests/content_visibility/fixtures/get_visibility_sql.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_topics"> + <column>topic_id</column> + <column>forum_id</column> + <column>topic_visibility</column> + <column>topic_title</column> + <row> + <value>1</value> + <value>1</value> + <value>0</value> + <value>Unapproved</value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>1</value> + <value>Approved</value> + </row> + <row> + <value>3</value> + <value>1</value> + <value>2</value> + <value>Softdeleted</value> + </row> + </table> + <table name="phpbb_posts"> + <column>post_id</column> + <column>topic_id</column> + <column>forum_id</column> + <column>post_visibility</column> + <column>post_text</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value>Unapproved</value> + </row> + <row> + <value>2</value> + <value>2</value> + <value>1</value> + <value>1</value> + <value>Approved</value> + </row> + <row> + <value>3</value> + <value>3</value> + <value>1</value> + <value>2</value> + <value>Softdeleted</value> + </row> + </table> +</dataset> diff --git a/tests/content_visibility/fixtures/set_post_visibility.xml b/tests/content_visibility/fixtures/set_post_visibility.xml new file mode 100644 index 0000000000..5f792d0f05 --- /dev/null +++ b/tests/content_visibility/fixtures/set_post_visibility.xml @@ -0,0 +1,154 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <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_posts_approved</column> + <column>topic_posts_softdeleted</column> + <column>topic_posts_unapproved</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value>Approved</value> + <value>2</value> + <value>2</value> + <value>1</value> + <value>1</value> + <value>1</value> + </row> + + <row> + <value>2</value> + <value>1</value> + <value>1</value> + <value>2 Approved posts</value> + <value>5</value> + <value>6</value> + <value>1</value> + <value>1</value> + <value>1</value> + </row> + + <row> + <value>3</value> + <value>1</value> + <value>1</value> + <value>Only 1 Approved posts</value> + <value>8</value> + <value>8</value> + <value>1</value> + <value>0</value> + <value>0</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_text</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value>Unapproved</value> + </row> + <row> + <value>2</value> + <value>2</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>Approved</value> + </row> + <row> + <value>3</value> + <value>3</value> + <value>1</value> + <value>1</value> + <value>2</value> + <value>Softdeleted</value> + </row> + + <row> + <value>4</value> + <value>1</value> + <value>2</value> + <value>1</value> + <value>0</value> + <value>Unapproved</value> + </row> + <row> + <value>5</value> + <value>2</value> + <value>2</value> + <value>1</value> + <value>1</value> + <value>Approved</value> + </row> + <row> + <value>6</value> + <value>2</value> + <value>2</value> + <value>1</value> + <value>1</value> + <value>Approved 2</value> + </row> + <row> + <value>7</value> + <value>3</value> + <value>2</value> + <value>1</value> + <value>2</value> + <value>Softdeleted</value> + </row> + <row> + <value>8</value> + <value>1</value> + <value>3</value> + <value>1</value> + <value>1</value> + <value>Approved</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> + <row> + <value>1</value> + <value>1</value> + <value>user 1</value> + <value>user 1</value> + <value></value> + <value></value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>user 2</value> + <value>user 2</value> + <value></value> + <value></value> + </row> + <row> + <value>3</value> + <value>1</value> + <value>user 3</value> + <value>user 3</value> + <value></value> + <value></value> + </row> + </table> +</dataset> diff --git a/tests/content_visibility/fixtures/set_topic_visibility.xml b/tests/content_visibility/fixtures/set_topic_visibility.xml new file mode 100644 index 0000000000..02ab5f16fe --- /dev/null +++ b/tests/content_visibility/fixtures/set_topic_visibility.xml @@ -0,0 +1,132 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <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> + + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value>Approved</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value>0</value> + <value></value> + </row> + + <row> + <value>2</value> + <value>1</value> + <value>2</value> + <value>Soft deleted</value> + <value>4</value> + <value>5</value> + <value>2</value> + <value>123</value> + <value></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_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>Approved</value> + <value>2</value> + <value>0</value> + <value></value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>2</value> + <value>Soft deleted</value> + <value>2</value> + <value>123</value> + <value>manually</value> + </row> + <row> + <value>3</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value>Unapproved</value> + <value>0</value> + <value>0</value> + <value></value> + </row> + + <row> + <value>4</value> + <value>1</value> + <value>2</value> + <value>1</value> + <value>2</value> + <value>Soft deleted by topic soft delete</value> + <value>2</value> + <value>123</value> + <value></value> + </row> + <row> + <value>5</value> + <value>1</value> + <value>2</value> + <value>1</value> + <value>2</value> + <value>Soft deleted before the topic was soft deleted</value> + <value>2</value> + <value>120</value> + <value>manually</value> + </row> + <row> + <value>6</value> + <value>1</value> + <value>2</value> + <value>1</value> + <value>0</value> + <value>Unapproved before the topic was soft deleted</value> + <value>0</value> + <value>0</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> + <row> + <value>1</value> + <value>6</value> + <value>user 1</value> + <value>user 1</value> + <value></value> + <value></value> + </row> + </table> +</dataset> diff --git a/tests/content_visibility/get_forums_visibility_sql_test.php b/tests/content_visibility/get_forums_visibility_sql_test.php new file mode 100644 index 0000000000..22f210c406 --- /dev/null +++ b/tests/content_visibility/get_forums_visibility_sql_test.php @@ -0,0 +1,143 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_content_visibility_get_forums_visibility_sql_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/get_forums_visibility_sql.xml'); + } + + public function get_forums_visibility_sql_data() + { + return array( + array( + 'phpbb_topics', + 'topic', array(1, 2, 3), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('topic_id' => 1), + array('topic_id' => 2), + array('topic_id' => 3), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 6), + array('topic_id' => 7), + array('topic_id' => 8), + array('topic_id' => 9), + ), + ), + array( + 'phpbb_topics', + 'topic', array(1, 2), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('topic_id' => 1), + array('topic_id' => 2), + array('topic_id' => 3), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 6), + ), + ), + array( + 'phpbb_topics', + 'topic', array(1, 2, 3), '', + array( + array('m_approve', true, array(2 => true)), + ), + array( + array('topic_id' => 2), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 6), + array('topic_id' => 8), + ), + ), + array( + 'phpbb_posts', + 'post', array(1, 2, 3), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('post_id' => 1), + array('post_id' => 2), + array('post_id' => 3), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 6), + array('post_id' => 7), + array('post_id' => 8), + array('post_id' => 9), + ), + ), + array( + 'phpbb_posts', + 'post', array(1, 2), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('post_id' => 1), + array('post_id' => 2), + array('post_id' => 3), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 6), + ), + ), + array( + 'phpbb_posts', + 'post', array(1, 2, 3), '', + array( + array('m_approve', true, array(2 => true)), + ), + array( + array('post_id' => 2), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 6), + array('post_id' => 8), + ), + ), + ); + } + + /** + * @dataProvider get_forums_visibility_sql_data + */ + public function test_get_forums_visibility_sql($table, $mode, $forum_ids, $table_alias, $permissions, $expected) + { + global $cache, $db, $auth, $phpbb_root_path, $phpEx; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + + // Create auth mock + $auth = $this->getMock('\phpbb\auth\auth'); + $auth->expects($this->any()) + ->method('acl_getf') + ->with($this->stringContains('_'), $this->anything()) + ->will($this->returnValueMap($permissions)); + $user = $this->getMock('\phpbb\user'); + $content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + + $result = $db->sql_query('SELECT ' . $mode . '_id + FROM ' . $table . ' + WHERE ' . $content_visibility->get_forums_visibility_sql($mode, $forum_ids, $table_alias) . ' + ORDER BY ' . $mode . '_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} diff --git a/tests/content_visibility/get_global_visibility_sql_test.php b/tests/content_visibility/get_global_visibility_sql_test.php new file mode 100644 index 0000000000..9488a8c0b3 --- /dev/null +++ b/tests/content_visibility/get_global_visibility_sql_test.php @@ -0,0 +1,143 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_content_visibility_get_global_visibility_sql_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/get_forums_visibility_sql.xml'); + } + + public function get_global_visibility_sql_data() + { + return array( + array( + 'phpbb_topics', + 'topic', array(), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('topic_id' => 1), + array('topic_id' => 2), + array('topic_id' => 3), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 6), + array('topic_id' => 7), + array('topic_id' => 8), + array('topic_id' => 9), + ), + ), + array( + 'phpbb_topics', + 'topic', array(3), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('topic_id' => 1), + array('topic_id' => 2), + array('topic_id' => 3), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 6), + ), + ), + array( + 'phpbb_topics', + 'topic', array(), '', + array( + array('m_approve', true, array(2 => true)), + ), + array( + array('topic_id' => 2), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 6), + array('topic_id' => 8), + ), + ), + array( + 'phpbb_posts', + 'post', array(), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('post_id' => 1), + array('post_id' => 2), + array('post_id' => 3), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 6), + array('post_id' => 7), + array('post_id' => 8), + array('post_id' => 9), + ), + ), + array( + 'phpbb_posts', + 'post', array(3), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('post_id' => 1), + array('post_id' => 2), + array('post_id' => 3), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 6), + ), + ), + array( + 'phpbb_posts', + 'post', array(), '', + array( + array('m_approve', true, array(2 => true)), + ), + array( + array('post_id' => 2), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 6), + array('post_id' => 8), + ), + ), + ); + } + + /** + * @dataProvider get_global_visibility_sql_data + */ + public function test_get_global_visibility_sql($table, $mode, $forum_ids, $table_alias, $permissions, $expected) + { + global $cache, $db, $auth, $phpbb_root_path, $phpEx; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + + // Create auth mock + $auth = $this->getMock('\phpbb\auth\auth'); + $auth->expects($this->any()) + ->method('acl_getf') + ->with($this->stringContains('_'), $this->anything()) + ->will($this->returnValueMap($permissions)); + $user = $this->getMock('\phpbb\user'); + $content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + + $result = $db->sql_query('SELECT ' . $mode . '_id + FROM ' . $table . ' + WHERE ' . $content_visibility->get_global_visibility_sql($mode, $forum_ids, $table_alias) . ' + ORDER BY ' . $mode . '_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} diff --git a/tests/content_visibility/get_visibility_sql_test.php b/tests/content_visibility/get_visibility_sql_test.php new file mode 100644 index 0000000000..111e735650 --- /dev/null +++ b/tests/content_visibility/get_visibility_sql_test.php @@ -0,0 +1,90 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/get_visibility_sql.xml'); + } + + public function get_visibility_sql_data() + { + return array( + array( + 'phpbb_posts', + 'post', 1, '', + array( + array('m_approve', 1, true), + ), + array( + array('post_id' => 1), + array('post_id' => 2), + array('post_id' => 3), + ), + ), + array( + 'phpbb_posts', + 'post', 1, '', + array( + ), + array( + array('post_id' => 2), + ), + ), + array( + 'phpbb_topics', + 'topic', 1, '', + array( + array('m_approve', 1, true), + ), + array( + array('topic_id' => 1), + array('topic_id' => 2), + array('topic_id' => 3), + ), + ), + array( + 'phpbb_topics', + 'topic', 1, '', + array(), + array( + array('topic_id' => 2), + ), + ), + ); + } + + /** + * @dataProvider get_visibility_sql_data + */ + public function test_get_visibility_sql($table, $mode, $forum_id, $table_alias, $permissions, $expected) + { + global $cache, $db, $auth, $phpbb_root_path, $phpEx; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + + // Create auth mock + $auth = $this->getMock('\phpbb\auth\auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), $this->anything()) + ->will($this->returnValueMap($permissions)); + $user = $this->getMock('\phpbb\user'); + $content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + + $result = $db->sql_query('SELECT ' . $mode . '_id + FROM ' . $table . ' + WHERE ' . $content_visibility->get_visibility_sql($mode, $forum_id, $table_alias) . ' + ORDER BY ' . $mode . '_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} diff --git a/tests/content_visibility/set_post_visibility_test.php b/tests/content_visibility/set_post_visibility_test.php new file mode 100644 index 0000000000..f81b83ff86 --- /dev/null +++ b/tests/content_visibility/set_post_visibility_test.php @@ -0,0 +1,143 @@ +<?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'; + +class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/set_post_visibility.xml'); + } + + public function set_post_visibility_data() + { + return array( + array( + ITEM_APPROVED, + 1, 1, 1, + 2, time(), 'approve', + true, false, + array( + array('post_id' => 1, 'post_visibility' => 1, 'post_delete_reason' => 'approve'), + array('post_id' => 2, 'post_visibility' => 1, 'post_delete_reason' => ''), + array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 1, 'topic_first_post_id' => 1, 'topic_last_post_id' => 2), + ), + ), + array( + ITEM_APPROVED, + 3, 1, 1, + 2, time(), 'approve', + false, true, + array( + array('post_id' => 1, 'post_visibility' => 0, 'post_delete_reason' => ''), + array('post_id' => 2, 'post_visibility' => 1, 'post_delete_reason' => ''), + array('post_id' => 3, 'post_visibility' => 1, 'post_delete_reason' => 'approve'), + ), + array( + array('topic_visibility' => 1, 'topic_first_post_id' => 2, 'topic_last_post_id' => 3), + ), + ), + array( + ITEM_DELETED, + 2, 1, 1, + 2, time(), 'deleted', + true, true, + array( + array('post_id' => 1, 'post_visibility' => 0, 'post_delete_reason' => ''), + array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'), + array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 2, 'topic_first_post_id' => 1, 'topic_last_post_id' => 3), + ), + ), + array( + ITEM_DELETED, + 5, 2, 1, + 2, time(), 'deleted', + true, false, + array( + array('post_id' => 4, 'post_visibility' => 0, 'post_delete_reason' => ''), + array('post_id' => 5, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'), + array('post_id' => 6, 'post_visibility' => 1, 'post_delete_reason' => ''), + array('post_id' => 7, 'post_visibility' => 2, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 1, 'topic_first_post_id' => 6, 'topic_last_post_id' => 6), + ), + ), + array( + ITEM_DELETED, + 6, 2, 1, + 2, time(), 'deleted', + false, true, + array( + array('post_id' => 4, 'post_visibility' => 0, 'post_delete_reason' => ''), + array('post_id' => 5, 'post_visibility' => 1, 'post_delete_reason' => ''), + array('post_id' => 6, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'), + array('post_id' => 7, 'post_visibility' => 2, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 1, 'topic_first_post_id' => 5, 'topic_last_post_id' => 5), + ), + ), + array( + ITEM_DELETED, + 8, 3, 1, + 2, time(), 'deleted', + true, true, + array( + array('post_id' => 8, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'), + ), + array( + array('topic_visibility' => 2, 'topic_first_post_id' => 8, 'topic_last_post_id' => 8), + ), + ), + ); + } + + /** + * @dataProvider set_post_visibility_data + */ + 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; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $auth = $this->getMock('\phpbb\auth\auth'); + $user = $this->getMock('\phpbb\user'); + $content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + + $content_visibility->set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest); + + $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, $db->sql_fetchrowset($result)); + $db->sql_freeresult($result); + + $result = $db->sql_query('SELECT topic_visibility, topic_first_post_id, topic_last_post_id + FROM phpbb_topics + WHERE topic_id = ' . $topic_id); + + $this->assertEquals($expected_topic, $db->sql_fetchrowset($result)); + $db->sql_freeresult($result); + } +} diff --git a/tests/content_visibility/set_topic_visibility_test.php b/tests/content_visibility/set_topic_visibility_test.php new file mode 100644 index 0000000000..92b1253a15 --- /dev/null +++ b/tests/content_visibility/set_topic_visibility_test.php @@ -0,0 +1,107 @@ +<?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'; + +class phpbb_content_visibility_set_topic_visibility_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/set_topic_visibility.xml'); + } + + public function set_topic_visibility_data() + { + return array( + array( + ITEM_DELETED, 1, 1, + 2, time(), 'delete', false, + array( + array('post_id' => 1, 'post_visibility' => 2, 'post_delete_reason' => ''), + array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => 'manually'), + array('post_id' => 3, 'post_visibility' => 0, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 2, 'topic_first_post_id' => 1, 'topic_last_post_id' => 3, 'topic_delete_reason' => 'delete'), + ), + ), + array( + ITEM_DELETED, 1, 1, + 2, time(), 'delete-forced', true, + array( + array('post_id' => 1, 'post_visibility' => 2, 'post_delete_reason' => ''), + array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => ''), + array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 2, 'topic_first_post_id' => 1, 'topic_last_post_id' => 3, 'topic_delete_reason' => 'delete-forced'), + ), + ), + array( + ITEM_APPROVED, 2, 1, + 2, time(), 'approved', false, + array( + array('post_id' => 4, 'post_visibility' => 1, 'post_delete_reason' => ''), + array('post_id' => 5, 'post_visibility' => 2, 'post_delete_reason' => 'manually'), + array('post_id' => 6, 'post_visibility' => 0, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 1, 'topic_first_post_id' => 4, 'topic_last_post_id' => 4, 'topic_delete_reason' => 'approved'), + ), + ), + array( + ITEM_APPROVED, 2, 1, + 2, time(), 'approved-forced', true, + array( + array('post_id' => 4, 'post_visibility' => 1, 'post_delete_reason' => ''), + array('post_id' => 5, 'post_visibility' => 1, 'post_delete_reason' => ''), + array('post_id' => 6, 'post_visibility' => 1, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 1, 'topic_first_post_id' => 4, 'topic_last_post_id' => 6, 'topic_delete_reason' => 'approved-forced'), + ), + ), + ); + } + + /** + * @dataProvider set_topic_visibility_data + */ + public function test_set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all, $expected_posts, $expected_topic) + { + global $cache, $db, $auth, $phpbb_root_path, $phpEx; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $auth = $this->getMock('\phpbb\auth\auth'); + $user = $this->getMock('\phpbb\user'); + $content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + + $content_visibility->set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all); + + $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_delete_reason + FROM phpbb_topics + WHERE topic_id = ' . $topic_id); + + $this->assertEquals($expected_topic, $db->sql_fetchrowset($result)); + $db->sql_freeresult($result); + } +} |