Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 273 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_functional_visibility_reapprove_test | |
0.00% |
0 / 273 |
|
0.00% |
0 / 10 |
380 | |
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_approve_post | |
0.00% |
0 / 50 |
|
0.00% |
0 / 1 |
2 | |||
| test_approve_topic | |
0.00% |
0 / 48 |
|
0.00% |
0 / 1 |
2 | |||
| test_edit_posts | |
0.00% |
0 / 70 |
|
0.00% |
0 / 1 |
2 | |||
| test_approve_post_again | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| test_approve_topic_again | |
0.00% |
0 / 1 |
|
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 | |||
| 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_reapprove_test extends phpbb_functional_test_case |
| 18 | { |
| 19 | protected $data = array(); |
| 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(array( |
| 28 | 'forum_name' => 'Reapprove Test #1', |
| 29 | )); |
| 30 | $crawler = self::submit($form); |
| 31 | $form = $crawler->selectButton('update')->form(array( |
| 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(array( |
| 44 | 'forums' => array( |
| 45 | 'Reapprove Test #1', |
| 46 | ), |
| 47 | )); |
| 48 | |
| 49 | $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( |
| 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']['Reapprove Test #1'], 'Reapprove 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('Reapprove Test Topic #1', $crawler->filter('h2')->text()); |
| 64 | $this->data['topics']['Reapprove Test Topic #1'] = (int) $post['topic_id']; |
| 65 | $this->data['posts']['Reapprove 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']['Reapprove Test #1'], array( |
| 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']['Reapprove Test Topic #1'], |
| 75 | ), 'after creating topic #1'); |
| 76 | |
| 77 | $this->logout(); |
| 78 | $this->create_user('reapprove_testuser'); |
| 79 | $this->add_user_group('NEWLY_REGISTERED', array('reapprove_testuser')); |
| 80 | $this->login('reapprove_testuser'); |
| 81 | |
| 82 | // Test creating a reply |
| 83 | $post2 = $this->create_post($this->data['forums']['Reapprove Test #1'], $post['topic_id'], 'Re: Reapprove Test Topic #1-#2', 'This is a test post posted by the testing framework.', array(), 'POST_STORED_MOD'); |
| 84 | |
| 85 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}"); |
| 86 | $this->assertStringNotContainsString('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text()); |
| 87 | |
| 88 | $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( |
| 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']['Reapprove Test Topic #1'], |
| 96 | ), 'after replying'); |
| 97 | |
| 98 | // Test creating topic #2 |
| 99 | $post = $this->create_topic($this->data['forums']['Reapprove Test #1'], 'Reapprove Test Topic #2', 'This is a test topic posted by the testing framework.', array(), 'POST_STORED_MOD'); |
| 100 | $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Reapprove Test #1']}&sid={$this->sid}"); |
| 101 | |
| 102 | $this->assertStringNotContainsString('Reapprove Test Topic #2', $crawler->filter('html')->text()); |
| 103 | |
| 104 | $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( |
| 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']['Reapprove Test Topic #1'], |
| 112 | ), 'after creating topic #2'); |
| 113 | |
| 114 | $this->logout(); |
| 115 | } |
| 116 | |
| 117 | public function test_approve_post() |
| 118 | { |
| 119 | $this->login(); |
| 120 | $this->load_ids(array( |
| 121 | 'forums' => array( |
| 122 | 'Reapprove Test #1', |
| 123 | ), |
| 124 | 'topics' => array( |
| 125 | 'Reapprove Test Topic #1', |
| 126 | 'Reapprove Test Topic #2', |
| 127 | ), |
| 128 | 'posts' => array( |
| 129 | 'Reapprove Test Topic #1', |
| 130 | 'Re: Reapprove Test Topic #1-#2', |
| 131 | 'Reapprove Test Topic #2', |
| 132 | ), |
| 133 | )); |
| 134 | |
| 135 | $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( |
| 136 | 'forum_posts_approved' => 1, |
| 137 | 'forum_posts_unapproved' => 2, |
| 138 | 'forum_posts_softdeleted' => 0, |
| 139 | 'forum_topics_approved' => 1, |
| 140 | 'forum_topics_unapproved' => 1, |
| 141 | 'forum_topics_softdeleted' => 0, |
| 142 | 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'], |
| 143 | ), 'before approving post'); |
| 144 | |
| 145 | $this->add_lang('posting'); |
| 146 | $this->add_lang('viewtopic'); |
| 147 | $this->add_lang('mcp'); |
| 148 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}"); |
| 149 | $this->assertStringContainsString('Reapprove Test Topic #1', $crawler->filter('h2')->text()); |
| 150 | $this->assertStringContainsString('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text()); |
| 151 | |
| 152 | $form = $crawler->selectButton($this->lang('APPROVE'))->form(); |
| 153 | $crawler = self::submit($form); |
| 154 | $form = $crawler->selectButton($this->lang('YES'))->form(); |
| 155 | $crawler = self::submit($form); |
| 156 | $this->assertContainsLang('POST_APPROVED_SUCCESS', $crawler->text()); |
| 157 | |
| 158 | $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( |
| 159 | 'forum_posts_approved' => 2, |
| 160 | 'forum_posts_unapproved' => 1, |
| 161 | 'forum_posts_softdeleted' => 0, |
| 162 | 'forum_topics_approved' => 1, |
| 163 | 'forum_topics_unapproved' => 1, |
| 164 | 'forum_topics_softdeleted' => 0, |
| 165 | 'forum_last_post_id' => $this->data['posts']['Re: Reapprove Test Topic #1-#2'], |
| 166 | ), 'after approving post'); |
| 167 | |
| 168 | $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link(); |
| 169 | $link_url = $link->getUri(); |
| 170 | $this->assertStringContainsString('viewtopic.php?t=' . $this->data['topics']['Reapprove Test Topic #1'], $link_url); |
| 171 | |
| 172 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}"); |
| 173 | $this->assertStringContainsString('Reapprove Test Topic #1', $crawler->filter('h2')->text()); |
| 174 | $this->assertStringContainsString('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text()); |
| 175 | } |
| 176 | |
| 177 | public function test_approve_topic() |
| 178 | { |
| 179 | $this->login(); |
| 180 | $this->load_ids(array( |
| 181 | 'forums' => array( |
| 182 | 'Reapprove Test #1', |
| 183 | ), |
| 184 | 'topics' => array( |
| 185 | 'Reapprove Test Topic #1', |
| 186 | 'Reapprove Test Topic #2', |
| 187 | ), |
| 188 | 'posts' => array( |
| 189 | 'Reapprove Test Topic #1', |
| 190 | 'Re: Reapprove Test Topic #1-#2', |
| 191 | 'Reapprove Test Topic #2', |
| 192 | ), |
| 193 | )); |
| 194 | |
| 195 | $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( |
| 196 | 'forum_posts_approved' => 2, |
| 197 | 'forum_posts_unapproved' => 1, |
| 198 | 'forum_posts_softdeleted' => 0, |
| 199 | 'forum_topics_approved' => 1, |
| 200 | 'forum_topics_unapproved' => 1, |
| 201 | 'forum_topics_softdeleted' => 0, |
| 202 | 'forum_last_post_id' => $this->data['posts']['Re: Reapprove Test Topic #1-#2'], |
| 203 | ), 'before approving topic'); |
| 204 | |
| 205 | $this->add_lang('posting'); |
| 206 | $this->add_lang('viewtopic'); |
| 207 | $this->add_lang('mcp'); |
| 208 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #2']}&sid={$this->sid}"); |
| 209 | $this->assertStringContainsString('Reapprove Test Topic #2', $crawler->filter('h2')->text()); |
| 210 | |
| 211 | $form = $crawler->selectButton($this->lang('APPROVE'))->form(); |
| 212 | $crawler = self::submit($form); |
| 213 | $form = $crawler->selectButton($this->lang('YES'))->form(); |
| 214 | $crawler = self::submit($form); |
| 215 | $this->assertContainsLang('TOPIC_APPROVED_SUCCESS', $crawler->text()); |
| 216 | |
| 217 | $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( |
| 218 | 'forum_posts_approved' => 3, |
| 219 | 'forum_posts_unapproved' => 0, |
| 220 | 'forum_posts_softdeleted' => 0, |
| 221 | 'forum_topics_approved' => 2, |
| 222 | 'forum_topics_unapproved' => 0, |
| 223 | 'forum_topics_softdeleted' => 0, |
| 224 | 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #2'], |
| 225 | ), 'after approving topic'); |
| 226 | |
| 227 | $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link(); |
| 228 | $link_url = $link->getUri(); |
| 229 | $this->assertStringContainsString('viewtopic.php?t=' . $this->data['topics']['Reapprove Test Topic #2'], $link_url); |
| 230 | |
| 231 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #2']}&sid={$this->sid}"); |
| 232 | $this->assertStringContainsString('Reapprove Test Topic #2', $crawler->filter('h2')->text()); |
| 233 | } |
| 234 | |
| 235 | public function test_edit_posts() |
| 236 | { |
| 237 | $this->load_ids(array( |
| 238 | 'forums' => array( |
| 239 | 'Reapprove Test #1', |
| 240 | ), |
| 241 | 'topics' => array( |
| 242 | 'Reapprove Test Topic #1', |
| 243 | 'Reapprove Test Topic #2', |
| 244 | ), |
| 245 | 'posts' => array( |
| 246 | 'Reapprove Test Topic #1', |
| 247 | 'Re: Reapprove Test Topic #1-#2', |
| 248 | 'Reapprove Test Topic #2', |
| 249 | ), |
| 250 | )); |
| 251 | $this->add_lang('posting'); |
| 252 | |
| 253 | $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( |
| 254 | 'forum_posts_approved' => 3, |
| 255 | 'forum_posts_unapproved' => 0, |
| 256 | 'forum_posts_softdeleted' => 0, |
| 257 | 'forum_topics_approved' => 2, |
| 258 | 'forum_topics_unapproved' => 0, |
| 259 | 'forum_topics_softdeleted' => 0, |
| 260 | 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #2'], |
| 261 | ), 'before editing post'); |
| 262 | |
| 263 | $this->login('reapprove_testuser'); |
| 264 | $this->add_user_group('NEWLY_REGISTERED', array('reapprove_testuser')); |
| 265 | |
| 266 | // Test editing a post |
| 267 | $posting_url = "posting.php?mode=edit&p={$this->data['posts']['Re: Reapprove Test Topic #1-#2']}&sid={$this->sid}"; |
| 268 | $form_data = array( |
| 269 | 'message' => 'Post edited by testing framework', |
| 270 | 'subject' => 'Re: Reapprove Test Topic #1-#2', |
| 271 | 'post' => true, |
| 272 | ); |
| 273 | $this->submit_post($posting_url, 'EDIT_POST', $form_data, 'POST_EDITED_MOD'); |
| 274 | |
| 275 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}"); |
| 276 | $this->assertStringNotContainsString('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text()); |
| 277 | $this->assertStringNotContainsString('Post edited by testing framework', $crawler->filter('#page-body')->text()); |
| 278 | |
| 279 | $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( |
| 280 | 'forum_posts_approved' => 2, |
| 281 | 'forum_posts_unapproved' => 1, |
| 282 | 'forum_posts_softdeleted' => 0, |
| 283 | 'forum_topics_approved' => 2, |
| 284 | 'forum_topics_unapproved' => 0, |
| 285 | 'forum_topics_softdeleted' => 0, |
| 286 | 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #2'], |
| 287 | ), 'after editing post'); |
| 288 | |
| 289 | // Test editing a topic |
| 290 | $posting_url = "posting.php?mode=edit&p={$this->data['posts']['Reapprove Test Topic #2']}&sid={$this->sid}"; |
| 291 | $form_data = array( |
| 292 | 'message' => 'Post edited by testing framework', |
| 293 | 'subject' => 'Reapprove Test Topic #2', |
| 294 | 'post' => true, |
| 295 | ); |
| 296 | $this->submit_post($posting_url, 'EDIT_POST', $form_data, 'POST_EDITED_MOD'); |
| 297 | |
| 298 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #2']}&sid={$this->sid}", array(), false); |
| 299 | self::assert_response_html(404); |
| 300 | $this->assertStringNotContainsString('Reapprove Test Topic #2', $crawler->filter('#page-body')->text()); |
| 301 | $this->assertStringNotContainsString('Post edited by testing framework', $crawler->filter('#page-body')->text()); |
| 302 | |
| 303 | $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( |
| 304 | 'forum_posts_approved' => 1, |
| 305 | 'forum_posts_unapproved' => 2, |
| 306 | 'forum_posts_softdeleted' => 0, |
| 307 | 'forum_topics_approved' => 1, |
| 308 | 'forum_topics_unapproved' => 1, |
| 309 | 'forum_topics_softdeleted' => 0, |
| 310 | 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'], |
| 311 | ), 'after editing topic'); |
| 312 | |
| 313 | $this->logout(); |
| 314 | $this->login(); |
| 315 | |
| 316 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}"); |
| 317 | $this->assertStringContainsString('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text()); |
| 318 | $this->assertStringContainsString('Post edited by testing framework', $crawler->filter('#page-body')->text()); |
| 319 | } |
| 320 | |
| 321 | public function test_approve_post_again() |
| 322 | { |
| 323 | $this->test_approve_post(); |
| 324 | } |
| 325 | |
| 326 | public function test_approve_topic_again() |
| 327 | { |
| 328 | $this->test_approve_topic(); |
| 329 | } |
| 330 | |
| 331 | public function test_reset_flood_interval() |
| 332 | { |
| 333 | $this->login(); |
| 334 | $this->admin_login(); |
| 335 | |
| 336 | // Set flood interval back to 15 |
| 337 | $this->set_flood_interval(15); |
| 338 | } |
| 339 | |
| 340 | protected function assert_forum_details($forum_id, $details, $additional_error_message = '') |
| 341 | { |
| 342 | $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' |
| 343 | FROM phpbb_forums |
| 344 | WHERE forum_id = ' . (int) $forum_id; |
| 345 | $result = $this->db->sql_query($sql); |
| 346 | $data = $this->db->sql_fetchrow($result); |
| 347 | $this->db->sql_freeresult($result); |
| 348 | |
| 349 | $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}"); |
| 350 | } |
| 351 | |
| 352 | protected function load_ids($data) |
| 353 | { |
| 354 | if (!empty($data['forums'])) |
| 355 | { |
| 356 | $sql = 'SELECT * |
| 357 | FROM phpbb_forums |
| 358 | WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']); |
| 359 | $result = $this->db->sql_query($sql); |
| 360 | while ($row = $this->db->sql_fetchrow($result)) |
| 361 | { |
| 362 | if (in_array($row['forum_name'], $data['forums'])) |
| 363 | { |
| 364 | $this->data['forums'][$row['forum_name']] = (int) $row['forum_id']; |
| 365 | } |
| 366 | } |
| 367 | $this->db->sql_freeresult($result); |
| 368 | } |
| 369 | |
| 370 | if (!empty($data['topics'])) |
| 371 | { |
| 372 | $sql = 'SELECT * |
| 373 | FROM phpbb_topics |
| 374 | WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']); |
| 375 | $result = $this->db->sql_query($sql); |
| 376 | while ($row = $this->db->sql_fetchrow($result)) |
| 377 | { |
| 378 | if (in_array($row['topic_title'], $data['topics'])) |
| 379 | { |
| 380 | $this->data['topics'][$row['topic_title']] = (int) $row['topic_id']; |
| 381 | } |
| 382 | } |
| 383 | $this->db->sql_freeresult($result); |
| 384 | } |
| 385 | |
| 386 | if (!empty($data['posts'])) |
| 387 | { |
| 388 | $sql = 'SELECT * |
| 389 | FROM phpbb_posts |
| 390 | WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']); |
| 391 | $result = $this->db->sql_query($sql); |
| 392 | while ($row = $this->db->sql_fetchrow($result)) |
| 393 | { |
| 394 | if (in_array($row['post_subject'], $data['posts'])) |
| 395 | { |
| 396 | $this->data['posts'][$row['post_subject']] = (int) $row['post_id']; |
| 397 | } |
| 398 | } |
| 399 | $this->db->sql_freeresult($result); |
| 400 | } |
| 401 | } |
| 402 | } |