[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/tests/phpunit/testcases/topics/functions/ -> topic.php (source)

   1  <?php
   2  
   3  /**
   4   * Tests for the topic component functions.
   5   *
   6   * @group topics
   7   * @group functions
   8   * @group topic
   9   */
  10  class BBP_Tests_Topics_Functions_Topic extends BBP_UnitTestCase {
  11  
  12      /**
  13       * @group canonical
  14       * @covers ::bbp_insert_topic
  15       */
  16  	public function test_bbp_insert_topic() {
  17          $u = $this->factory->user->create_many( 2 );
  18          $f = $this->factory->forum->create();
  19  
  20          $now = time();
  21          $post_date = date( 'Y-m-d H:i:s', $now - 60 * 60 * 100 );
  22  
  23          $t = $this->factory->topic->create( array(
  24              'post_title'   => 'Topic 1',
  25              'post_content' => 'Content for Topic 1',
  26              'post_parent'  => $f,
  27              'post_date'    => $post_date,
  28              'post_author'  => $u[0],
  29              'topic_meta'   => array(
  30                  'forum_id' => $f,
  31              ),
  32          ) );
  33  
  34          $r = $this->factory->reply->create( array(
  35              'post_parent' => $t,
  36              'post_date'   => $post_date,
  37              'post_author'  => $u[1],
  38              'reply_meta'  => array(
  39                  'forum_id' => $f,
  40                  'topic_id' => $t,
  41              ),
  42          ) );
  43  
  44          // Get the topic.
  45          $topic = bbp_get_topic( $t );
  46  
  47          remove_all_filters( 'bbp_get_topic_content' );
  48  
  49          // Topic post.
  50          $this->assertSame( 'Topic 1', bbp_get_topic_title( $t ) );
  51          $this->assertSame( 'Content for Topic 1', bbp_get_topic_content( $t ) );
  52          $this->assertSame( 'publish', bbp_get_topic_status( $t ) );
  53          $this->assertSame( $f, wp_get_post_parent_id( $t ) );
  54          $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/?topic=' . $topic->post_name, $topic->guid );
  55  
  56          // Topic meta.
  57          $this->assertSame( $f, bbp_get_topic_forum_id( $t ) );
  58          $this->assertSame( 1,  bbp_get_topic_reply_count( $t, true ) );
  59          $this->assertSame( 0,  bbp_get_topic_reply_count_hidden( $t, true ) );
  60          $this->assertSame( 2,  bbp_get_topic_voice_count( $t, true ) );
  61          $this->assertSame( $r, bbp_get_topic_last_reply_id( $t ) );
  62          $this->assertSame( $r, bbp_get_topic_last_active_id( $t ) );
  63          $this->assertSame( '4 days, 4 hours ago', bbp_get_topic_last_active_time( $t ) );
  64      }
  65  
  66      /**
  67       * @covers ::bbp_new_topic_handler
  68       * @todo   Implement test_bbp_new_topic_handler().
  69       */
  70  	public function test_bbp_new_topic_handler() {
  71          // Remove the following lines when you implement this test.
  72          $this->markTestIncomplete(
  73              'This test has not been implemented yet.'
  74          );
  75      }
  76  
  77      /**
  78       * @covers ::bbp_edit_topic_handler
  79       * @todo   Implement test_bbp_edit_topic_handler().
  80       */
  81  	public function test_bbp_edit_topic_handler() {
  82          // Remove the following lines when you implement this test.
  83          $this->markTestIncomplete(
  84              'This test has not been implemented yet.'
  85          );
  86      }
  87  
  88      /**
  89       * @covers ::bbp_update_topic
  90       * @todo   Implement test_bbp_update_topic().
  91       */
  92  	public function test_bbp_update_topic() {
  93          // Remove the following lines when you implement this test.
  94          $this->markTestIncomplete(
  95              'This test has not been implemented yet.'
  96          );
  97      }
  98  
  99      /**
 100       * @covers ::bbp_update_topic_walker
 101       * @todo   Implement test_bbp_update_topic_walker().
 102       */
 103  	public function test_bbp_update_topic_walker() {
 104          // Remove the following lines when you implement this test.
 105          $this->markTestIncomplete(
 106              'This test has not been implemented yet.'
 107          );
 108      }
 109  
 110      /**
 111       * @covers ::bbp_move_topic_handler
 112       */
 113  	public function test_bbp_move_topic_handler() {
 114          $old_current_user = 0;
 115          $this->old_current_user = get_current_user_id();
 116          $this->set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
 117          $this->keymaster_id = get_current_user_id();
 118          bbp_set_user_role( $this->keymaster_id, bbp_get_keymaster_role() );
 119  
 120          $old_forum_id = $this->factory->forum->create();
 121          $topic_id = $this->factory->topic->create( array(
 122              'post_parent' => $old_forum_id,
 123              'topic_meta' => array(
 124                  'forum_id' => $old_forum_id,
 125              ),
 126          ) );
 127  
 128          $reply_id = $this->factory->reply->create( array(
 129              'post_parent' => $topic_id,
 130              'reply_meta' => array(
 131                  'forum_id' => $old_forum_id,
 132                  'topic_id' => $topic_id,
 133              ),
 134          ) );
 135  
 136          // Topic post parent
 137          $topic_parent = wp_get_post_parent_id( $topic_id );
 138          $this->assertSame( $old_forum_id, $topic_parent );
 139  
 140          // Forum meta
 141          $this->assertSame( 1, bbp_get_forum_topic_count( $old_forum_id, true, true ) );
 142          $this->assertSame( 1, bbp_get_forum_reply_count( $old_forum_id, true, true ) );
 143          $this->assertSame( $topic_id, bbp_get_forum_last_topic_id( $old_forum_id ) );
 144          $this->assertSame( $reply_id, bbp_get_forum_last_reply_id( $old_forum_id ) );
 145          $this->assertSame( $reply_id, bbp_get_forum_last_active_id( $old_forum_id ) );
 146  
 147          // Topic meta
 148          $this->assertSame( $old_forum_id, bbp_get_topic_forum_id( $topic_id ) );
 149          $this->assertSame( 1, bbp_get_topic_voice_count( $topic_id, true ) );
 150          $this->assertSame( 1, bbp_get_topic_reply_count( $topic_id, true ) );
 151          $this->assertSame( $reply_id, bbp_get_topic_last_reply_id( $topic_id ) );
 152          $this->assertSame( $reply_id, bbp_get_topic_last_active_id( $topic_id ) );
 153  
 154          // Reply Meta
 155          $this->assertSame( $old_forum_id, bbp_get_reply_forum_id( $reply_id ) );
 156          $this->assertSame( $topic_id, bbp_get_reply_topic_id( $reply_id ) );
 157  
 158          // Create a new forum
 159          $new_forum_id = $this->factory->forum->create();
 160  
 161          // Move the topic into the new forum
 162          bbp_move_topic_handler( $topic_id, $old_forum_id, $new_forum_id );
 163  
 164          // Topic post parent
 165          $topic_parent = wp_get_post_parent_id( $topic_id );
 166          $this->assertSame( $new_forum_id, $topic_parent );
 167  
 168          // Forum meta
 169          $this->assertSame( 1, bbp_get_forum_topic_count( $new_forum_id, true, true ) );
 170          $this->assertSame( 1, bbp_get_forum_reply_count( $new_forum_id, true, true ) );
 171          $this->assertSame( $topic_id, bbp_get_forum_last_topic_id( $new_forum_id ) );
 172          $this->assertSame( $reply_id, bbp_get_forum_last_reply_id( $new_forum_id ) );
 173          $this->assertSame( $reply_id, bbp_get_forum_last_active_id( $new_forum_id ) );
 174  
 175          // Topic meta
 176          $this->assertSame( $new_forum_id, bbp_get_topic_forum_id( $topic_id ) );
 177          $this->assertSame( 1, bbp_get_topic_voice_count( $topic_id, true ) );
 178          $this->assertSame( 1, bbp_get_topic_reply_count( $topic_id, true ) );
 179          $this->assertSame( $reply_id, bbp_get_topic_last_reply_id( $topic_id ) );
 180          $this->assertSame( $reply_id, bbp_get_topic_last_active_id( $topic_id ) );
 181  
 182          // Reply Meta
 183          $this->assertSame( $new_forum_id, bbp_get_reply_forum_id( $reply_id ) );
 184          $this->assertSame( $topic_id, bbp_get_reply_topic_id( $reply_id ) );
 185  
 186          // Old Topic/Reply Counts
 187          $this->assertSame( 0, bbp_get_forum_topic_count( $old_forum_id, true, true ) );
 188          $this->assertSame( 0, bbp_get_forum_reply_count( $old_forum_id, true, true ) );
 189  
 190  
 191          // Retore the user
 192          $this->set_current_user( $this->old_current_user );
 193      }
 194  
 195      /**
 196       * @covers ::bbp_merge_topic_handler
 197       * @todo   Implement test_bbp_merge_topic_handler().
 198       */
 199  	public function test_bbp_merge_topic_handler() {
 200          // Remove the following lines when you implement this test.
 201          $this->markTestIncomplete(
 202              'This test has not been implemented yet.'
 203          );
 204      }
 205  
 206      /**
 207       * @covers ::bbp_merge_topic_count
 208       * @todo   Implement test_bbp_merge_topic_count().
 209       */
 210  	public function test_bbp_merge_topic_count() {
 211          // Remove the following lines when you implement this test.
 212          $this->markTestIncomplete(
 213              'This test has not been implemented yet.'
 214          );
 215      }
 216  
 217      /**
 218       * @covers ::bbp_split_topic_handler
 219       * @todo   Implement test_bbp_split_topic_handler().
 220       */
 221  	public function test_bbp_split_topic_handler() {
 222          // Remove the following lines when you implement this test.
 223          $this->markTestIncomplete(
 224              'This test has not been implemented yet.'
 225          );
 226      }
 227  
 228      /**
 229       * @covers ::bbp_split_topic_count
 230       * @todo   Implement test_bbp_split_topic_count().
 231       */
 232  	public function test_bbp_split_topic_count() {
 233          // Remove the following lines when you implement this test.
 234          $this->markTestIncomplete(
 235              'This test has not been implemented yet.'
 236          );
 237      }
 238  
 239      /**
 240       * @covers ::bbp_get_topic_statuses
 241       * @todo   Implement test_bbp_get_topic_statuses().
 242       */
 243  	public function test_bbp_get_topic_statuses() {
 244          // Remove the following lines when you implement this test.
 245          $this->markTestIncomplete(
 246              'This test has not been implemented yet.'
 247          );
 248      }
 249  
 250      /**
 251       * @covers ::bbp_get_topic_types
 252       * @todo   Implement test_bbp_get_topic_types().
 253       */
 254  	public function test_bbp_get_topic_types() {
 255          // Remove the following lines when you implement this test.
 256          $this->markTestIncomplete(
 257              'This test has not been implemented yet.'
 258          );
 259      }
 260  
 261      /**
 262       * @covers ::bbp_get_stickies
 263       * @todo   Implement test_bbp_get_stickies().
 264       */
 265  	public function test_bbp_get_stickies() {
 266          // Remove the following lines when you implement this test.
 267          $this->markTestIncomplete(
 268              'This test has not been implemented yet.'
 269          );
 270      }
 271  
 272      /**
 273       * @covers ::bbp_get_super_stickies
 274       * @todo   Implement test_bbp_get_super_stickies().
 275       */
 276  	public function test_bbp_get_super_stickies() {
 277          // Remove the following lines when you implement this test.
 278          $this->markTestIncomplete(
 279              'This test has not been implemented yet.'
 280          );
 281      }
 282  
 283      /**
 284       * @covers ::bbp_toggle_topic_handler
 285       * @todo   Implement test_bbp_toggle_topic_handler().
 286       */
 287  	public function test_bbp_toggle_topic_handler() {
 288          // Remove the following lines when you implement this test.
 289          $this->markTestIncomplete(
 290              'This test has not been implemented yet.'
 291          );
 292      }
 293  
 294      /**
 295       * @covers ::bbp_remove_topic_from_all_favorites
 296       * @todo   Implement test_bbp_remove_topic_from_all_favorites().
 297       */
 298  	public function test_bbp_remove_topic_from_all_favorites() {
 299          // Remove the following lines when you implement this test.
 300          $this->markTestIncomplete(
 301              'This test has not been implemented yet.'
 302          );
 303      }
 304  
 305      /**
 306       * @covers ::bbp_remove_topic_from_all_subscriptions
 307       * @todo   Implement test_bbp_remove_topic_from_all_subscriptions().
 308       */
 309  	public function test_bbp_remove_topic_from_all_subscriptions() {
 310          // Remove the following lines when you implement this test.
 311          $this->markTestIncomplete(
 312              'This test has not been implemented yet.'
 313          );
 314      }
 315  
 316      /**
 317       * @covers ::bbp_update_topic_forum_id
 318       */
 319  	public function test_bbp_update_topic_forum_id() {
 320          $f = $this->factory->forum->create();
 321          $t = $this->factory->topic->create( array(
 322              'post_parent' => $f,
 323              'topic_meta' => array(
 324                  'forum_id' => $f,
 325              ),
 326          ) );
 327  
 328          $forum_id = bbp_get_topic_forum_id( $t );
 329          $this->assertSame( $f, $forum_id );
 330  
 331          $topic_parent = wp_get_post_parent_id( $t );
 332          $this->assertSame( $f, $topic_parent );
 333  
 334          $this->assertTrue( delete_post_meta_by_key( '_bbp_forum_id' ) );
 335  
 336          bbp_update_topic_forum_id( $t, $f );
 337  
 338          $forum_id = bbp_get_topic_forum_id( $t );
 339          $this->assertSame( $f, $forum_id );
 340      }
 341  
 342      /**
 343       * @covers ::bbp_update_topic_topic_id
 344       * @todo   Implement test_bbp_update_topic_topic_id().
 345       */
 346  	public function test_bbp_update_topic_topic_id() {
 347          // Remove the following lines when you implement this test.
 348          $this->markTestIncomplete(
 349              'This test has not been implemented yet.'
 350          );
 351      }
 352  
 353      /**
 354       * @covers ::bbp_update_topic_revision_log
 355       * @todo   Implement test_bbp_update_topic_revision_log().
 356       */
 357  	public function test_bbp_update_topic_revision_log() {
 358          // Remove the following lines when you implement this test.
 359          $this->markTestIncomplete(
 360              'This test has not been implemented yet.'
 361          );
 362      }
 363  
 364      /**
 365       * @covers ::bbp_delete_topic
 366       * @todo   Implement test_bbp_delete_topic().
 367       */
 368  	public function test_bbp_delete_topic() {
 369          // Remove the following lines when you implement this test.
 370          $this->markTestIncomplete(
 371              'This test has not been implemented yet.'
 372          );
 373      }
 374  
 375      /**
 376       * @covers ::bbp_delete_topic_replies
 377       */
 378  	public function test_bbp_delete_topic_replies() {
 379          $f = $this->factory->forum->create();
 380          $t = $this->factory->topic->create( array(
 381              'post_parent' => $f,
 382              'topic_meta' => array(
 383                  'forum_id' => $f,
 384              ),
 385          ) );
 386          $r = $this->factory->reply->create_many( 2, array(
 387              'post_parent' => $t,
 388              'reply_meta' => array(
 389                  'forum_id' => $f,
 390                  'topic_id' => $t,
 391              ),
 392          ) );
 393  
 394          $this->assertSame( 2, bbp_get_topic_reply_count( $t, true ) );
 395  
 396          bbp_delete_topic_replies( $t );
 397  
 398          $count = count( bbp_get_all_child_ids( $t, bbp_get_reply_post_type() ) );
 399          $this->assertSame( 0, ( $count ) );
 400      }
 401  
 402      /**
 403       * @covers ::bbp_trash_topic
 404       * @todo   Implement test_bbp_trash_topic().
 405       */
 406  	public function test_bbp_trash_topic() {
 407          // Remove the following lines when you implement this test.
 408          $this->markTestIncomplete(
 409              'This test has not been implemented yet.'
 410          );
 411      }
 412  
 413      /**
 414       * @covers ::bbp_trash_topic_replies
 415       * @todo   Implement test_bbp_trash_topic_replies().
 416       */
 417  	public function test_bbp_trash_topic_replies() {
 418          // Remove the following lines when you implement this test.
 419          $this->markTestIncomplete(
 420              'This test has not been implemented yet.'
 421          );
 422      }
 423  
 424      /**
 425       * @covers ::bbp_untrash_topic
 426       */
 427  	public function test_bbp_untrash_topic() {
 428          $f = $this->factory->forum->create();
 429          $t = $this->factory->topic->create( array(
 430              'post_parent' => $f,
 431              'topic_meta' => array(
 432                  'forum_id' => $f,
 433              ),
 434          ) );
 435  
 436          wp_trash_post( $t );
 437  
 438          wp_untrash_post( $t );
 439  
 440          $this->assertTrue( 'publish' === get_post_status( $t ) );
 441      }
 442  
 443      /**
 444       * @covers ::bbp_untrash_topic_replies
 445       */
 446  	public function test_bbp_untrash_topic_replies() {
 447          $f = $this->factory->forum->create();
 448          $t = $this->factory->topic->create( array(
 449              'post_parent' => $f,
 450              'topic_meta' => array(
 451                  'forum_id' => $f,
 452              ),
 453          ) );
 454          $r = $this->factory->reply->create_many( 2, array(
 455              'post_parent' => $t,
 456              'reply_meta' => array(
 457                  'forum_id' => $f,
 458                  'topic_id' => $t,
 459              ),
 460          ) );
 461  
 462          wp_trash_post( $t );
 463  
 464          wp_untrash_post( $t );
 465  
 466          $expected = [];
 467          $expected[] = get_post_status( $r[0] );
 468          $expected[] = get_post_status( $r[1] );
 469  
 470          $this->assertSame( [ 'publish', 'publish' ], $expected );
 471      }
 472  
 473      /**
 474       * @covers ::bbp_deleted_topic
 475       * @todo   Implement test_bbp_deleted_topic().
 476       */
 477  	public function test_bbp_deleted_topic() {
 478          // Remove the following lines when you implement this test.
 479          $this->markTestIncomplete(
 480              'This test has not been implemented yet.'
 481          );
 482      }
 483  
 484      /**
 485       * @covers ::bbp_trashed_topic
 486       * @todo   Implement test_bbp_trashed_topic().
 487       */
 488  	public function test_bbp_trashed_topic() {
 489          // Remove the following lines when you implement this test.
 490          $this->markTestIncomplete(
 491              'This test has not been implemented yet.'
 492          );
 493      }
 494  
 495      /**
 496       * @covers ::bbp_untrashed_topic
 497       * @todo   Implement test_bbp_untrashed_topic().
 498       */
 499  	public function test_bbp_untrashed_topic() {
 500          // Remove the following lines when you implement this test.
 501          $this->markTestIncomplete(
 502              'This test has not been implemented yet.'
 503          );
 504      }
 505  
 506      /**
 507       * @covers ::bbp_get_topics_per_page
 508       * @todo   Implement test_bbp_get_topics_per_page().
 509       */
 510  	public function test_bbp_get_topics_per_page() {
 511          // Remove the following lines when you implement this test.
 512          $this->markTestIncomplete(
 513              'This test has not been implemented yet.'
 514          );
 515      }
 516  
 517      /**
 518       * @covers ::bbp_get_topics_per_rss_page
 519       * @todo   Implement test_bbp_get_topics_per_rss_page().
 520       */
 521  	public function test_bbp_get_topics_per_rss_page() {
 522          // Remove the following lines when you implement this test.
 523          $this->markTestIncomplete(
 524              'This test has not been implemented yet.'
 525          );
 526      }
 527  
 528      /**
 529       * @covers ::bbp_topic_content_autoembed
 530       * @todo   Implement test_bbp_topic_content_autoembed().
 531       */
 532  	public function test_bbp_topic_content_autoembed() {
 533          // Remove the following lines when you implement this test.
 534          $this->markTestIncomplete(
 535              'This test has not been implemented yet.'
 536          );
 537      }
 538  
 539      /**
 540       * @covers ::bbp_display_topics_feed_rss2
 541       * @todo   Implement test_bbp_display_topics_feed_rss2().
 542       */
 543  	public function test_bbp_display_topics_feed_rss2() {
 544          // Remove the following lines when you implement this test.
 545          $this->markTestIncomplete(
 546              'This test has not been implemented yet.'
 547          );
 548      }
 549  
 550      /**
 551       * @covers ::bbp_check_topic_edit
 552       * @todo   Implement test_bbp_check_topic_edit().
 553       */
 554  	public function test_bbp_check_topic_edit() {
 555          // Remove the following lines when you implement this test.
 556          $this->markTestIncomplete(
 557              'This test has not been implemented yet.'
 558          );
 559      }
 560  }


Generated: Sun Apr 28 01:00:59 2024 Cross-referenced by PHPXref 0.7.1