Changeset 7776
- Timestamp:
- 10/04/2026 03:44:23 AM (5 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/forums/functions/forum.php
r7455 r7776 9 9 */ 10 10 class BBP_Tests_Forums_Functions_Forum extends BBP_UnitTestCase { 11 12 /** 13 * Assert a forum lifecycle wrapper validates its target and fires its action. 14 * 15 * @param string $function Wrapper function. 16 * @param string $action Action name. 17 */ 18 protected function assert_forum_action_dispatches( $function, $action ) { 19 $forum_id = $this->factory->forum->create(); 20 $observed = array(); 21 $callback = function( $id ) use ( &$observed ) { 22 $observed[] = $id; 23 }; 24 25 add_action( $action, $callback ); 26 try { 27 $this->assertFalse( call_user_func( $function, 0 ) ); 28 call_user_func( $function, $forum_id ); 29 } finally { 30 remove_action( $action, $callback ); 31 } 32 33 $this->assertSame( array( $forum_id ), $observed ); 34 } 11 35 12 36 /** … … 156 180 /** 157 181 * @covers ::bbp_remove_forum_from_all_subscriptions 158 * @todo Implement test_bbp_remove_forum_from_all_subscriptions().159 182 */ 160 183 public function test_bbp_remove_forum_from_all_subscriptions() { 161 // Remove the following lines when you implement this test. 162 $this->markTestIncomplete( 163 'This test has not been implemented yet.' 164 ); 184 $forum_id = $this->factory->forum->create(); 185 $user_ids = $this->factory->user->create_many( 2 ); 186 187 foreach ( $user_ids as $user_id ) { 188 $this->assertTrue( bbp_add_user_subscription( $user_id, $forum_id ) ); 189 $this->assertTrue( bbp_is_user_subscribed( $user_id, $forum_id ) ); 190 } 191 192 bbp_remove_forum_from_all_subscriptions( $forum_id ); 193 foreach ( $user_ids as $user_id ) { 194 $this->assertFalse( bbp_is_user_subscribed( $user_id, $forum_id ) ); 195 } 165 196 } 166 197 … … 256 287 /** 257 288 * @covers ::bbp_trash_forum_topics 258 * @todo Implement test_bbp_trash_forum_topics().259 289 */ 260 290 public function test_bbp_trash_forum_topics() { 261 // Remove the following lines when you implement this test. 262 $this->markTestIncomplete( 263 'This test has not been implemented yet.' 264 ); 291 $forum_id = $this->factory->forum->create(); 292 $topic_id = $this->factory->topic->create( array( 293 'post_parent' => $forum_id, 294 'topic_meta' => array( 'forum_id' => $forum_id ), 295 ) ); 296 $spam_id = $this->factory->topic->create( array( 297 'post_parent' => $forum_id, 298 'post_status' => bbp_get_spam_status_id(), 299 'topic_meta' => array( 'forum_id' => $forum_id ), 300 ) ); 301 302 bbp_trash_forum_topics( $forum_id ); 303 304 $this->assertSame( 'trash', get_post_status( $topic_id ) ); 305 $this->assertSame( bbp_get_spam_status_id(), get_post_status( $spam_id ) ); 306 $this->assertSame( array( $topic_id ), get_post_meta( $forum_id, '_bbp_pre_trashed_topics', true ) ); 265 307 } 266 308 267 309 /** 268 310 * @covers ::bbp_untrash_forum_topics 269 * @todo Implement test_bbp_untrash_forum_topics().270 311 */ 271 312 public function test_bbp_untrash_forum_topics() { 272 // Remove the following lines when you implement this test. 273 $this->markTestIncomplete( 274 'This test has not been implemented yet.' 275 ); 313 $forum_id = $this->factory->forum->create(); 314 $topic_id = $this->factory->topic->create( array( 315 'post_parent' => $forum_id, 316 'topic_meta' => array( 'forum_id' => $forum_id ), 317 ) ); 318 $already_trashed_id = $this->factory->topic->create( array( 319 'post_parent' => $forum_id, 320 'topic_meta' => array( 'forum_id' => $forum_id ), 321 ) ); 322 wp_trash_post( $already_trashed_id ); 323 bbp_trash_forum_topics( $forum_id ); 324 325 $this->assertSame( 'trash', get_post_status( $topic_id ) ); 326 bbp_untrash_forum_topics( $forum_id ); 327 $this->assertSame( bbp_get_public_status_id(), get_post_status( $topic_id ) ); 328 $this->assertSame( 'trash', get_post_status( $already_trashed_id ) ); 329 } 330 331 /** 332 * @covers ::bbp_trash_forum 333 * @covers ::bbp_untrash_forum 334 * @covers ::bbp_trash_forum_topics 335 * @covers ::bbp_untrash_forum_topics 336 * @covers ::bbp_remove_forum_from_all_subscriptions 337 */ 338 public function test_forum_trash_restores_only_its_topics_and_removes_subscriptions() { 339 $forum_id = $this->factory->forum->create(); 340 $topic_id = $this->factory->topic->create( array( 341 'post_parent' => $forum_id, 342 'topic_meta' => array( 'forum_id' => $forum_id ), 343 ) ); 344 $already_trashed_id = $this->factory->topic->create( array( 345 'post_parent' => $forum_id, 346 'topic_meta' => array( 'forum_id' => $forum_id ), 347 ) ); 348 $user_id = $this->factory->user->create(); 349 $this->assertTrue( bbp_add_user_subscription( $user_id, $forum_id ) ); 350 wp_trash_post( $already_trashed_id ); 351 352 wp_trash_post( $forum_id ); 353 $this->assertSame( 'trash', get_post_status( $forum_id ) ); 354 $this->assertSame( 'trash', get_post_status( $topic_id ) ); 355 $this->assertFalse( bbp_is_user_subscribed( $user_id, $forum_id ) ); 356 357 wp_untrash_post( $forum_id ); 358 $this->assertSame( bbp_get_public_status_id(), get_post_status( $forum_id ) ); 359 $this->assertSame( bbp_get_public_status_id(), get_post_status( $topic_id ) ); 360 $this->assertSame( 'trash', get_post_status( $already_trashed_id ) ); 276 361 } 277 362 278 363 /** 279 364 * @covers ::bbp_delete_forum 280 * @todo Implement test_bbp_delete_forum().281 365 */ 282 366 public function test_bbp_delete_forum() { 283 // Remove the following lines when you implement this test. 284 $this->markTestIncomplete( 285 'This test has not been implemented yet.' 286 ); 367 $this->assert_forum_action_dispatches( 'bbp_delete_forum', 'bbp_delete_forum' ); 287 368 } 288 369 289 370 /** 290 371 * @covers ::bbp_trash_forum 291 * @todo Implement test_bbp_trash_forum().292 372 */ 293 373 public function test_bbp_trash_forum() { 294 // Remove the following lines when you implement this test. 295 $this->markTestIncomplete( 296 'This test has not been implemented yet.' 297 ); 374 $this->assert_forum_action_dispatches( 'bbp_trash_forum', 'bbp_trash_forum' ); 298 375 } 299 376 300 377 /** 301 378 * @covers ::bbp_untrash_forum 302 * @todo Implement test_bbp_untrash_forum().303 379 */ 304 380 public function test_bbp_untrash_forum() { 305 // Remove the following lines when you implement this test. 306 $this->markTestIncomplete( 307 'This test has not been implemented yet.' 308 ); 381 $this->assert_forum_action_dispatches( 'bbp_untrash_forum', 'bbp_untrash_forum' ); 309 382 } 310 383 311 384 /** 312 385 * @covers ::bbp_deleted_forum 313 * @todo Implement test_bbp_deleted_forum().314 386 */ 315 387 public function test_bbp_deleted_forum() { 316 // Remove the following lines when you implement this test. 317 $this->markTestIncomplete( 318 'This test has not been implemented yet.' 319 ); 388 $forum_id = $this->factory->forum->create(); 389 $forum = get_post( $forum_id ); 390 $observed = array(); 391 $callback = function( $id, $post ) use ( &$observed ) { 392 $observed[] = array( $id, $post ); 393 }; 394 395 add_action( 'bbp_deleted_forum', $callback, 10, 2 ); 396 try { 397 $this->assertFalse( bbp_deleted_forum( 0 ) ); 398 bbp_deleted_forum( $forum_id, $forum ); 399 } finally { 400 remove_action( 'bbp_deleted_forum', $callback ); 401 } 402 403 $this->assertSame( array( array( $forum_id, $forum ) ), $observed ); 320 404 } 321 405 322 406 /** 323 407 * @covers ::bbp_trashed_forum 324 * @todo Implement test_bbp_trashed_forum().325 408 */ 326 409 public function test_bbp_trashed_forum() { 327 // Remove the following lines when you implement this test. 328 $this->markTestIncomplete( 329 'This test has not been implemented yet.' 330 ); 410 $this->assert_forum_action_dispatches( 'bbp_trashed_forum', 'bbp_trashed_forum' ); 331 411 } 332 412 333 413 /** 334 414 * @covers ::bbp_untrashed_forum 335 * @todo Implement test_bbp_untrashed_forum().336 415 */ 337 416 public function test_bbp_untrashed_forum() { 338 // Remove the following lines when you implement this test. 339 $this->markTestIncomplete( 340 'This test has not been implemented yet.' 341 ); 417 $this->assert_forum_action_dispatches( 'bbp_untrashed_forum', 'bbp_untrashed_forum' ); 342 418 } 343 419 }
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)