Changeset 7786
- Timestamp:
- 10/04/2026 08:15:48 AM (6 weeks ago)
- Location:
- trunk/tests/phpunit/testcases
- Files:
-
- 2 edited
-
replies/template/forms.php (modified) (7 diffs)
-
topics/template/forms.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/replies/template/forms.php
r7461 r7786 9 9 */ 10 10 class BBP_Tests_Replies_Template_Forms extends BBP_UnitTestCase { 11 12 private function with_reply_edit( $reply_id, $callback ) { 13 $old_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null; 14 $old_reply_id = bbpress()->current_reply_id; 15 $GLOBALS['post'] = get_post( $reply_id ); 16 bbpress()->current_reply_id = $reply_id; 17 setup_postdata( $GLOBALS['post'] ); 18 add_filter( 'bbp_is_reply_edit', '__return_true' ); 19 20 try { 21 $callback(); 22 } finally { 23 remove_filter( 'bbp_is_reply_edit', '__return_true' ); 24 bbpress()->current_reply_id = $old_reply_id; 25 $GLOBALS['post'] = $old_post; 26 wp_reset_postdata(); 27 } 28 } 29 30 private function with_reply_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 } 11 46 12 47 /** … … 71 106 * @covers ::bbp_form_reply_content 72 107 * @covers ::bbp_get_form_reply_content 73 * @todo Implement test_bbp_get_form_reply_content().74 108 */ 75 109 public function test_bbp_get_form_reply_content() { 76 // Remove the following lines when you implement this test. 77 $this->markTestIncomplete( 78 'This test has not been implemented yet.' 79 ); 110 $this->assertSame( '', bbp_get_form_reply_content() ); 111 $topic_id = $this->factory->topic->create(); 112 $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_content' => 'Saved reply' ) ); 113 $this->with_reply_edit( $reply_id, function() { 114 $this->assertSame( 'Saved reply', bbp_get_form_reply_content() ); 115 } ); 116 $this->with_reply_post( 'bbp-new-reply', array( 'bbp_reply_content' => wp_slash( 'Posted "reply"' ) ), function() { 117 $this->assertSame( 'Posted "reply"', bbp_get_form_reply_content() ); 118 $this->expectOutputString( 'Posted "reply"' ); 119 bbp_form_reply_content(); 120 } ); 80 121 } 81 122 … … 83 124 * @covers ::bbp_form_reply_to 84 125 * @covers ::bbp_get_form_reply_to 85 * @todo Implement test_bbp_get_form_reply_to().86 126 */ 87 127 public function test_bbp_get_form_reply_to() { 88 // Remove the following lines when you implement this test. 89 $this->markTestIncomplete( 90 'This test has not been implemented yet.' 91 ); 128 $this->assertSame( 0, bbp_get_form_reply_to() ); 129 $forum_id = $this->factory->forum->create(); 130 $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) ); 131 $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) ); 132 $old_request = $_REQUEST; 133 try { 134 $_REQUEST['bbp_reply_to'] = (string) $reply_id; 135 $this->assertSame( $reply_id, bbp_get_form_reply_to() ); 136 $this->expectOutputString( (string) $reply_id ); 137 bbp_form_reply_to(); 138 } finally { 139 $_REQUEST = $old_request; 140 } 92 141 } 93 142 … … 95 144 * @covers ::bbp_reply_to_dropdown 96 145 * @covers ::bbp_get_reply_to_dropdown 97 * @todo Implement test_bbp_get_reply_to_dropdown().98 146 */ 99 147 public function test_bbp_get_reply_to_dropdown() { 100 // Remove the following lines when you implement this test. 101 $this->markTestIncomplete( 102 'This test has not been implemented yet.' 103 ); 148 $forum_id = $this->factory->forum->create(); 149 $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) ); 150 $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) ); 151 $child_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) ); 152 bbp_update_reply_to( $child_id, $reply_id ); 153 $html = bbp_get_reply_to_dropdown( $child_id ); 154 $this->assertStringContainsString( 'name="bbp_reply_to"', $html ); 155 $this->assertStringContainsString( 'value="' . $reply_id . '"', $html ); 156 $this->assertMatchesRegularExpression( '/value="' . $child_id . '"[^>]*disabled=/', $html ); 157 $this->expectOutputString( $html ); 158 bbp_reply_to_dropdown( $child_id ); 104 159 } 105 160 … … 107 162 * @covers ::bbp_form_reply_log_edit 108 163 * @covers ::bbp_get_form_reply_log_edit 109 * @todo Implement test_bbp_get_form_reply_log_edit().110 164 */ 111 165 public function test_bbp_get_form_reply_log_edit() { 112 // Remove the following lines when you implement this test. 113 $this->markTestIncomplete( 114 'This test has not been implemented yet.' 115 ); 166 $this->assertSame( ' checked=\'checked\'', bbp_get_form_reply_log_edit() ); 167 $this->with_reply_post( 'bbp-new-reply', array( 'bbp_log_reply_edit' => '0' ), function() { 168 $this->assertSame( '', bbp_get_form_reply_log_edit() ); 169 $this->expectOutputString( '' ); 170 bbp_form_reply_log_edit(); 171 } ); 116 172 } 117 173 … … 119 175 * @covers ::bbp_form_reply_edit_reason 120 176 * @covers ::bbp_get_form_reply_edit_reason 121 * @todo Implement test_bbp_get_form_reply_edit_reason().122 177 */ 123 178 public function test_bbp_get_form_reply_edit_reason() { 124 // Remove the following lines when you implement this test. 125 $this->markTestIncomplete( 126 'This test has not been implemented yet.' 127 ); 179 $this->assertSame( '', bbp_get_form_reply_edit_reason() ); 180 $this->with_reply_post( 'bbp-new-reply', array( 'bbp_reply_edit_reason' => wp_slash( 'Fixed "details"' ) ), function() { 181 $this->assertSame( 'Fixed "details"', bbp_get_form_reply_edit_reason() ); 182 $this->expectOutputString( 'Fixed "details"' ); 183 bbp_form_reply_edit_reason(); 184 } ); 128 185 } 129 186 … … 131 188 * @covers ::bbp_form_reply_status_dropdown 132 189 * @covers ::bbp_get_form_reply_status_dropdown 133 * @todo Implement test_bbp_get_form_reply_status_dropdown().134 190 */ 135 191 public function test_bbp_get_form_reply_status_dropdown() { 136 // Remove the following lines when you implement this test. 137 $this->markTestIncomplete( 138 'This test has not been implemented yet.' 139 ); 192 $args = array( 'select_id' => 'custom_reply_status', 'selected' => bbp_get_pending_status_id() ); 193 $html = bbp_get_form_reply_status_dropdown( $args ); 194 $this->assertStringContainsString( 'name="custom_reply_status"', $html ); 195 $this->assertMatchesRegularExpression( '/<option value="pending" selected=/', $html ); 196 $this->assertStringContainsString( '<option value="publish"', $html ); 197 $this->expectOutputString( $html ); 198 bbp_form_reply_status_dropdown( $args ); 140 199 } 141 200 142 201 /** 143 202 * @covers ::bbp_is_reply_form_post_request 144 * @todo Implement test_bbp_is_reply_form_post_request().145 203 */ 146 204 public function test_bbp_is_reply_form_post_request() { 147 // Remove the following lines when you implement this test. 148 $this->markTestIncomplete( 149 'This test has not been implemented yet.' 150 ); 205 $this->assertFalse( bbp_is_reply_form_post_request() ); 206 $this->with_reply_post( 'bbp-new-reply', array(), function() { 207 $this->assertTrue( bbp_is_reply_form_post_request() ); 208 $nonce = $_REQUEST['_wpnonce']; 209 $_REQUEST['_wpnonce'] = 'invalid'; 210 $this->assertFalse( bbp_is_reply_form_post_request() ); 211 $_REQUEST['_wpnonce'] = $nonce; 212 $_SERVER['REQUEST_METHOD'] = 'GET'; 213 $this->assertFalse( bbp_is_reply_form_post_request() ); 214 } ); 215 $this->with_reply_post( 'bbp-edit-reply', array(), function() { 216 $this->assertTrue( bbp_is_reply_form_post_request() ); 217 } ); 151 218 } 152 219 } -
trunk/tests/phpunit/testcases/topics/template/forms.php
r7463 r7786 16 16 */ 17 17 protected $topic_tag_name = ''; 18 19 private function with_topic_edit( $topic_id, $callback ) { 20 $old_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null; 21 $old_topic_id = bbpress()->current_topic_id; 22 $GLOBALS['post'] = get_post( $topic_id ); 23 bbpress()->current_topic_id = $topic_id; 24 setup_postdata( $GLOBALS['post'] ); 25 add_filter( 'bbp_is_topic_edit', '__return_true' ); 26 27 try { 28 $callback(); 29 } finally { 30 remove_filter( 'bbp_is_topic_edit', '__return_true' ); 31 bbpress()->current_topic_id = $old_topic_id; 32 $GLOBALS['post'] = $old_post; 33 wp_reset_postdata(); 34 } 35 } 36 37 private function with_topic_post( $action, $values, $callback ) { 38 $old_method = $_SERVER['REQUEST_METHOD']; 39 $old_post = $_POST; 40 $old_request = $_REQUEST; 41 $_SERVER['REQUEST_METHOD'] = 'POST'; 42 $_POST = $values; 43 $_REQUEST = array_merge( $old_request, $values, array( '_wpnonce' => wp_create_nonce( $action ) ) ); 44 45 try { 46 $callback(); 47 } finally { 48 $_SERVER['REQUEST_METHOD'] = $old_method; 49 $_POST = $old_post; 50 $_REQUEST = $old_request; 51 } 52 } 18 53 19 54 /** … … 105 140 * @covers ::bbp_form_topic_type_dropdown 106 141 * @covers ::bbp_get_form_topic_type_dropdown 107 * @todo Implement test_bbp_get_form_topic_type_dropdown().108 142 */ 109 143 public function test_bbp_get_form_topic_type_dropdown() { 110 // Remove the following lines when you implement this test. 111 $this->markTestIncomplete( 112 'This test has not been implemented yet.' 113 ); 144 $args = array( 'select_id' => 'custom_topic_type', 'selected' => 'stick' ); 145 $html = bbp_get_form_topic_type_dropdown( $args ); 146 $this->assertStringContainsString( 'name="custom_topic_type"', $html ); 147 $this->assertMatchesRegularExpression( '/<option value="stick" selected=/', $html ); 148 $this->assertStringContainsString( '<option value="unstick"', $html ); 149 $this->expectOutputString( $html ); 150 bbp_form_topic_type_dropdown( $args ); 114 151 } 115 152 … … 117 154 * @covers ::bbp_form_topic_status_dropdown 118 155 * @covers ::bbp_get_form_topic_status_dropdown 119 * @todo Implement test_bbp_get_form_topic_status_dropdown().120 156 */ 121 157 public function test_bbp_get_form_topic_status_dropdown() { 122 // Remove the following lines when you implement this test. 123 $this->markTestIncomplete( 124 'This test has not been implemented yet.' 125 ); 158 $args = array( 'select_id' => 'custom_topic_status', 'selected' => bbp_get_closed_status_id() ); 159 $html = bbp_get_form_topic_status_dropdown( $args ); 160 $this->assertStringContainsString( 'name="custom_topic_status"', $html ); 161 $this->assertMatchesRegularExpression( '/<option value="closed" selected=/', $html ); 162 $this->assertStringContainsString( '<option value="publish"', $html ); 163 $this->expectOutputString( $html ); 164 bbp_form_topic_status_dropdown( $args ); 126 165 } 127 166 … … 129 168 * @covers ::bbp_form_topic_title 130 169 * @covers ::bbp_get_form_topic_title 131 * @todo Implement test_bbp_get_form_topic_title().132 170 */ 133 171 public function test_bbp_get_form_topic_title() { 134 // Remove the following lines when you implement this test. 135 $this->markTestIncomplete( 136 'This test has not been implemented yet.' 137 ); 172 $this->assertSame( '', bbp_get_form_topic_title() ); 173 $topic_id = $this->factory->topic->create( array( 'post_title' => 'Saved title' ) ); 174 $this->with_topic_edit( $topic_id, function() { 175 $this->assertSame( 'Saved title', bbp_get_form_topic_title() ); 176 } ); 177 $this->with_topic_post( 'bbp-new-topic', array( 'bbp_topic_title' => wp_slash( 'Posted "title"' ) ), function() { 178 $this->assertSame( 'Posted "title"', bbp_get_form_topic_title() ); 179 $this->expectOutputString( 'Posted "title"' ); 180 bbp_form_topic_title(); 181 } ); 138 182 } 139 183 … … 141 185 * @covers ::bbp_form_topic_content 142 186 * @covers ::bbp_get_form_topic_content 143 * @todo Implement test_bbp_get_form_topic_content().144 187 */ 145 188 public function test_bbp_get_form_topic_content() { 146 // Remove the following lines when you implement this test. 147 $this->markTestIncomplete( 148 'This test has not been implemented yet.' 149 ); 189 $this->assertSame( '', bbp_get_form_topic_content() ); 190 $topic_id = $this->factory->topic->create( array( 'post_content' => 'Saved content' ) ); 191 $this->with_topic_edit( $topic_id, function() { 192 $this->assertSame( 'Saved content', bbp_get_form_topic_content() ); 193 } ); 194 $this->with_topic_post( 'bbp-new-topic', array( 'bbp_topic_content' => wp_slash( 'Posted "content"' ) ), function() { 195 $this->assertSame( 'Posted "content"', bbp_get_form_topic_content() ); 196 $this->expectOutputString( 'Posted "content"' ); 197 bbp_form_topic_content(); 198 } ); 150 199 } 151 200 … … 153 202 * @covers ::bbp_form_topic_tags 154 203 * @covers ::bbp_get_form_topic_tags 155 * @todo Implement test_bbp_get_form_topic_tags().156 204 */ 157 205 public function test_bbp_get_form_topic_tags() { 158 // Remove the following lines when you implement this test. 159 $this->markTestIncomplete( 160 'This test has not been implemented yet.' 161 ); 206 $this->assertSame( '', bbp_get_form_topic_tags() ); 207 $this->with_topic_post( 'bbp-new-topic', array( 'bbp_topic_tags' => wp_slash( 'alpha, beta' ) ), function() { 208 $this->assertSame( 'alpha, beta', bbp_get_form_topic_tags() ); 209 $this->expectOutputString( 'alpha, beta' ); 210 bbp_form_topic_tags(); 211 } ); 162 212 } 163 213 … … 165 215 * @covers ::bbp_form_topic_forum 166 216 * @covers ::bbp_get_form_topic_forum 167 * @todo Implement test_bbp_get_form_topic_forum().168 217 */ 169 218 public function test_bbp_get_form_topic_forum() { 170 // Remove the following lines when you implement this test. 171 $this->markTestIncomplete( 172 'This test has not been implemented yet.' 173 ); 219 $this->assertSame( 0, bbp_get_form_topic_forum() ); 220 $forum_id = $this->factory->forum->create(); 221 $this->with_topic_post( 'bbp-new-topic', array( 'bbp_forum_id' => (string) $forum_id ), function() use ( $forum_id ) { 222 $this->assertSame( $forum_id, bbp_get_form_topic_forum() ); 223 $this->expectOutputString( (string) $forum_id ); 224 bbp_form_topic_forum(); 225 } ); 174 226 } 175 227 … … 177 229 * @covers ::bbp_form_topic_subscribed 178 230 * @covers ::bbp_get_form_topic_subscribed 179 * @todo Implement test_bbp_get_form_topic_subscribed().180 231 */ 181 232 public function test_bbp_get_form_topic_subscribed() { 182 // Remove the following lines when you implement this test. 183 $this->markTestIncomplete( 184 'This test has not been implemented yet.' 185 ); 233 $this->assertSame( '', bbp_get_form_topic_subscribed() ); 234 $this->with_topic_post( 'bbp-new-topic', array( 'bbp_topic_subscription' => '1' ), function() { 235 $this->assertSame( ' checked=\'checked\'', bbp_get_form_topic_subscribed() ); 236 $this->expectOutputString( bbp_get_form_topic_subscribed() ); 237 bbp_form_topic_subscribed(); 238 } ); 186 239 } 187 240 … … 189 242 * @covers ::bbp_form_topic_log_edit 190 243 * @covers ::bbp_get_form_topic_log_edit 191 * @todo Implement test_bbp_get_form_topic_log_edit().192 244 */ 193 245 public function test_bbp_get_form_topic_log_edit() { 194 // Remove the following lines when you implement this test. 195 $this->markTestIncomplete( 196 'This test has not been implemented yet.' 197 ); 246 $this->assertSame( ' checked=\'checked\'', bbp_get_form_topic_log_edit() ); 247 $this->with_topic_post( 'bbp-new-topic', array( 'bbp_log_topic_edit' => '0' ), function() { 248 $this->assertSame( '', bbp_get_form_topic_log_edit() ); 249 $this->expectOutputString( '' ); 250 bbp_form_topic_log_edit(); 251 } ); 198 252 } 199 253 … … 201 255 * @covers ::bbp_form_topic_edit_reason 202 256 * @covers ::bbp_get_form_topic_edit_reason 203 * @todo Implement test_bbp_get_form_topic_edit_reason().204 257 */ 205 258 public function test_bbp_get_form_topic_edit_reason() { 206 // Remove the following lines when you implement this test. 207 $this->markTestIncomplete( 208 'This test has not been implemented yet.' 209 ); 259 $this->assertSame( '', bbp_get_form_topic_edit_reason() ); 260 $this->with_topic_post( 'bbp-new-topic', array( 'bbp_topic_edit_reason' => wp_slash( 'Fixed "details"' ) ), function() { 261 $this->assertSame( 'Fixed "details"', bbp_get_form_topic_edit_reason() ); 262 $this->expectOutputString( 'Fixed "details"' ); 263 bbp_form_topic_edit_reason(); 264 } ); 210 265 } 211 266 212 267 /** 213 268 * @covers ::bbp_is_topic_form_post_request 214 * @todo Implement test_bbp_is_topic_form_post_request().215 269 */ 216 270 public function test_bbp_is_topic_form_post_request() { 217 // Remove the following lines when you implement this test. 218 $this->markTestIncomplete( 219 'This test has not been implemented yet.' 220 ); 271 $this->assertFalse( bbp_is_topic_form_post_request() ); 272 $this->with_topic_post( 'bbp-new-topic', array(), function() { 273 $this->assertTrue( bbp_is_topic_form_post_request() ); 274 $nonce = $_REQUEST['_wpnonce']; 275 $_REQUEST['_wpnonce'] = 'invalid'; 276 $this->assertFalse( bbp_is_topic_form_post_request() ); 277 $_REQUEST['_wpnonce'] = $nonce; 278 $_SERVER['REQUEST_METHOD'] = 'GET'; 279 $this->assertFalse( bbp_is_topic_form_post_request() ); 280 } ); 281 $topic_id = $this->factory->topic->create(); 282 $this->with_topic_edit( $topic_id, function() use ( $topic_id ) { 283 $this->with_topic_post( 'bbp-edit-topic_' . $topic_id, array(), function() { 284 $this->assertTrue( bbp_is_topic_form_post_request() ); 285 } ); 286 } ); 221 287 } 222 288 }
Note:
See TracChangeset
for help on using the changeset viewer.