Changeset 7792
- Timestamp:
- 10/04/2026 08:48:01 AM (3 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/topics/template/links.php
r6802 r7792 10 10 class BBP_Tests_Topics_Template_Links extends BBP_UnitTestCase { 11 11 12 private function with_keymaster_topic( $callback ) { 13 $old_user = get_current_user_id(); 14 $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); 15 $forum_id = $this->factory->forum->create(); 16 $topic_id = $this->factory->topic->create( array( 17 'post_parent' => $forum_id, 18 'post_author' => $user_id, 19 'topic_meta' => array( 'forum_id' => $forum_id ), 20 ) ); 21 bbp_set_user_role( $user_id, bbp_get_keymaster_role() ); 22 $this->set_current_user( $user_id ); 23 24 try { 25 $callback( $topic_id, $forum_id, $user_id ); 26 } finally { 27 $this->set_current_user( $old_user ); 28 } 29 } 30 12 31 /** 13 32 * @covers ::bbp_topic_subscription_link 14 33 * @covers ::bbp_get_topic_subscription_link 15 * @todo Implement test_bbp_get_topic_subscription_link().16 34 */ 17 35 public function test_bbp_get_topic_subscription_link() { 18 // Remove the following lines when you implement this test. 19 $this->markTestIncomplete( 20 'This test has not been implemented yet.' 21 ); 36 $old_user = get_current_user_id(); 37 $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); 38 $forum_id = $this->factory->forum->create(); 39 $topic_id = $this->factory->topic->create( array( 40 'post_parent' => $forum_id, 41 'topic_meta' => array( 'forum_id' => $forum_id ), 42 ) ); 43 $args = array( 'user_id' => $user_id, 'object_id' => $topic_id, 'before' => '' ); 44 bbp_set_user_role( $user_id, bbp_get_keymaster_role() ); 45 $this->set_current_user( $user_id ); 46 47 try { 48 $this->assertStringContainsString( 'Subscribe', bbp_get_topic_subscription_link( $args ) ); 49 bbp_add_user_topic_subscription( $user_id, $topic_id ); 50 $html = bbp_get_topic_subscription_link( $args ); 51 $this->assertStringContainsString( 'Unsubscribe', $html ); 52 $this->expectOutputString( $html ); 53 bbp_topic_subscription_link( $args ); 54 } finally { 55 $this->set_current_user( $old_user ); 56 } 22 57 } 23 58 … … 25 60 * @covers ::bbp_topic_favorite_link 26 61 * @covers ::bbp_get_topic_favorite_link 27 * @todo Implement test_bbp_get_topic_favorite_link().28 62 */ 29 63 public function test_bbp_get_topic_favorite_link() { 30 // Remove the following lines when you implement this test. 31 $this->markTestIncomplete( 32 'This test has not been implemented yet.' 33 ); 64 $old_user = get_current_user_id(); 65 $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); 66 $forum_id = $this->factory->forum->create(); 67 $topic_id = $this->factory->topic->create( array( 68 'post_parent' => $forum_id, 69 'topic_meta' => array( 'forum_id' => $forum_id ), 70 ) ); 71 $args = array( 'user_id' => $user_id, 'object_id' => $topic_id ); 72 bbp_set_user_role( $user_id, bbp_get_keymaster_role() ); 73 $this->set_current_user( $user_id ); 74 75 try { 76 $this->assertStringContainsString( 'Favorite', bbp_get_topic_favorite_link( $args ) ); 77 bbp_add_user_favorite( $user_id, $topic_id ); 78 $html = bbp_get_topic_favorite_link( $args ); 79 $this->assertStringContainsString( 'Unfavorite', $html ); 80 $this->expectOutputString( $html ); 81 bbp_topic_favorite_link( $args ); 82 } finally { 83 $this->set_current_user( $old_user ); 84 } 34 85 } 35 86 … … 213 264 * @covers ::bbp_topic_replies_link 214 265 * @covers ::bbp_get_topic_replies_link 215 * @todo Implement test_bbp_get_topic_replies_link().216 266 */ 217 267 public function test_bbp_get_topic_replies_link() { 218 // Remove the following lines when you implement this test. 219 $this->markTestIncomplete( 220 'This test has not been implemented yet.' 221 ); 268 $forum_id = $this->factory->forum->create(); 269 $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) ); 270 $this->assertSame( '0 replies', bbp_get_topic_replies_link( $topic_id ) ); 271 272 $this->factory->reply->create( array( 'post_parent' => $topic_id ) ); 273 $html = bbp_get_topic_replies_link( $topic_id ); 274 $this->assertSame( '1 reply', $html ); 275 $this->expectOutputString( $html ); 276 bbp_topic_replies_link( $topic_id ); 222 277 } 223 278 … … 225 280 * @covers ::bbp_topic_admin_links 226 281 * @covers ::bbp_get_topic_admin_links 227 * @todo Implement test_bbp_get_topic_admin_links().228 282 */ 229 283 public function test_bbp_get_topic_admin_links() { 230 // Remove the following lines when you implement this test. 231 $this->markTestIncomplete( 232 'This test has not been implemented yet.' 233 ); 284 $this->with_keymaster_topic( function( $topic_id ) { 285 $args = array( 'id' => $topic_id, 'before' => '[', 'after' => ']', 'sep' => ', ', 'links' => array( 'edit' => 'Edit', 'close' => 'Close' ) ); 286 $this->assertSame( '[Edit, Close]', bbp_get_topic_admin_links( $args ) ); 287 $this->assertStringContainsString( 'bbp-topic-edit-link', bbp_get_topic_admin_links( array( 'id' => $topic_id ) ) ); 288 $this->expectOutputString( '[Edit, Close]' ); 289 bbp_topic_admin_links( $args ); 290 } ); 234 291 } 235 292 … … 237 294 * @covers ::bbp_topic_edit_link 238 295 * @covers ::bbp_get_topic_edit_link 239 * @todo Implement test_bbp_get_topic_edit_link().240 296 */ 241 297 public function test_bbp_get_topic_edit_link() { 242 // Remove the following lines when you implement this test. 243 $this->markTestIncomplete( 244 'This test has not been implemented yet.' 245 ); 298 $this->with_keymaster_topic( function( $topic_id ) { 299 $args = array( 'id' => $topic_id, 'edit_text' => 'Edit topic' ); 300 $html = bbp_get_topic_edit_link( $args ); 301 $this->assertStringContainsString( 'class="bbp-topic-edit-link"', $html ); 302 $this->assertStringContainsString( '>Edit topic</a>', $html ); 303 $this->assertStringContainsString( esc_url( bbp_get_topic_edit_url( $topic_id ) ), $html ); 304 $this->expectOutputString( $html ); 305 bbp_topic_edit_link( $args ); 306 } ); 246 307 } 247 308 … … 249 310 * @covers ::bbp_topic_edit_url 250 311 * @covers ::bbp_get_topic_edit_url 251 * @todo Implement test_bbp_get_topic_edit_url().252 312 */ 253 313 public function test_bbp_get_topic_edit_url() { 254 // Remove the following lines when you implement this test. 255 $this->markTestIncomplete( 256 'This test has not been implemented yet.' 257 ); 314 $this->assertNull( bbp_get_topic_edit_url( PHP_INT_MAX ) ); 315 $this->with_keymaster_topic( function( $topic_id ) { 316 $url = bbp_get_topic_edit_url( $topic_id ); 317 if ( false === strpos( bbp_get_topic_permalink( $topic_id ), '?' ) ) { 318 $this->assertStringContainsString( bbp_get_edit_slug(), $url ); 319 } else { 320 $this->assertStringContainsString( bbp_get_edit_rewrite_id() . '=1', $url ); 321 } 322 $this->expectOutputString( esc_url( $url ) ); 323 bbp_topic_edit_url( $topic_id ); 324 } ); 258 325 } 259 326 … … 261 328 * @covers ::bbp_topic_trash_link 262 329 * @covers ::bbp_get_topic_trash_link 263 * @todo Implement test_bbp_get_topic_trash_link().264 330 */ 265 331 public function test_bbp_get_topic_trash_link() { 266 // Remove the following lines when you implement this test. 267 $this->markTestIncomplete( 268 'This test has not been implemented yet.' 269 ); 332 $this->with_keymaster_topic( function( $topic_id ) { 333 $args = array( 'id' => $topic_id ); 334 $html = bbp_get_topic_trash_link( $args ); 335 $this->assertStringContainsString( 'class="bbp-topic-trash-link">Trash</a>', $html ); 336 $this->expectOutputString( $html ); 337 bbp_topic_trash_link( $args ); 338 339 wp_trash_post( $topic_id ); 340 $trashed_html = bbp_get_topic_trash_link( $args ); 341 $this->assertStringContainsString( 'class="bbp-topic-restore-link">Restore</a>', $trashed_html ); 342 $this->assertStringContainsString( 'class="bbp-topic-delete-link">Delete</a>', $trashed_html ); 343 } ); 270 344 } 271 345 … … 273 347 * @covers ::bbp_topic_close_link 274 348 * @covers ::bbp_get_topic_close_link 275 * @todo Implement test_bbp_get_topic_close_link().276 349 */ 277 350 public function test_bbp_get_topic_close_link() { 278 // Remove the following lines when you implement this test. 279 $this->markTestIncomplete( 280 'This test has not been implemented yet.' 281 ); 351 $this->with_keymaster_topic( function( $topic_id ) { 352 $args = array( 'id' => $topic_id ); 353 $html = bbp_get_topic_close_link( $args ); 354 $this->assertStringContainsString( 'class="bbp-topic-close-link">Close</a>', $html ); 355 $this->expectOutputString( $html ); 356 bbp_topic_close_link( $args ); 357 bbp_close_topic( $topic_id ); 358 $this->assertStringContainsString( 'class="bbp-topic-close-link">Open</a>', bbp_get_topic_close_link( $args ) ); 359 } ); 282 360 } 283 361 … … 285 363 * @covers ::bbp_topic_approve_link 286 364 * @covers ::bbp_get_topic_approve_link 287 * @todo Implement test_bbp_get_topic_approve_link().288 365 */ 289 366 public function test_bbp_get_topic_approve_link() { 290 // Remove the following lines when you implement this test. 291 $this->markTestIncomplete( 292 'This test has not been implemented yet.' 293 ); 367 $this->with_keymaster_topic( function( $topic_id ) { 368 $args = array( 'id' => $topic_id ); 369 $html = bbp_get_topic_approve_link( $args ); 370 $this->assertStringContainsString( 'class="bbp-topic-approve-link">Unapprove</a>', $html ); 371 $this->expectOutputString( $html ); 372 bbp_topic_approve_link( $args ); 373 bbp_unapprove_topic( $topic_id ); 374 $this->assertStringContainsString( 'class="bbp-topic-approve-link">Approve</a>', bbp_get_topic_approve_link( $args ) ); 375 } ); 294 376 } 295 377 … … 297 379 * @covers ::bbp_topic_stick_link 298 380 * @covers ::bbp_get_topic_stick_link 299 * @todo Implement test_bbp_get_topic_stick_link().300 381 */ 301 382 public function test_bbp_get_topic_stick_link() { 302 // Remove the following lines when you implement this test. 303 $this->markTestIncomplete( 304 'This test has not been implemented yet.' 305 ); 383 $this->with_keymaster_topic( function( $topic_id ) { 384 $args = array( 'id' => $topic_id ); 385 $html = bbp_get_topic_stick_link( $args ); 386 $this->assertStringContainsString( 'class="bbp-topic-sticky-link">Stick</a>', $html ); 387 $this->assertStringContainsString( 'class="bbp-topic-super-sticky-link">(to front)</a>', $html ); 388 $this->expectOutputString( $html ); 389 bbp_topic_stick_link( $args ); 390 391 bbp_stick_topic( $topic_id ); 392 $this->assertStringContainsString( 'class="bbp-topic-sticky-link">Unstick</a>', bbp_get_topic_stick_link( $args ) ); 393 } ); 306 394 } 307 395 … … 309 397 * @covers ::bbp_topic_merge_link 310 398 * @covers ::bbp_get_topic_merge_link 311 * @todo Implement test_bbp_get_topic_merge_link().312 399 */ 313 400 public function test_bbp_get_topic_merge_link() { 314 // Remove the following lines when you implement this test. 315 $this->markTestIncomplete( 316 'This test has not been implemented yet.' 317 ); 401 $this->with_keymaster_topic( function( $topic_id ) { 402 $args = array( 'id' => $topic_id ); 403 $html = bbp_get_topic_merge_link( $args ); 404 $this->assertStringContainsString( 'class="bbp-topic-merge-link">Merge</a>', $html ); 405 $this->assertStringContainsString( 'action=merge', $html ); 406 $this->expectOutputString( $html ); 407 bbp_topic_merge_link( $args ); 408 } ); 318 409 } 319 410 … … 321 412 * @covers ::bbp_topic_spam_link 322 413 * @covers ::bbp_get_topic_spam_link 323 * @todo Implement test_bbp_get_topic_spam_link().324 414 */ 325 415 public function test_bbp_get_topic_spam_link() { 326 // Remove the following lines when you implement this test. 327 $this->markTestIncomplete( 328 'This test has not been implemented yet.' 329 ); 416 $this->with_keymaster_topic( function( $topic_id ) { 417 $args = array( 'id' => $topic_id ); 418 $html = bbp_get_topic_spam_link( $args ); 419 $this->assertStringContainsString( 'class="bbp-topic-spam-link">Spam</a>', $html ); 420 $this->expectOutputString( $html ); 421 bbp_topic_spam_link( $args ); 422 bbp_spam_topic( $topic_id ); 423 $this->assertStringContainsString( 'class="bbp-topic-spam-link">Unspam</a>', bbp_get_topic_spam_link( $args ) ); 424 } ); 330 425 } 331 426 … … 333 428 * @covers ::bbp_topic_reply_link 334 429 * @covers ::bbp_get_topic_reply_link 335 * @todo Implement test_bbp_get_topic_reply_link().336 430 */ 337 431 public function test_bbp_get_topic_reply_link() { 338 // Remove the following lines when you implement this test. 339 $this->markTestIncomplete( 340 'This test has not been implemented yet.' 341 ); 432 $this->with_keymaster_topic( function( $topic_id ) { 433 $args = array( 'id' => $topic_id, 'reply_text' => 'Respond' ); 434 $html = bbp_get_topic_reply_link( $args ); 435 $this->assertStringContainsString( 'class="bbp-topic-reply-link"', $html ); 436 $this->assertStringContainsString( '#new-post', $html ); 437 $this->assertStringContainsString( '>Respond</a>', $html ); 438 $this->expectOutputString( $html ); 439 bbp_topic_reply_link( $args ); 440 } ); 342 441 } 343 442 … … 345 444 * @covers ::bbp_forum_pagination_links 346 445 * @covers ::bbp_get_forum_pagination_links 347 * @todo Implement test_bbp_get_forum_pagination_links().348 446 */ 349 447 public function test_bbp_get_forum_pagination_links() { 350 // Remove the following lines when you implement this test. 351 $this->markTestIncomplete( 352 'This test has not been implemented yet.' 353 ); 448 $old_query = bbpress()->topic_query; 449 try { 450 bbpress()->topic_query = null; 451 $this->assertFalse( bbp_get_forum_pagination_links() ); 452 453 bbpress()->topic_query = (object) array( 'pagination_links' => '<a href="?page=2">2</a>' ); 454 $this->assertSame( '<a href="?page=2">2</a>', bbp_get_forum_pagination_links() ); 455 $this->expectOutputString( '<a href="?page=2">2</a>' ); 456 bbp_forum_pagination_links(); 457 } finally { 458 bbpress()->topic_query = $old_query; 459 } 354 460 } 355 461 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)