Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 201 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_functional_visibility_disapprove_test | |
0.00% |
0 / 201 |
|
0.00% |
0 / 7 |
272 | |
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_reset_flood_interval | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| test_disapprove_post | |
0.00% |
0 / 50 |
|
0.00% |
0 / 1 |
2 | |||
| test_disapprove_topic | |
0.00% |
0 / 48 |
|
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_disapprove_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' => 'Disapprove 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 | 'Disapprove Test #1', |
| 46 | ), |
| 47 | )); |
| 48 | |
| 49 | $this->assert_forum_details($this->data['forums']['Disapprove 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']['Disapprove Test #1'], 'Disapprove 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('Disapprove Test Topic #1', $crawler->filter('html')->text()); |
| 64 | $this->data['topics']['Disapprove Test Topic #1'] = (int) $post['topic_id']; |
| 65 | $this->data['posts']['Disapprove 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']['Disapprove 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']['Disapprove Test Topic #1'], |
| 75 | ), 'after creating topic #1'); |
| 76 | |
| 77 | $this->logout(); |
| 78 | $this->create_user('disapprove_testuser'); |
| 79 | $this->add_user_group('NEWLY_REGISTERED', array('disapprove_testuser')); |
| 80 | $this->login('disapprove_testuser'); |
| 81 | |
| 82 | // Test creating a reply |
| 83 | $post2 = $this->create_post($this->data['forums']['Disapprove Test #1'], $post['topic_id'], 'Re: Disapprove 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']['Disapprove Test Topic #1']}&sid={$this->sid}"); |
| 86 | $this->assertStringNotContainsString('Re: Disapprove Test Topic #1-#2', $crawler->filter('html')->text()); |
| 87 | |
| 88 | $this->assert_forum_details($this->data['forums']['Disapprove 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']['Disapprove Test Topic #1'], |
| 96 | ), 'after replying'); |
| 97 | |
| 98 | // Test creating topic #2 |
| 99 | $post = $this->create_topic($this->data['forums']['Disapprove Test #1'], 'Disapprove 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']['Disapprove Test #1']}&sid={$this->sid}"); |
| 101 | |
| 102 | $this->assertStringNotContainsString('Disapprove Test Topic #2', $crawler->filter('html')->text()); |
| 103 | |
| 104 | $this->assert_forum_details($this->data['forums']['Disapprove 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']['Disapprove Test Topic #1'], |
| 112 | ), 'after creating topic #2'); |
| 113 | |
| 114 | $this->logout(); |
| 115 | } |
| 116 | |
| 117 | public function test_reset_flood_interval() |
| 118 | { |
| 119 | $this->login(); |
| 120 | $this->admin_login(); |
| 121 | |
| 122 | // Set flood interval back to 15 |
| 123 | $this->set_flood_interval(15); |
| 124 | } |
| 125 | |
| 126 | public function test_disapprove_post() |
| 127 | { |
| 128 | $this->login(); |
| 129 | $this->load_ids(array( |
| 130 | 'forums' => array( |
| 131 | 'Disapprove Test #1', |
| 132 | ), |
| 133 | 'topics' => array( |
| 134 | 'Disapprove Test Topic #1', |
| 135 | 'Disapprove Test Topic #2', |
| 136 | ), |
| 137 | 'posts' => array( |
| 138 | 'Disapprove Test Topic #1', |
| 139 | 'Re: Disapprove Test Topic #1-#2', |
| 140 | 'Disapprove Test Topic #2', |
| 141 | ), |
| 142 | )); |
| 143 | |
| 144 | $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array( |
| 145 | 'forum_posts_approved' => 1, |
| 146 | 'forum_posts_unapproved' => 2, |
| 147 | 'forum_posts_softdeleted' => 0, |
| 148 | 'forum_topics_approved' => 1, |
| 149 | 'forum_topics_unapproved' => 1, |
| 150 | 'forum_topics_softdeleted' => 0, |
| 151 | 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'], |
| 152 | ), 'before disapproving post'); |
| 153 | |
| 154 | $this->add_lang('posting'); |
| 155 | $this->add_lang('viewtopic'); |
| 156 | $this->add_lang('mcp'); |
| 157 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #1']}&sid={$this->sid}"); |
| 158 | $this->assertStringContainsString('Disapprove Test Topic #1', $crawler->filter('html')->text()); |
| 159 | $this->assertStringContainsString('Re: Disapprove Test Topic #1-#2', $crawler->filter('html')->text()); |
| 160 | |
| 161 | $form = $crawler->selectButton($this->lang('DISAPPROVE'))->form(); |
| 162 | $crawler = self::submit($form); |
| 163 | $form = $crawler->selectButton($this->lang('YES'))->form(); |
| 164 | $crawler = self::submit($form); |
| 165 | $this->assertContainsLang('POST_DISAPPROVED_SUCCESS', $crawler->text()); |
| 166 | |
| 167 | $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array( |
| 168 | 'forum_posts_approved' => 1, |
| 169 | 'forum_posts_unapproved' => 1, |
| 170 | 'forum_posts_softdeleted' => 0, |
| 171 | 'forum_topics_approved' => 1, |
| 172 | 'forum_topics_unapproved' => 1, |
| 173 | 'forum_topics_softdeleted' => 0, |
| 174 | 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'], |
| 175 | ), 'after disapproving post'); |
| 176 | |
| 177 | $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link(); |
| 178 | $link_url = $link->getUri(); |
| 179 | $this->assertStringContainsString('viewtopic.php?t=' . $this->data['topics']['Disapprove Test Topic #1'], $link_url); |
| 180 | |
| 181 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #1']}&sid={$this->sid}"); |
| 182 | $this->assertStringContainsString('Disapprove Test Topic #1', $crawler->filter('html')->text()); |
| 183 | $this->assertStringNotContainsString('Re: Disapprove Test Topic #1-#2', $crawler->filter('html')->text()); |
| 184 | } |
| 185 | |
| 186 | public function test_disapprove_topic() |
| 187 | { |
| 188 | $this->login(); |
| 189 | $this->load_ids(array( |
| 190 | 'forums' => array( |
| 191 | 'Disapprove Test #1', |
| 192 | ), |
| 193 | 'topics' => array( |
| 194 | 'Disapprove Test Topic #1', |
| 195 | 'Disapprove Test Topic #2', |
| 196 | ), |
| 197 | 'posts' => array( |
| 198 | 'Disapprove Test Topic #1', |
| 199 | 'Disapprove Test Topic #2', |
| 200 | ), |
| 201 | )); |
| 202 | |
| 203 | $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array( |
| 204 | 'forum_posts_approved' => 1, |
| 205 | 'forum_posts_unapproved' => 1, |
| 206 | 'forum_posts_softdeleted' => 0, |
| 207 | 'forum_topics_approved' => 1, |
| 208 | 'forum_topics_unapproved' => 1, |
| 209 | 'forum_topics_softdeleted' => 0, |
| 210 | 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'], |
| 211 | ), 'before disapproving topic'); |
| 212 | |
| 213 | $this->add_lang('posting'); |
| 214 | $this->add_lang('viewtopic'); |
| 215 | $this->add_lang('mcp'); |
| 216 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #2']}&sid={$this->sid}"); |
| 217 | $this->assertStringContainsString('Disapprove Test Topic #2', $crawler->filter('html')->text()); |
| 218 | |
| 219 | $form = $crawler->selectButton($this->lang('DISAPPROVE'))->form(); |
| 220 | $crawler = self::submit($form); |
| 221 | $form = $crawler->selectButton($this->lang('YES'))->form(); |
| 222 | $crawler = self::submit($form); |
| 223 | $this->assertContainsLang('TOPIC_DISAPPROVED_SUCCESS', $crawler->text()); |
| 224 | |
| 225 | $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array( |
| 226 | 'forum_posts_approved' => 1, |
| 227 | 'forum_posts_unapproved' => 0, |
| 228 | 'forum_posts_softdeleted' => 0, |
| 229 | 'forum_topics_approved' => 1, |
| 230 | 'forum_topics_unapproved' => 0, |
| 231 | 'forum_topics_softdeleted' => 0, |
| 232 | 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'], |
| 233 | ), 'after disapproving topic'); |
| 234 | |
| 235 | $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link(); |
| 236 | $link_url = $link->getUri(); |
| 237 | $this->assertStringContainsString('viewforum.php?f=' . $this->data['forums']['Disapprove Test #1'], $link_url); |
| 238 | |
| 239 | $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #2']}&sid={$this->sid}", array(), false); |
| 240 | self::assert_response_html(404); |
| 241 | $this->assertStringNotContainsString('Disapprove Test Topic #2', $crawler->filter('html')->text()); |
| 242 | } |
| 243 | |
| 244 | protected function assert_forum_details($forum_id, $details, $additional_error_message = '') |
| 245 | { |
| 246 | $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' |
| 247 | FROM phpbb_forums |
| 248 | WHERE forum_id = ' . (int) $forum_id; |
| 249 | $result = $this->db->sql_query($sql); |
| 250 | $data = $this->db->sql_fetchrow($result); |
| 251 | $this->db->sql_freeresult($result); |
| 252 | |
| 253 | $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}"); |
| 254 | } |
| 255 | |
| 256 | protected function load_ids($data) |
| 257 | { |
| 258 | if (!empty($data['forums'])) |
| 259 | { |
| 260 | $sql = 'SELECT * |
| 261 | FROM phpbb_forums |
| 262 | WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']); |
| 263 | $result = $this->db->sql_query($sql); |
| 264 | while ($row = $this->db->sql_fetchrow($result)) |
| 265 | { |
| 266 | if (in_array($row['forum_name'], $data['forums'])) |
| 267 | { |
| 268 | $this->data['forums'][$row['forum_name']] = (int) $row['forum_id']; |
| 269 | } |
| 270 | } |
| 271 | $this->db->sql_freeresult($result); |
| 272 | } |
| 273 | |
| 274 | if (!empty($data['topics'])) |
| 275 | { |
| 276 | $sql = 'SELECT * |
| 277 | FROM phpbb_topics |
| 278 | WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']); |
| 279 | $result = $this->db->sql_query($sql); |
| 280 | while ($row = $this->db->sql_fetchrow($result)) |
| 281 | { |
| 282 | if (in_array($row['topic_title'], $data['topics'])) |
| 283 | { |
| 284 | $this->data['topics'][$row['topic_title']] = (int) $row['topic_id']; |
| 285 | } |
| 286 | } |
| 287 | $this->db->sql_freeresult($result); |
| 288 | } |
| 289 | |
| 290 | if (!empty($data['posts'])) |
| 291 | { |
| 292 | $sql = 'SELECT * |
| 293 | FROM phpbb_posts |
| 294 | WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']); |
| 295 | $result = $this->db->sql_query($sql); |
| 296 | while ($row = $this->db->sql_fetchrow($result)) |
| 297 | { |
| 298 | if (in_array($row['post_subject'], $data['posts'])) |
| 299 | { |
| 300 | $this->data['posts'][$row['post_subject']] = (int) $row['post_id']; |
| 301 | } |
| 302 | } |
| 303 | $this->db->sql_freeresult($result); |
| 304 | } |
| 305 | } |
| 306 | } |