Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 205 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_functional_visibility_unapproved_posts_test | |
0.00% |
0 / 205 |
|
0.00% |
0 / 8 |
306 | |
0.00% |
0 / 1 |
| test_setup_forums | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
| test_create_posts | |
0.00% |
0 / 58 |
|
0.00% |
0 / 1 |
2 | |||
| test_view_unapproved_post_disabled | |
0.00% |
0 / 43 |
|
0.00% |
0 / 1 |
2 | |||
| test_view_unapproved_post_enabled | |
0.00% |
0 / 49 |
|
0.00% |
0 / 1 |
2 | |||
| test_reset_flood_interval | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| assert_forum_details | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| load_ids | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
110 | |||
| config_display_unapproved_posts_state | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| 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 | /** |
| 15 | * @group functional |
| 16 | */ |
| 17 | class phpbb_functional_visibility_unapproved_posts_test extends phpbb_functional_test_case |
| 18 | { |
| 19 | protected $data = []; |
| 20 | |
| 21 | public function test_setup_forums() |
| 22 | { |
| 23 | $this->login(); |
| 24 | $this->admin_login(); |
| 25 | |
| 26 | $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); |
| 27 | $form = $crawler->selectButton('addforum')->form([ |
| 28 | 'forum_name' => 'Unapproved Posts Test #1', |
| 29 | ]); |
| 30 | $crawler = self::submit($form); |
| 31 | $form = $crawler->selectButton('update')->form([ |
| 32 | 'forum_perm_from' => 2, |
| 33 | ]); |
| 34 | $crawler = self::submit($form); |
| 35 | |
| 36 | // Set flood interval to 0 |
| 37 | $this->set_flood_interval(0); |
| 38 | } |
| 39 | |
| 40 | public function test_create_posts() |
| 41 | { |
| 42 | $this->login(); |
| 43 | $this->load_ids([ |
| 44 | 'forums' => [ |
| 45 | 'Unapproved Posts Test #1', |
| 46 | ], |
| 47 | ]); |
| 48 | |
| 49 | $this->assert_forum_details($this->data['forums']['Unapproved Posts Test #1'], [ |
| 50 | 'forum_posts_approved' => 0, |
| 51 | 'forum_posts_unapproved' => 0, |
| 52 | 'forum_posts_softdeleted' => 0, |
| 53 | 'forum_topics_approved' => 0, |
| 54 | 'forum_topics_unapproved' => 0, |
| 55 | 'forum_topics_softdeleted' => 0, |
| 56 | 'forum_last_post_id' => 0, |
| 57 | ], 'initial comparison'); |
| 58 | |
| 59 | // Test creating topic #1 |
| 60 | $post = $this->create_topic($this->data['forums']['Unapproved Posts Test #1'], 'Unapproved Posts Test Topic #1', 'This is a test topic posted by the testing framework.'); |
| 61 | $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); |
| 62 | |
| 63 | $this->assertStringContainsString('Unapproved Posts Test Topic #1', $crawler->filter('h2')->text()); |
| 64 | $this->data['topics']['Unapproved Posts Test Topic #1'] = (int) $post['topic_id']; |
| 65 | $this->data['posts']['Unapproved Posts Test Topic #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); |
| 66 | |
| 67 | $this->assert_forum_details($this->data['forums']['Unapproved Posts Test #1'], [ |
| 68 | 'forum_posts_approved' => 1, |
| 69 | 'forum_posts_unapproved' => 0, |
| 70 | 'forum_posts_softdeleted' => 0, |
| 71 | 'forum_topics_approved' => 1, |
| 72 | 'forum_topics_unapproved' => 0, |
| 73 | 'forum_topics_softdeleted' => 0, |
| 74 | 'forum_last_post_id' => $this->data['posts']['Unapproved Posts Test Topic #1'], |
| 75 | ], 'after creating topic #1'); |
| 76 | |
| 77 | $this->logout(); |
| 78 | $this->create_user('unapproved_posts_test_user#1'); |
| 79 | $this->add_user_group('NEWLY_REGISTERED', ['unapproved_posts_test_user#1']); |
| 80 | $this->login('unapproved_posts_test_user#1'); |
| 81 | |
| 82 | // Test creating a reply |
| 83 | $post2 = $this->create_post($this->data['forums']['Unapproved Posts Test #1'], $post['topic_id'], 'Re: Unapproved Posts Test Topic #1-#2', 'This is a test post posted by the testing framework.', [], 'POST_STORED_MOD'); |
| 84 | |
| 85 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Unapproved Posts Test Topic #1']}&sid={$this->sid}"); |
| 86 | $this->assertStringNotContainsString('Re: Unapproved Posts Test Topic #1-#2', $crawler->filter('#page-body')->text()); |
| 87 | |
| 88 | $this->assert_forum_details($this->data['forums']['Unapproved Posts Test #1'], [ |
| 89 | 'forum_posts_approved' => 1, |
| 90 | 'forum_posts_unapproved' => 1, |
| 91 | 'forum_posts_softdeleted' => 0, |
| 92 | 'forum_topics_approved' => 1, |
| 93 | 'forum_topics_unapproved' => 0, |
| 94 | 'forum_topics_softdeleted' => 0, |
| 95 | 'forum_last_post_id' => $this->data['posts']['Unapproved Posts Test Topic #1'], |
| 96 | ], 'after replying'); |
| 97 | |
| 98 | // Test creating topic #2 |
| 99 | $post = $this->create_topic($this->data['forums']['Unapproved Posts Test #1'], 'Unapproved Posts Test Topic #2', 'This is a test topic posted by the testing framework.', [], 'POST_STORED_MOD'); |
| 100 | $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Unapproved Posts Test #1']}&sid={$this->sid}"); |
| 101 | |
| 102 | $this->assertStringNotContainsString('Unapproved Posts Test Topic #2', $crawler->filter('html')->text()); |
| 103 | |
| 104 | $this->assert_forum_details($this->data['forums']['Unapproved Posts Test #1'], [ |
| 105 | 'forum_posts_approved' => 1, |
| 106 | 'forum_posts_unapproved' => 2, |
| 107 | 'forum_posts_softdeleted' => 0, |
| 108 | 'forum_topics_approved' => 1, |
| 109 | 'forum_topics_unapproved' => 1, |
| 110 | 'forum_topics_softdeleted' => 0, |
| 111 | 'forum_last_post_id' => $this->data['posts']['Unapproved Posts Test Topic #1'], |
| 112 | ], 'after creating topic #2'); |
| 113 | |
| 114 | $this->logout(); |
| 115 | } |
| 116 | |
| 117 | public function test_view_unapproved_post_disabled() |
| 118 | { |
| 119 | // user who created post |
| 120 | $this->login('unapproved_posts_test_user#1'); |
| 121 | $this->load_ids([ |
| 122 | 'forums' => [ |
| 123 | 'Unapproved Posts Test #1', |
| 124 | ], |
| 125 | 'topics' => [ |
| 126 | 'Unapproved Posts Test Topic #1', |
| 127 | 'Unapproved Posts Test Topic #2', |
| 128 | ], |
| 129 | 'posts' => [ |
| 130 | 'Unapproved Posts Test Topic #1', |
| 131 | 'Re: Unapproved Posts Test Topic #1-#2', |
| 132 | 'Unapproved Posts Test Topic #2', |
| 133 | ], |
| 134 | ]); |
| 135 | |
| 136 | $this->assert_forum_details($this->data['forums']['Unapproved Posts Test #1'], [ |
| 137 | 'forum_posts_approved' => 1, |
| 138 | 'forum_posts_unapproved' => 2, |
| 139 | 'forum_posts_softdeleted' => 0, |
| 140 | 'forum_topics_approved' => 1, |
| 141 | 'forum_topics_unapproved' => 1, |
| 142 | 'forum_topics_softdeleted' => 0, |
| 143 | 'forum_last_post_id' => $this->data['posts']['Unapproved Posts Test Topic #1'], |
| 144 | ], 'before approving post'); |
| 145 | |
| 146 | $this->add_lang('posting'); |
| 147 | $this->add_lang('viewtopic'); |
| 148 | $this->add_lang('mcp'); |
| 149 | |
| 150 | // should be able to see topic 1 but not unapproved post |
| 151 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Unapproved Posts Test Topic #1']}&sid={$this->sid}"); |
| 152 | $this->assertStringContainsString('Unapproved Posts Test Topic #1', $crawler->filter('h2')->text()); |
| 153 | $this->assertStringNotContainsString('Re: Unapproved Posts Test Topic #1-#2', $crawler->filter('#page-body')->text()); |
| 154 | $this->assertStringNotContainsString('This post is not visible to other users until it has been approved', $crawler->filter('#page-body')->text()); |
| 155 | |
| 156 | // should not be able to see topic 2 |
| 157 | $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Unapproved Posts Test #1']}&sid={$this->sid}"); |
| 158 | $this->assertStringNotContainsString('Unapproved Posts Test Topic #2', $crawler->filter('html')->text()); |
| 159 | $this->logout(); |
| 160 | |
| 161 | // another user |
| 162 | $this->create_user('unapproved_posts_test_user#2'); |
| 163 | $this->login('unapproved_posts_test_user#2'); |
| 164 | |
| 165 | $this->add_lang(['posting', 'viewtopic', 'mcp']); |
| 166 | |
| 167 | // should be able to see topic 1 but not unapproved post |
| 168 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Unapproved Posts Test Topic #1']}&sid={$this->sid}"); |
| 169 | $this->assertStringContainsString('Unapproved Posts Test Topic #1', $crawler->filter('h2')->text()); |
| 170 | $this->assertStringNotContainsString('Re: Unapproved Posts Test Topic #1-#2', $crawler->filter('#page-body')->text()); |
| 171 | $this->assertStringNotContainsString('This post is not visible to other users until it has been approved', $crawler->filter('#page-body')->text()); |
| 172 | |
| 173 | // should not be able to see topic 2 |
| 174 | $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Unapproved Posts Test #1']}&sid={$this->sid}"); |
| 175 | $this->assertStringNotContainsString('Unapproved Posts Test Topic #2', $crawler->filter('html')->text()); |
| 176 | } |
| 177 | |
| 178 | public function test_view_unapproved_post_enabled() |
| 179 | { |
| 180 | $this->config_display_unapproved_posts_state(true); |
| 181 | |
| 182 | // user who created post |
| 183 | $this->login('unapproved_posts_test_user#1'); |
| 184 | $this->load_ids([ |
| 185 | 'forums' => [ |
| 186 | 'Unapproved Posts Test #1', |
| 187 | ], |
| 188 | 'topics' => [ |
| 189 | 'Unapproved Posts Test Topic #1', |
| 190 | 'Unapproved Posts Test Topic #2', |
| 191 | ], |
| 192 | 'posts' => [ |
| 193 | 'Unapproved Posts Test Topic #1', |
| 194 | 'Re: Unapproved Posts Test Topic #1-#2', |
| 195 | 'Unapproved Posts Test Topic #2', |
| 196 | ], |
| 197 | ]); |
| 198 | |
| 199 | $this->assert_forum_details($this->data['forums']['Unapproved Posts Test #1'], [ |
| 200 | 'forum_posts_approved' => 1, |
| 201 | 'forum_posts_unapproved' => 2, |
| 202 | 'forum_posts_softdeleted' => 0, |
| 203 | 'forum_topics_approved' => 1, |
| 204 | 'forum_topics_unapproved' => 1, |
| 205 | 'forum_topics_softdeleted' => 0, |
| 206 | 'forum_last_post_id' => $this->data['posts']['Unapproved Posts Test Topic #1'], |
| 207 | ], 'before approving post'); |
| 208 | |
| 209 | $this->add_lang('posting'); |
| 210 | $this->add_lang('viewtopic'); |
| 211 | $this->add_lang('mcp'); |
| 212 | |
| 213 | // should be able to see topic 1 and unapproved post |
| 214 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Unapproved Posts Test Topic #1']}&sid={$this->sid}"); |
| 215 | $this->assertStringContainsString('Unapproved Posts Test Topic #1', $crawler->filter('h2')->text()); |
| 216 | $this->assertStringContainsString('Re: Unapproved Posts Test Topic #1-#2', $crawler->filter('#page-body')->text()); |
| 217 | $this->assertStringContainsString('This post is not visible to other users until it has been approved', $crawler->filter('#page-body')->text()); |
| 218 | |
| 219 | // should be able to see topic 2 |
| 220 | $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Unapproved Posts Test #1']}&sid={$this->sid}"); |
| 221 | $this->assertStringContainsString('Unapproved Posts Test Topic #2', $crawler->filter('html')->text()); |
| 222 | |
| 223 | // should be able to see post in topic 2 |
| 224 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Unapproved Posts Test Topic #2']}&sid={$this->sid}"); |
| 225 | $this->assertStringContainsString('Unapproved Posts Test Topic #2', $crawler->filter('#page-body')->text()); |
| 226 | $this->assertStringContainsString('This post is not visible to other users until it has been approved', $crawler->filter('#page-body')->text()); |
| 227 | $this->logout(); |
| 228 | |
| 229 | // another user |
| 230 | $this->login('unapproved_posts_test_user#2'); |
| 231 | |
| 232 | $this->add_lang('posting'); |
| 233 | $this->add_lang('viewtopic'); |
| 234 | $this->add_lang('mcp'); |
| 235 | |
| 236 | // should be able to see topic 1 but not unapproved post |
| 237 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Unapproved Posts Test Topic #1']}&sid={$this->sid}"); |
| 238 | $this->assertStringContainsString('Unapproved Posts Test Topic #1', $crawler->filter('h2')->text()); |
| 239 | $this->assertStringNotContainsString('Re: Unapproved Posts Test Topic #1-#2', $crawler->filter('#page-body')->text()); |
| 240 | $this->assertStringNotContainsString('This post is not visible to other users until it has been approved', $crawler->filter('#page-body')->text()); |
| 241 | |
| 242 | // should not be able to see topic 2 |
| 243 | $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Unapproved Posts Test #1']}&sid={$this->sid}"); |
| 244 | $this->assertStringNotContainsString('Unapproved Posts Test Topic #2', $crawler->filter('html')->text()); |
| 245 | $this->logout(); |
| 246 | } |
| 247 | |
| 248 | public function test_reset_flood_interval() |
| 249 | { |
| 250 | $this->login(); |
| 251 | $this->admin_login(); |
| 252 | |
| 253 | // Set flood interval back to 15 |
| 254 | $this->set_flood_interval(15); |
| 255 | } |
| 256 | |
| 257 | protected function assert_forum_details($forum_id, $details, $additional_error_message = '') |
| 258 | { |
| 259 | $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' |
| 260 | FROM phpbb_forums |
| 261 | WHERE forum_id = ' . (int) $forum_id; |
| 262 | $result = $this->db->sql_query($sql); |
| 263 | $data = $this->db->sql_fetchrow($result); |
| 264 | $this->db->sql_freeresult($result); |
| 265 | |
| 266 | $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}"); |
| 267 | } |
| 268 | |
| 269 | protected function load_ids($data) |
| 270 | { |
| 271 | if (!empty($data['forums'])) |
| 272 | { |
| 273 | $sql = 'SELECT forum_id, forum_name |
| 274 | FROM phpbb_forums |
| 275 | WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']); |
| 276 | $result = $this->db->sql_query($sql); |
| 277 | while ($row = $this->db->sql_fetchrow($result)) |
| 278 | { |
| 279 | if (in_array($row['forum_name'], $data['forums'])) |
| 280 | { |
| 281 | $this->data['forums'][$row['forum_name']] = (int) $row['forum_id']; |
| 282 | } |
| 283 | } |
| 284 | $this->db->sql_freeresult($result); |
| 285 | } |
| 286 | |
| 287 | if (!empty($data['topics'])) |
| 288 | { |
| 289 | $sql = 'SELECT * |
| 290 | FROM phpbb_topics |
| 291 | WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']); |
| 292 | $result = $this->db->sql_query($sql); |
| 293 | while ($row = $this->db->sql_fetchrow($result)) |
| 294 | { |
| 295 | if (in_array($row['topic_title'], $data['topics'])) |
| 296 | { |
| 297 | $this->data['topics'][$row['topic_title']] = (int) $row['topic_id']; |
| 298 | } |
| 299 | } |
| 300 | $this->db->sql_freeresult($result); |
| 301 | } |
| 302 | |
| 303 | if (!empty($data['posts'])) |
| 304 | { |
| 305 | $sql = 'SELECT * |
| 306 | FROM phpbb_posts |
| 307 | WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']); |
| 308 | $result = $this->db->sql_query($sql); |
| 309 | while ($row = $this->db->sql_fetchrow($result)) |
| 310 | { |
| 311 | if (in_array($row['post_subject'], $data['posts'])) |
| 312 | { |
| 313 | $this->data['posts'][$row['post_subject']] = (int) $row['post_id']; |
| 314 | } |
| 315 | } |
| 316 | $this->db->sql_freeresult($result); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | protected function config_display_unapproved_posts_state($state) |
| 321 | { |
| 322 | $this->login(); |
| 323 | $this->admin_login(); |
| 324 | |
| 325 | $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=features"); |
| 326 | |
| 327 | $form = $crawler->selectButton('Submit')->form(); |
| 328 | $values = $form->getValues(); |
| 329 | |
| 330 | // Enable display of unapproved posts to posters |
| 331 | $values['config[display_unapproved_posts]'] = $state; |
| 332 | |
| 333 | $form->setValues($values); |
| 334 | |
| 335 | $crawler = self::submit($form); |
| 336 | self::assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text()); |
| 337 | $this->logout(); |
| 338 | } |
| 339 | } |