Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
29.58% |
21 / 71 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_content_visibility_set_topic_visibility_test | |
29.58% |
21 / 71 |
|
66.67% |
2 / 3 |
6.14 | |
0.00% |
0 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| set_topic_visibility_data | |
0.00% |
0 / 50 |
|
0.00% |
0 / 1 |
2 | |||
| test_set_topic_visibility | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | require_once __DIR__ . '/../../phpBB/includes/functions_admin.php'; |
| 15 | require_once __DIR__ . '/../../phpBB/includes/functions_posting.php'; |
| 16 | |
| 17 | class phpbb_content_visibility_set_topic_visibility_test extends phpbb_database_test_case |
| 18 | { |
| 19 | public function getDataSet() |
| 20 | { |
| 21 | return $this->createXMLDataSet(__DIR__ . '/fixtures/set_topic_visibility.xml'); |
| 22 | } |
| 23 | |
| 24 | public static function set_topic_visibility_data() |
| 25 | { |
| 26 | return array( |
| 27 | array( |
| 28 | ITEM_DELETED, 1, 1, |
| 29 | 2, time(), 'delete', false, |
| 30 | array( |
| 31 | array('post_id' => 1, 'post_visibility' => 2, 'post_delete_reason' => ''), |
| 32 | array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => 'manually'), |
| 33 | array('post_id' => 3, 'post_visibility' => 0, 'post_delete_reason' => ''), |
| 34 | ), |
| 35 | array( |
| 36 | array('topic_visibility' => 2, 'topic_first_post_id' => 1, 'topic_last_post_id' => 3, 'topic_delete_reason' => 'delete'), |
| 37 | ), |
| 38 | ), |
| 39 | array( |
| 40 | ITEM_DELETED, 1, 1, |
| 41 | 2, time(), 'delete-forced', true, |
| 42 | array( |
| 43 | array('post_id' => 1, 'post_visibility' => 2, 'post_delete_reason' => ''), |
| 44 | array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => ''), |
| 45 | array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''), |
| 46 | ), |
| 47 | array( |
| 48 | array('topic_visibility' => 2, 'topic_first_post_id' => 1, 'topic_last_post_id' => 3, 'topic_delete_reason' => 'delete-forced'), |
| 49 | ), |
| 50 | ), |
| 51 | array( |
| 52 | ITEM_APPROVED, 2, 1, |
| 53 | 2, time(), 'approved', false, |
| 54 | array( |
| 55 | array('post_id' => 4, 'post_visibility' => 1, 'post_delete_reason' => ''), |
| 56 | array('post_id' => 5, 'post_visibility' => 2, 'post_delete_reason' => 'manually'), |
| 57 | array('post_id' => 6, 'post_visibility' => 0, 'post_delete_reason' => ''), |
| 58 | ), |
| 59 | array( |
| 60 | array('topic_visibility' => 1, 'topic_first_post_id' => 4, 'topic_last_post_id' => 4, 'topic_delete_reason' => 'approved'), |
| 61 | ), |
| 62 | ), |
| 63 | array( |
| 64 | ITEM_APPROVED, 2, 1, |
| 65 | 2, time(), 'approved-forced', true, |
| 66 | array( |
| 67 | array('post_id' => 4, 'post_visibility' => 1, 'post_delete_reason' => ''), |
| 68 | array('post_id' => 5, 'post_visibility' => 1, 'post_delete_reason' => ''), |
| 69 | array('post_id' => 6, 'post_visibility' => 1, 'post_delete_reason' => ''), |
| 70 | ), |
| 71 | array( |
| 72 | array('topic_visibility' => 1, 'topic_first_post_id' => 4, 'topic_last_post_id' => 6, 'topic_delete_reason' => 'approved-forced'), |
| 73 | ), |
| 74 | ), |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @dataProvider set_topic_visibility_data |
| 80 | */ |
| 81 | public function test_set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all, $expected_posts, $expected_topic) |
| 82 | { |
| 83 | global $cache, $db, $auth, $phpbb_root_path, $phpEx; |
| 84 | |
| 85 | $cache = new phpbb_mock_cache; |
| 86 | $db = $this->new_dbal(); |
| 87 | $auth = $this->createMock('\phpbb\auth\auth'); |
| 88 | $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); |
| 89 | $lang = new \phpbb\language\language($lang_loader); |
| 90 | $user = new \phpbb\user($lang, '\phpbb\datetime'); |
| 91 | $config = new phpbb\config\config(array()); |
| 92 | $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); |
| 93 | $content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); |
| 94 | |
| 95 | $content_visibility->set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all); |
| 96 | |
| 97 | $result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason |
| 98 | FROM phpbb_posts |
| 99 | WHERE topic_id = ' . $topic_id . ' |
| 100 | ORDER BY post_id ASC'); |
| 101 | |
| 102 | $this->assertEquals($expected_posts, $db->sql_fetchrowset($result)); |
| 103 | $db->sql_freeresult($result); |
| 104 | |
| 105 | $result = $db->sql_query('SELECT topic_visibility, topic_first_post_id, topic_last_post_id, topic_delete_reason |
| 106 | FROM phpbb_topics |
| 107 | WHERE topic_id = ' . $topic_id); |
| 108 | |
| 109 | $this->assertEquals($expected_topic, $db->sql_fetchrowset($result)); |
| 110 | $db->sql_freeresult($result); |
| 111 | } |
| 112 | } |