[ 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       * @todo   Implement test_bbp_untrash_topic().
 427       */
 428  	public function test_bbp_untrash_topic() {
 429          // Remove the following lines when you implement this test.
 430          $this->markTestIncomplete(
 431              'This test has not been implemented yet.'
 432          );
 433      }
 434  
 435      /**
 436       * @covers ::bbp_untrash_topic_replies
 437       * @todo   Implement test_bbp_untrash_topic_replies().
 438       */
 439  	public function test_bbp_untrash_topic_replies() {
 440          // Remove the following lines when you implement this test.
 441          $this->markTestIncomplete(
 442              'This test has not been implemented yet.'
 443          );
 444      }
 445  
 446      /**
 447       * @covers ::bbp_deleted_topic
 448       * @todo   Implement test_bbp_deleted_topic().
 449       */
 450  	public function test_bbp_deleted_topic() {
 451          // Remove the following lines when you implement this test.
 452          $this->markTestIncomplete(
 453              'This test has not been implemented yet.'
 454          );
 455      }
 456  
 457      /**
 458       * @covers ::bbp_trashed_topic
 459       * @todo   Implement test_bbp_trashed_topic().
 460       */
 461  	public function test_bbp_trashed_topic() {
 462          // Remove the following lines when you implement this test.
 463          $this->markTestIncomplete(
 464              'This test has not been implemented yet.'
 465          );
 466      }
 467  
 468      /**
 469       * @covers ::bbp_untrashed_topic
 470       * @todo   Implement test_bbp_untrashed_topic().
 471       */
 472  	public function test_bbp_untrashed_topic() {
 473          // Remove the following lines when you implement this test.
 474          $this->markTestIncomplete(
 475              'This test has not been implemented yet.'
 476          );
 477      }
 478  
 479      /**
 480       * @covers ::bbp_get_topics_per_page
 481       * @todo   Implement test_bbp_get_topics_per_page().
 482       */
 483  	public function test_bbp_get_topics_per_page() {
 484          // Remove the following lines when you implement this test.
 485          $this->markTestIncomplete(
 486              'This test has not been implemented yet.'
 487          );
 488      }
 489  
 490      /**
 491       * @covers ::bbp_get_topics_per_rss_page
 492       * @todo   Implement test_bbp_get_topics_per_rss_page().
 493       */
 494  	public function test_bbp_get_topics_per_rss_page() {
 495          // Remove the following lines when you implement this test.
 496          $this->markTestIncomplete(
 497              'This test has not been implemented yet.'
 498          );
 499      }
 500  
 501      /**
 502       * @covers ::bbp_topic_content_autoembed
 503       * @todo   Implement test_bbp_topic_content_autoembed().
 504       */
 505  	public function test_bbp_topic_content_autoembed() {
 506          // Remove the following lines when you implement this test.
 507          $this->markTestIncomplete(
 508              'This test has not been implemented yet.'
 509          );
 510      }
 511  
 512      /**
 513       * @covers ::bbp_display_topics_feed_rss2
 514       * @todo   Implement test_bbp_display_topics_feed_rss2().
 515       */
 516  	public function test_bbp_display_topics_feed_rss2() {
 517          // Remove the following lines when you implement this test.
 518          $this->markTestIncomplete(
 519              'This test has not been implemented yet.'
 520          );
 521      }
 522  
 523      /**
 524       * @covers ::bbp_check_topic_edit
 525       * @todo   Implement test_bbp_check_topic_edit().
 526       */
 527  	public function test_bbp_check_topic_edit() {
 528          // Remove the following lines when you implement this test.
 529          $this->markTestIncomplete(
 530              'This test has not been implemented yet.'
 531          );
 532      }
 533  }


Generated: Wed Jul 17 01:01:28 2019 Cross-referenced by PHPXref 0.7.1