Changeset 7772
- Timestamp:
- 10/03/2026 02:10:51 AM (6 weeks ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
CHANGELOG.md (modified) (1 diff)
-
src/includes/forums/template.php (modified) (3 diffs)
-
tests/phpunit/testcases/forums/template/forms.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/CHANGELOG.md
r7768 r7772 45 45 ### Fixed 46 46 47 - Restored assigned moderator names in forum edit forms and corrected forum type and visibility dropdown behavior. 47 48 - Kept closed category ancestors from being ignored by forum status checks. 48 49 - Preserved topic subscriptions when topics and replies are edited in administration. -
trunk/src/includes/forums/template.php
r7768 r7772 2408 2408 // Comma separate user nicenames 2409 2409 if ( ! empty( $user_nicenames ) ) { 2410 $forum_mods = implode( ', ', wp_list_pluck( $user_nicenames, 'user_nicename' ));2410 $forum_mods = implode( ', ', $user_nicenames ); 2411 2411 } 2412 2412 } … … 2629 2629 $r['selected'] = bbp_get_forum_type( $r['forum_id'] ); 2630 2630 2631 // New topic2631 // New forum 2632 2632 } else { 2633 $r['selected'] = bbp_get_public_status_id();2633 $r['selected'] = 'forum'; 2634 2634 } 2635 2635 } … … 2824 2824 <?php 2825 2825 2826 // Filter & return 2827 return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r, $args ); 2826 // Preserve the existing type filter for visibility dropdowns. 2827 $html = apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r, $args ); 2828 2829 // Filter & return 2830 return apply_filters( 'bbp_get_form_forum_visibility_dropdown', $html, $r, $args ); 2828 2831 } 2829 2832 -
trunk/tests/phpunit/testcases/forums/template/forms.php
r7461 r7772 10 10 class BBP_Tests_Forums_Template_Forms extends BBP_UnitTestCase { 11 11 12 private function with_forum_edit( $forum_id, $callback ) { 13 $old_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null; 14 $old_forum_id = bbpress()->current_forum_id; 15 $GLOBALS['post'] = get_post( $forum_id ); 16 bbpress()->current_forum_id = $forum_id; 17 setup_postdata( $GLOBALS['post'] ); 18 add_filter( 'bbp_is_forum_edit', '__return_true' ); 19 20 try { 21 $callback(); 22 } finally { 23 remove_filter( 'bbp_is_forum_edit', '__return_true' ); 24 bbpress()->current_forum_id = $old_forum_id; 25 $GLOBALS['post'] = $old_post; 26 wp_reset_postdata(); 27 } 28 } 29 30 private function with_forum_post( $action, $values, $callback ) { 31 $old_method = $_SERVER['REQUEST_METHOD']; 32 $old_post = $_POST; 33 $old_request = $_REQUEST; 34 $_SERVER['REQUEST_METHOD'] = 'POST'; 35 $_POST = $values; 36 $_REQUEST = array_merge( $old_request, $values, array( '_wpnonce' => wp_create_nonce( $action ) ) ); 37 38 try { 39 $callback(); 40 } finally { 41 $_SERVER['REQUEST_METHOD'] = $old_method; 42 $_POST = $old_post; 43 $_REQUEST = $old_request; 44 } 45 } 46 12 47 /** 13 48 * @covers ::bbp_form_forum_title … … 35 70 36 71 /** 72 * @covers ::bbp_form_forum_title 73 * @covers ::bbp_get_form_forum_title 74 */ 75 public function test_bbp_get_form_forum_title_from_post() { 76 $this->assertSame( '', bbp_get_form_forum_title() ); 77 78 $this->with_forum_post( 'bbp-new-forum', array( 'bbp_forum_title' => 'Posted forum' ), function() { 79 $this->assertSame( 'Posted forum', bbp_get_form_forum_title() ); 80 $this->expectOutputString( 'Posted forum' ); 81 bbp_form_forum_title(); 82 } ); 83 } 84 85 /** 37 86 * @covers ::bbp_form_forum_content 38 87 * @covers ::bbp_get_form_forum_content 39 * @todo Implement test_bbp_form_forum_content().40 * @todo Implement test_bbp_get_form_forum_content().41 88 */ 42 89 public function test_bbp_get_form_forum_content() { 43 // Remove the following lines when you implement this test. 44 $this->markTestIncomplete( 45 'This test has not been implemented yet.' 46 ); 90 $this->assertSame( '', bbp_get_form_forum_content() ); 91 92 $forum_id = $this->factory->forum->create( array( 'post_content' => 'Saved forum content' ) ); 93 $this->with_forum_edit( $forum_id, function() { 94 $this->assertSame( 'Saved forum content', bbp_get_form_forum_content() ); 95 } ); 96 97 $this->with_forum_post( 'bbp-new-forum', array( 'bbp_forum_content' => 'Submitted \\"content\\"' ), function() { 98 $this->assertSame( 'Submitted "content"', bbp_get_form_forum_content() ); 99 $this->expectOutputString( 'Submitted "content"' ); 100 bbp_form_forum_content(); 101 } ); 102 } 103 104 /** 105 * @covers ::bbp_form_forum_moderators 106 * @covers ::bbp_get_form_forum_moderators 107 */ 108 public function test_bbp_get_form_forum_moderators() { 109 $this->assertSame( '', bbp_get_form_forum_moderators() ); 110 111 $user_id = $this->factory->user->create(); 112 $forum_id = $this->factory->forum->create(); 113 bbp_add_moderator( $forum_id, $user_id ); 114 $this->with_forum_edit( $forum_id, function() use ( $user_id, $forum_id ) { 115 $this->assertSame( $forum_id, get_the_ID() ); 116 $this->assertContains( $user_id, bbp_get_moderator_ids( $forum_id ) ); 117 $this->assertSame( get_userdata( $user_id )->user_nicename, bbp_get_form_forum_moderators() ); 118 } ); 119 120 $this->with_forum_post( 'bbp-new-forum', array( 'bbp_moderators' => 'posted-moderator' ), function() { 121 $this->assertSame( 'posted-moderator', bbp_get_form_forum_moderators() ); 122 $this->expectOutputString( 'posted-moderator' ); 123 bbp_form_forum_moderators(); 124 } ); 47 125 } 48 126 … … 50 128 * @covers ::bbp_form_forum_parent 51 129 * @covers ::bbp_get_form_forum_parent 52 * @todo Implement test_bbp_form_forum_parent().53 * @todo Implement test_bbp_get_form_forum_parent().54 130 */ 55 131 public function test_bbp_get_form_forum_parent() { 56 // Remove the following lines when you implement this test. 57 $this->markTestIncomplete( 58 'This test has not been implemented yet.' 59 ); 132 $this->assertSame( 0, bbp_get_form_forum_parent() ); 133 134 $parent_id = $this->factory->forum->create(); 135 $forum_id = $this->factory->forum->create( array( 'post_parent' => $parent_id ) ); 136 $this->with_forum_edit( $forum_id, function() use ( $parent_id ) { 137 $this->assertSame( $parent_id, bbp_get_form_forum_parent() ); 138 } ); 139 140 $this->with_forum_post( 'bbp-new-forum', array( 'bbp_forum_id' => (string) $parent_id ), function() use ( $parent_id ) { 141 $this->assertSame( $parent_id, bbp_get_form_forum_parent() ); 142 $this->expectOutputString( (string) $parent_id ); 143 bbp_form_forum_parent(); 144 } ); 60 145 } 61 146 … … 63 148 * @covers ::bbp_form_forum_type 64 149 * @covers ::bbp_get_form_forum_type 65 * @todo Implement test_bbp_form_forum_type().66 * @todo Implement test_bbp_get_form_forum_type().67 150 */ 68 151 public function test_bbp_get_form_forum_type() { 69 // Remove the following lines when you implement this test. 70 $this->markTestIncomplete( 71 'This test has not been implemented yet.' 72 ); 152 $this->assertSame( 'forum', bbp_get_form_forum_type() ); 153 154 $forum_id = $this->factory->forum->create(); 155 bbp_categorize_forum( $forum_id ); 156 $this->with_forum_edit( $forum_id, function() { 157 $this->assertSame( 'category', bbp_get_form_forum_type() ); 158 } ); 159 160 $this->with_forum_post( 'bbp-new-forum', array( 'bbp_forum_type' => 'CATEGORY' ), function() { 161 $this->assertSame( 'category', bbp_get_form_forum_type() ); 162 $this->expectOutputString( 'category' ); 163 bbp_form_forum_type(); 164 } ); 73 165 } 74 166 … … 76 168 * @covers ::bbp_form_forum_visibility 77 169 * @covers ::bbp_get_form_forum_visibility 78 * @todo Implement test_bbp_form_forum_visibility().79 * @todo Implement test_bbp_get_form_forum_visibility().80 170 */ 81 171 public function test_bbp_get_form_forum_visibility() { 82 // Remove the following lines when you implement this test. 83 $this->markTestIncomplete( 84 'This test has not been implemented yet.' 85 ); 172 $this->assertSame( bbp_get_public_status_id(), bbp_get_form_forum_visibility() ); 173 174 $forum_id = $this->factory->forum->create(); 175 bbp_hide_forum( $forum_id ); 176 $this->with_forum_edit( $forum_id, function() { 177 $this->assertSame( bbp_get_hidden_status_id(), bbp_get_form_forum_visibility() ); 178 } ); 179 180 $this->with_forum_post( 'bbp-new-forum', array( 'bbp_forum_visibility' => 'PRIVATE' ), function() { 181 $this->assertSame( bbp_get_private_status_id(), bbp_get_form_forum_visibility() ); 182 $this->expectOutputString( bbp_get_private_status_id() ); 183 bbp_form_forum_visibility(); 184 } ); 86 185 } 87 186 … … 89 188 * @covers ::bbp_form_forum_subscribed 90 189 * @covers ::bbp_get_form_forum_subscribed 91 * @todo Implement test_bbp_form_forum_subscribed().92 * @todo Implement test_bbp_get_form_forum_subscribed().93 190 */ 94 191 public function test_bbp_get_form_forum_subscribed() { 95 // Remove the following lines when you implement this test. 96 $this->markTestIncomplete( 97 'This test has not been implemented yet.' 98 ); 192 $this->assertSame( '', bbp_get_form_forum_subscribed() ); 193 194 $user_id = $this->factory->user->create(); 195 $forum_id = $this->factory->forum->create( array( 'post_author' => $user_id ) ); 196 bbp_add_user_forum_subscription( $user_id, $forum_id ); 197 $this->with_forum_edit( $forum_id, function() { 198 $this->assertSame( checked( true, true, false ), bbp_get_form_forum_subscribed() ); 199 } ); 200 201 $old_user = get_current_user_id(); 202 $old_forum_id = bbpress()->current_forum_id; 203 $this->set_current_user( $user_id ); 204 bbpress()->current_forum_id = $forum_id; 205 add_filter( 'bbp_is_single_forum', '__return_true' ); 206 try { 207 $this->assertSame( checked( true, true, false ), bbp_get_form_forum_subscribed() ); 208 } finally { 209 remove_filter( 'bbp_is_single_forum', '__return_true' ); 210 bbpress()->current_forum_id = $old_forum_id; 211 $this->set_current_user( $old_user ); 212 } 213 214 $this->with_forum_post( 'bbp-new-forum', array( 'bbp_forum_subscription' => '1' ), function() { 215 $checked = checked( true, true, false ); 216 $this->assertSame( $checked, bbp_get_form_forum_subscribed() ); 217 $this->expectOutputString( $checked ); 218 bbp_form_forum_subscribed(); 219 } ); 99 220 } 100 221 … … 102 223 * @covers ::bbp_form_forum_type_dropdown 103 224 * @covers ::bbp_get_form_forum_type_dropdown 104 * @todo Implement test_bbp_form_forum_type_dropdown().105 * @todo Implement test_bbp_get_form_forum_type_dropdown().106 225 */ 107 226 public function test_bbp_get_form_forum_type_dropdown() { 108 // Remove the following lines when you implement this test. 109 $this->markTestIncomplete( 110 'This test has not been implemented yet.' 227 $args = array( 'select_id' => 'custom_forum_type', 'selected' => 'category' ); 228 $html = bbp_get_form_forum_type_dropdown( $args ); 229 $this->assertStringContainsString( 'name="custom_forum_type"', $html ); 230 $this->assertStringContainsString( 'id="custom_forum_type_select"', $html ); 231 $this->assertMatchesRegularExpression( '/<option value="category" selected=/', $html ); 232 $this->assertStringContainsString( '<option value="forum"', $html ); 233 $this->expectOutputString( $html ); 234 bbp_form_forum_type_dropdown( $args ); 235 } 236 237 /** 238 * @covers ::bbp_get_form_forum_type_dropdown 239 */ 240 public function test_bbp_get_form_forum_type_dropdown_selects_forum_by_default() { 241 $this->assertMatchesRegularExpression( 242 '/<option value="forum" selected=/', 243 bbp_get_form_forum_type_dropdown() 111 244 ); 112 245 } … … 115 248 * @covers ::bbp_form_forum_status_dropdown 116 249 * @covers ::bbp_get_form_forum_status_dropdown 117 * @todo Implement test_bbp_form_forum_status_dropdown().118 * @todo Implement test_bbp_get_form_forum_status_dropdown().119 250 */ 120 251 public function test_bbp_get_form_forum_status_dropdown() { 121 // Remove the following lines when you implement this test. 122 $this->markTestIncomplete( 123 'This test has not been implemented yet.' 124 ); 252 $args = array( 'select_id' => 'custom_forum_status', 'selected' => 'closed' ); 253 $html = bbp_get_form_forum_status_dropdown( $args ); 254 $this->assertStringContainsString( 'name="custom_forum_status"', $html ); 255 $this->assertMatchesRegularExpression( '/<option value="closed" selected=/', $html ); 256 $this->assertStringContainsString( '<option value="open"', $html ); 257 $this->expectOutputString( $html ); 258 bbp_form_forum_status_dropdown( $args ); 125 259 } 126 260 … … 128 262 * @covers ::bbp_form_forum_visibility_dropdown 129 263 * @covers ::bbp_get_form_forum_visibility_dropdown 130 * @todo Implement test_bbp_form_forum_visibility_dropdown().131 * @todo Implement test_bbp_get_form_forum_visibility_dropdown().132 264 */ 133 265 public function test_bbp_get_form_forum_visibility_dropdown() { 134 // Remove the following lines when you implement this test. 135 $this->markTestIncomplete( 136 'This test has not been implemented yet.' 137 ); 266 $args = array( 'select_id' => 'custom_forum_visibility', 'selected' => bbp_get_private_status_id() ); 267 $html = bbp_get_form_forum_visibility_dropdown( $args ); 268 $this->assertStringContainsString( 'name="custom_forum_visibility"', $html ); 269 $this->assertMatchesRegularExpression( '/<option value="private" selected=/', $html ); 270 $this->assertStringContainsString( '<option value="publish"', $html ); 271 $this->assertStringContainsString( '<option value="hidden"', $html ); 272 $this->expectOutputString( $html ); 273 bbp_form_forum_visibility_dropdown( $args ); 274 } 275 276 /** 277 * @covers ::bbp_get_form_forum_visibility_dropdown 278 */ 279 public function test_bbp_get_form_forum_visibility_dropdown_has_distinct_filter() { 280 $filter = function( $html ) { 281 return 'filtered visibility'; 282 }; 283 add_filter( 'bbp_get_form_forum_visibility_dropdown', $filter ); 284 try { 285 $this->assertSame( 'filtered visibility', bbp_get_form_forum_visibility_dropdown() ); 286 } finally { 287 remove_filter( 'bbp_get_form_forum_visibility_dropdown', $filter ); 288 } 289 } 290 291 /** 292 * @covers ::bbp_get_form_forum_visibility_dropdown 293 */ 294 public function test_bbp_get_form_forum_visibility_dropdown_preserves_type_filter() { 295 $filter = function( $html, $parsed_args, $args ) { 296 $this->assertSame( 'bbp_forum_visibility', $parsed_args['select_id'] ); 297 $this->assertSame( array(), $args ); 298 return 'filtered by type hook'; 299 }; 300 add_filter( 'bbp_get_form_forum_type_dropdown', $filter, 10, 3 ); 301 try { 302 $this->assertSame( 'filtered by type hook', bbp_get_form_forum_visibility_dropdown() ); 303 } finally { 304 remove_filter( 'bbp_get_form_forum_type_dropdown', $filter ); 305 } 138 306 } 139 307 140 308 /** 141 309 * @covers ::bbp_is_forum_form_post_request 142 * @todo Implement test_bbp_is_forum_form_post_request().143 310 */ 144 311 public function test_bbp_is_forum_form_post_request() { 145 // Remove the following lines when you implement this test. 146 $this->markTestIncomplete( 147 'This test has not been implemented yet.' 148 ); 312 $this->assertFalse( bbp_is_forum_form_post_request() ); 313 314 $this->with_forum_post( 'bbp-new-forum', array(), function() { 315 $this->assertTrue( bbp_is_forum_form_post_request() ); 316 317 $nonce = $_REQUEST['_wpnonce']; 318 $_REQUEST['_wpnonce'] = 'invalid'; 319 $this->assertFalse( bbp_is_forum_form_post_request() ); 320 $_REQUEST['_wpnonce'] = $nonce; 321 322 $_SERVER['REQUEST_METHOD'] = 'GET'; 323 $this->assertFalse( bbp_is_forum_form_post_request() ); 324 } ); 325 326 $forum_id = $this->factory->forum->create(); 327 $this->with_forum_edit( $forum_id, function() use ( $forum_id ) { 328 $this->with_forum_post( 'bbp-edit-forum_' . $forum_id, array(), function() { 329 $this->assertTrue( bbp_is_forum_form_post_request() ); 330 } ); 331 } ); 149 332 } 150 333 }
Note:
See TracChangeset
for help on using the changeset viewer.