[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/tests/phpunit/testcases/replies/template/ -> reply.php (source)

   1  <?php
   2  
   3  /**
   4   * Tests for the `bbp_*_reply_*()` template functions.
   5   *
   6   * @group replies
   7   * @group template
   8   * @group reply
   9   */
  10  class BBP_Tests_Replies_Template_Reply extends BBP_UnitTestCase {
  11  
  12      /**
  13       * @covers ::bbp_reply_id
  14       * @covers ::bbp_get_reply_id
  15       */
  16  	public function test_bbp_get_reply_id() {
  17          $f = $this->factory->forum->create();
  18          $t = $this->factory->topic->create( array(
  19              'post_parent' => $f,
  20              'topic_meta' => array(
  21                  'forum_id' => $f,
  22              ),
  23          ) );
  24  
  25          $r = $this->factory->reply->create( array(
  26              'post_parent' => $t,
  27              'reply_meta' => array(
  28                  'forum_id' => $f,
  29                  'topic_id' => $t,
  30              ),
  31          ) );
  32  
  33          $reply_id = bbp_get_reply_id( $r );
  34          $this->assertSame( $r, $reply_id );
  35      }
  36  
  37      /**
  38       * @covers ::bbp_get_reply
  39       * @todo   Implement test_bbp_get_reply().
  40       */
  41  	public function test_bbp_get_reply() {
  42          // Remove the following lines when you implement this test.
  43          $this->markTestIncomplete(
  44              'This test has not been implemented yet.'
  45          );
  46      }
  47  
  48      /**
  49       * @covers ::bbp_reply_permalink
  50       * @covers ::bbp_get_reply_permalink
  51       */
  52  	public function test_bbp_get_reply_permalink() {
  53          if ( is_multisite() ) {
  54              $this->markTestSkipped( 'Skipping URL tests in multiste for now.' );
  55          }
  56          $f = $this->factory->forum->create();
  57          $t = $this->factory->topic->create( array(
  58              'post_parent' => $f,
  59              'topic_meta' => array(
  60                  'forum_id' => $f,
  61              ),
  62          ) );
  63  
  64          $r = $this->factory->reply->create( array(
  65              'post_parent' => $t,
  66              'reply_meta' => array(
  67                  'forum_id' => $f,
  68                  'topic_id' => $t,
  69              ),
  70          ) );
  71  
  72          $reply_permalink = bbp_get_reply_permalink( $r );
  73  
  74          $this->expectOutputString( $reply_permalink );
  75          bbp_reply_permalink( $r );
  76  
  77          $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/?reply=' . bbp_get_reply_id( $r ), $reply_permalink );
  78      }
  79  
  80      /**
  81       * @covers ::bbp_reply_url
  82       * @covers ::bbp_get_reply_url
  83       *
  84       * @ticket BBP2845
  85       */
  86  	public function test_bbp_get_reply_url() {
  87          if ( is_multisite() ) {
  88              $this->markTestSkipped( 'Skipping URL tests in multisite for now.' );
  89          }
  90  
  91          $f = $this->factory->forum->create();
  92  
  93          $t = $this->factory->topic->create( array(
  94              'post_parent' => $f,
  95              'topic_meta' => array(
  96                  'forum_id' => $f,
  97              ),
  98          ) );
  99  
 100          $r = $this->factory->reply->create_many( 7, array(
 101              'post_parent' => $t,
 102              'reply_meta' => array(
 103                  'forum_id' => $f,
 104                  'topic_id' => $t,
 105              ),
 106          ) );
 107  
 108          // Store the original reply pagination option value.
 109          $default_reply_page = bbp_get_replies_per_page();
 110  
 111          // Lower the reply pagination value to test without so many replies.
 112          update_option( '_bbp_replies_per_page', 3 );
 113  
 114          // Reply menu position is unaltered when bbp_show_lead_topic() true.
 115          add_filter( 'bbp_show_lead_topic', '__return_true' );
 116  
 117          // 1st reply is on the first page, 3 replies and 1 topic per page.
 118          $reply_url = bbp_get_topic_permalink( $t ) . '#post-' . bbp_get_reply_id( $r[0] );
 119          $this->assertSame( $reply_url, bbp_get_reply_url( $r[0] ) );
 120  
 121          // 2nd reply is on the first page, 3 replies and 1 topic per page.
 122          $reply_url = bbp_get_topic_permalink( $t ) . '#post-' . bbp_get_reply_id( $r[1] );
 123          $this->assertSame( $reply_url, bbp_get_reply_url( $r[1] ) );
 124  
 125          // 3rd reply is on the first page, 3 replies and 1 topic per page.
 126          $reply_url = bbp_get_topic_permalink( $t ) . '#post-' . bbp_get_reply_id( $r[2] );
 127          $this->assertSame( $reply_url, bbp_get_reply_url( $r[2] ) );
 128  
 129          // 4th reply is on the second page, 3 replies and 1 topic per page.
 130          $reply_url = bbp_get_topic_permalink( $t ) . '&paged=2#post-' . bbp_get_reply_id( $r[3] );
 131          $this->assertSame( $reply_url, bbp_get_reply_url( $r[3] ) );
 132  
 133          // 5th reply is on the second page, 3 replies and 1 topic per page.
 134          $reply_url = bbp_get_topic_permalink( $t ) . '&paged=2#post-' . bbp_get_reply_id( $r[4] );
 135          $this->assertSame( $reply_url, bbp_get_reply_url( $r[4] ) );
 136  
 137          // 6th reply is on the second page, 3 replies and 1 topic per page.
 138          $reply_url = bbp_get_topic_permalink( $t ) . '&paged=2#post-' . bbp_get_reply_id( $r[5] );
 139          $this->assertSame( $reply_url, bbp_get_reply_url( $r[5] ) );
 140  
 141          // 7th reply is on the third page, 3 replies and 1 topic per page.
 142          $reply_url = bbp_get_topic_permalink( $t ) . '&paged=3#post-' . bbp_get_reply_id( $r[6] );
 143          $this->assertSame( $reply_url, bbp_get_reply_url( $r[6] ) );
 144  
 145          // Remove the filter for WordPress < 4.0 compatibility.
 146          remove_filter( 'bbp_show_lead_topic', '__return_true' );
 147  
 148          // Reply menu position is bumped by 1 when bbp_show_lead_topic() false.
 149          add_filter( 'bbp_show_lead_topic', '__return_false' );
 150  
 151          // 1st reply is on the first page, 2 replies and 1 topic per first page.
 152          $reply_url = bbp_get_topic_permalink( $t ) . '#post-' . bbp_get_reply_id( $r[0] );
 153          $this->assertSame( $reply_url, bbp_get_reply_url( $r[0] ) );
 154  
 155          // 2nd reply is on the first page, 2 replies and 1 topic per first page.
 156          $reply_url = bbp_get_topic_permalink( $t ) . '#post-' . bbp_get_reply_id( $r[1] );
 157          $this->assertSame( $reply_url, bbp_get_reply_url( $r[1] ) );
 158  
 159          // 3rd reply is on the second page, 2 replies and 1 topic per first page.
 160          $reply_url = bbp_get_topic_permalink( $t ) . '&paged=2#post-' . bbp_get_reply_id( $r[2] );
 161          $this->assertSame( $reply_url, bbp_get_reply_url( $r[2] ) );
 162  
 163          // 4th reply is on the second page, 3 replies per subsequent page.
 164          $reply_url = bbp_get_topic_permalink( $t ) . '&paged=2#post-' . bbp_get_reply_id( $r[3] );
 165          $this->assertSame( $reply_url, bbp_get_reply_url( $r[3] ) );
 166  
 167          // 5th reply is on the second page, 3 replies per subsequent page.
 168          $reply_url = bbp_get_topic_permalink( $t ) . '&paged=2#post-' . bbp_get_reply_id( $r[4] );
 169          $this->assertSame( $reply_url, bbp_get_reply_url( $r[4] ) );
 170  
 171          // 6th reply is on the third page, 3 replies per subsequent page.
 172          $reply_url = bbp_get_topic_permalink( $t ) . '&paged=3#post-' . bbp_get_reply_id( $r[5] );
 173          $this->assertSame( $reply_url, bbp_get_reply_url( $r[5] ) );
 174  
 175          // 7th reply is on the third page, 3 replies per subsequent page.
 176          $reply_url = bbp_get_topic_permalink( $t ) . '&paged=3#post-' . bbp_get_reply_id( $r[6] );
 177          $this->assertSame( $reply_url, bbp_get_reply_url( $r[6] ) );
 178  
 179          // Remove the filter for WordPress < 4.0 compatibility.
 180          remove_filter( 'bbp_show_lead_topic', '__return_false' );
 181  
 182          // Restore the original reply pagination option value.
 183          update_option( '_bbp_replies_per_page', $default_reply_page );
 184      }
 185  
 186      /**
 187       * @covers ::bbp_reply_title
 188       * @covers ::bbp_get_reply_title
 189       */
 190  	public function test_bbp_get_reply_title() {
 191          $f = $this->factory->forum->create();
 192          $t = $this->factory->topic->create( array(
 193              'post_parent' => $f,
 194              'topic_meta' => array(
 195                  'forum_id' => $f,
 196              ),
 197          ) );
 198  
 199          $r = $this->factory->reply->create( array(
 200              'post_parent' => $t,
 201              'reply_meta' => array(
 202                  'forum_id' => $f,
 203                  'topic_id' => $t,
 204              ),
 205          ) );
 206  
 207          $reply_title = bbp_get_reply_title( $r );
 208          $this->assertSame( 'Reply To: ' . bbp_get_topic_title( $t ), $reply_title );
 209      }
 210  
 211      /**
 212       * @covers ::bbp_get_reply_title_fallback
 213       */
 214  	public function test_bbp_get_reply_title_fallback() {
 215          $f = $this->factory->forum->create();
 216          $t = $this->factory->topic->create( array(
 217              'post_parent' => $f,
 218              'topic_meta' => array(
 219                  'forum_id' => $f,
 220              ),
 221          ) );
 222  
 223          $r = $this->factory->reply->create( array(
 224              'post_parent' => $t,
 225              'post_title'  => 'What are you supposed to be, some kind of a cosmonaut?',
 226              'reply_meta' => array(
 227                  'forum_id' => $f,
 228                  'topic_id' => $t,
 229              ),
 230          ) );
 231  
 232          $reply_title = 'What are you supposed to be, some kind of a cosmonaut?';
 233          $reply_title_fallback = bbp_get_reply_title_fallback( $reply_title, $r );
 234          $this->assertSame( $reply_title , $reply_title_fallback );
 235  
 236          $r = $this->factory->reply->create( array(
 237              'post_parent' => $t,
 238              'reply_meta' => array(
 239                  'forum_id' => $f,
 240                  'topic_id' => $t,
 241              ),
 242          ) );
 243  
 244          $reply_title = '';
 245          $reply_title_fallback = bbp_get_reply_title_fallback( $reply_title, $r );
 246          $this->assertSame( 'Reply To: ' . bbp_get_topic_title( $t ), $reply_title_fallback );
 247      }
 248  
 249      /**
 250       * @covers ::bbp_reply_content
 251       * @covers ::bbp_get_reply_content
 252       */
 253  	public function test_bbp_get_reply_content() {
 254          $f = $this->factory->forum->create();
 255          $t = $this->factory->topic->create( array(
 256              'post_parent' => $f,
 257              'topic_meta' => array(
 258                  'forum_id' => $f,
 259              ),
 260          ) );
 261  
 262          $r = $this->factory->reply->create( array(
 263              'post_content' => 'Content of Reply 1',
 264              'post_parent' => $t,
 265              'reply_meta' => array(
 266                  'forum_id' => $f,
 267                  'topic_id' => $t,
 268              ),
 269          ) );
 270  
 271          remove_all_filters( 'bbp_get_reply_content' );
 272          $reply_content = bbp_get_reply_content( $r );
 273          $this->assertSame( 'Content of Reply 1', $reply_content );
 274      }
 275  
 276      /**
 277       * @covers ::bbp_reply_excerpt
 278       * @covers ::bbp_get_reply_excerpt
 279       */
 280  	public function test_bbp_get_reply_excerpt() {
 281          $f = $this->factory->forum->create();
 282          $t = $this->factory->topic->create( array(
 283              'post_parent' => $f,
 284              'topic_meta' => array(
 285                  'forum_id' => $f,
 286              ),
 287          ) );
 288  
 289          $r = $this->factory->reply->create( array(
 290              'post_parent'   => $t,
 291              'post_content'  => 'I feel like the floor of a taxi cab.',
 292              'reply_meta' => array(
 293                  'forum_id' => $f,
 294                  'topic_id' => $t,
 295              ),
 296          ) );
 297  
 298          remove_all_filters( 'bbp_get_reply_content' );
 299          $reply_excerpt = bbp_get_reply_excerpt( $r, 22 );
 300          $this->assertSame( 'I feel like the floor&hellip;', $reply_excerpt );
 301      }
 302  
 303      /**
 304       * @covers ::bbp_reply_post_date
 305       * @covers ::bbp_get_reply_post_date
 306       */
 307  	public function test_bbp_get_reply_post_date() {
 308          $f = $this->factory->forum->create();
 309  
 310          $t = $this->factory->topic->create( array(
 311              'post_parent' => $f,
 312              'topic_meta' => array(
 313                  'forum_id' => $f,
 314              ),
 315          ) );
 316  
 317          $now = time();
 318          $post_date = date( 'Y-m-d H:i:s', $now - 60 * 66 );
 319  
 320          $r = $this->factory->reply->create( array(
 321              'post_parent' => $t,
 322              'post_date' => $post_date,
 323              'reply_meta' => array(
 324                  'forum_id' => $f,
 325                  'topic_id' => $t,
 326              ),
 327          ) );
 328  
 329          // Configue our written date time, August 4, 2012 at 2:37 pm.
 330          $gmt = false;
 331          $date   = get_post_time( get_option( 'date_format' ), $gmt, $r, true );
 332          $time   = get_post_time( get_option( 'time_format' ), $gmt, $r, true );
 333          $result = sprintf( '%1$s at %2$s', $date, $time );
 334  
 335          // Output, string, August 4, 2012 at 2:37 pm.
 336          $this->expectOutputString( $result );
 337          bbp_reply_post_date( $r );
 338  
 339          // String, August 4, 2012 at 2:37 pm.
 340          $datetime = bbp_get_topic_post_date( $r, false, false );
 341          $this->assertSame( $result, $datetime );
 342  
 343          // Humanized string, 4 days, 4 hours ago.
 344          $datetime = bbp_get_topic_post_date( $r, true, false );
 345          $this->assertSame( '1 hour, 6 minutes ago', $datetime );
 346  
 347          // Humanized string using GMT formatted date, 4 days, 4 hours ago.
 348          $datetime = bbp_get_topic_post_date( $r, true, true );
 349          $this->assertSame( '1 hour, 6 minutes ago', $datetime );
 350      }
 351  
 352      /**
 353       * @covers ::bbp_reply_topic_title
 354       * @covers ::bbp_get_reply_topic_title
 355       */
 356  	public function test_bbp_get_reply_topic_title() {
 357          $f = $this->factory->forum->create();
 358          $t = $this->factory->topic->create( array(
 359              'post_parent' => $f,
 360              'topic_meta' => array(
 361                  'forum_id' => $f,
 362              ),
 363          ) );
 364  
 365          $r = $this->factory->reply->create( array(
 366              'post_parent' => $t,
 367              'reply_meta' => array(
 368                  'forum_id' => $f,
 369                  'topic_id' => $t,
 370              ),
 371          ) );
 372  
 373          $reply_topic_title = bbp_get_reply_topic_title( $r );
 374          $this->assertSame( bbp_get_topic_title( $t ), $reply_topic_title );
 375      }
 376  
 377      /**
 378       * @covers ::bbp_reply_topic_id
 379       * @covers ::bbp_get_reply_topic_id
 380       */
 381  	public function test_bbp_get_reply_topic_id() {
 382          $f = $this->factory->forum->create();
 383          $t = $this->factory->topic->create( array(
 384              'post_parent' => $f,
 385              'topic_meta' => array(
 386                  'forum_id' => $f,
 387              ),
 388          ) );
 389  
 390          $r = $this->factory->reply->create( array(
 391              'post_parent' => $t,
 392              'reply_meta' => array(
 393                  'forum_id' => $f,
 394                  'topic_id' => $t,
 395              ),
 396          ) );
 397  
 398          $reply_topic_id = bbp_get_reply_topic_id( $r );
 399          $this->assertSame( $t, $reply_topic_id );
 400      }
 401  
 402      /**
 403       * @covers ::bbp_reply_forum_id
 404       * @covers ::bbp_get_reply_forum_id
 405       */
 406  	public function test_bbp_get_reply_forum_id() {
 407          $f = $this->factory->forum->create();
 408          $t = $this->factory->topic->create( array(
 409              'post_parent' => $f,
 410              'topic_meta' => array(
 411                  'forum_id' => $f,
 412              ),
 413          ) );
 414  
 415          $r = $this->factory->reply->create( array(
 416              'post_parent' => $t,
 417              'reply_meta' => array(
 418                  'forum_id' => $f,
 419                  'topic_id' => $t,
 420              ),
 421          ) );
 422  
 423          $reply_forum_id = bbp_get_reply_forum_id( $r );
 424          $this->assertSame( $f, $reply_forum_id );
 425      }
 426  
 427      /**
 428       * @covers ::bbp_reply_ancestor_id
 429       * @covers ::bbp_get_reply_ancestor_id
 430       */
 431  	public function test_bbp_get_reply_ancestor_id() {
 432          $f = $this->factory->forum->create();
 433          $t = $this->factory->topic->create( array(
 434              'post_parent' => $f,
 435              'topic_meta' => array(
 436                  'forum_id' => $f,
 437              ),
 438          ) );
 439  
 440          $r1 = $this->factory->reply->create( array(
 441              'post_parent' => $t,
 442              'reply_meta' => array(
 443                  'forum_id' => $f,
 444                  'topic_id' => $t,
 445              ),
 446          ) );
 447  
 448          $r2 = $this->factory->reply->create( array(
 449              'post_parent' => $t,
 450              'reply_meta' => array(
 451                  'forum_id' => $f,
 452                  'topic_id' => $t,
 453                  'reply_to' => $r1,
 454              ),
 455          ) );
 456  
 457          $reply_ancestor_id = bbp_get_reply_ancestor_id( $r2 );
 458          $this->assertSame( $r1, $reply_ancestor_id );
 459      }
 460  
 461      /**
 462       * @covers ::bbp_reply_to
 463       * @covers ::bbp_get_reply_to
 464       */
 465  	public function test_bbp_get_reply_to() {
 466          $f = $this->factory->forum->create();
 467          $t = $this->factory->topic->create( array(
 468              'post_parent' => $f,
 469              'topic_meta' => array(
 470                  'forum_id' => $f,
 471              ),
 472          ) );
 473  
 474          $r1 = $this->factory->reply->create( array(
 475              'post_parent' => $t,
 476              'reply_meta' => array(
 477                  'forum_id' => $f,
 478                  'topic_id' => $t,
 479              ),
 480          ) );
 481  
 482          $r2 = $this->factory->reply->create( array(
 483              'post_parent' => $t,
 484              'reply_meta' => array(
 485                  'forum_id' => $f,
 486                  'topic_id' => $t,
 487                  'reply_to' => $r1,
 488              ),
 489          ) );
 490  
 491          $reply_to = bbp_get_reply_to( $r2 );
 492          $this->assertSame( $r1, $reply_to );
 493      }
 494  
 495      /**
 496       * @covers ::bbp_reply_position
 497       * @covers ::bbp_get_reply_position
 498       *
 499       * @ticket BBP2845
 500       */
 501  	public function test_bbp_get_reply_position() {
 502          $f = $this->factory->forum->create();
 503  
 504          $t = $this->factory->topic->create( array(
 505              'post_parent' => $f,
 506              'topic_meta' => array(
 507                  'forum_id' => $f,
 508              ),
 509          ) );
 510  
 511          $r = $this->factory->reply->create_many( 7, array(
 512              'post_parent' => $t,
 513              'reply_meta' => array(
 514                  'forum_id' => $f,
 515                  'topic_id' => $t,
 516              ),
 517          ) );
 518  
 519          // Reply menu position is unaltered when bbp_show_lead_topic() true.
 520          add_filter( 'bbp_show_lead_topic', '__return_true' );
 521  
 522          $position = get_post_field( 'menu_order', $r[3] );
 523          $this->assertSame( 4, $position );
 524  
 525          $position = bbp_get_reply_position_raw( $r[3] );
 526          $this->assertSame( 4, $position );
 527  
 528          $position = bbp_get_reply_position( $r[3] );
 529          $this->assertSame( 4, $position );
 530  
 531          // Force a reply's 'menu_order' to 0.
 532          bbp_update_reply_position( $r[3], 0 );
 533  
 534          $position = get_post_field( 'menu_order', $r[3] );
 535          $this->assertSame( 0, $position );
 536  
 537          $position = bbp_get_reply_position_raw( $r[3] );
 538          $this->assertSame( 4, $position );
 539  
 540          $position = bbp_get_reply_position( $r[3] );
 541          $this->assertSame( 4, $position );
 542  
 543          // Remove the filter for WordPress < 4.0 compatibility.
 544          remove_filter( 'bbp_show_lead_topic', '__return_true' );
 545  
 546          // Reply menu position is bumped by 1 when bbp_show_lead_topic() false.
 547          add_filter( 'bbp_show_lead_topic', '__return_false' );
 548  
 549          $position = get_post_field( 'menu_order', $r[3] );
 550          $this->assertSame( 4, $position );
 551  
 552          $position = bbp_get_reply_position_raw( $r[3] );
 553          $this->assertSame( 4, $position );
 554  
 555          $position = bbp_get_reply_position( $r[3] );
 556          $this->assertSame( 5, $position );
 557  
 558          // Force a reply's 'menu_order' to 0.
 559          bbp_update_reply_position( $r[3], 0 );
 560  
 561          $position = get_post_field( 'menu_order', $r[3] );
 562          $this->assertSame( 0, $position );
 563  
 564          $position = bbp_get_reply_position_raw( $r[3] );
 565          $this->assertSame( 4, $position );
 566  
 567          $position = bbp_get_reply_position( $r[3] );
 568          $this->assertSame( 5, $position );
 569  
 570          // Remove the filter for WordPress < 4.0 compatibility.
 571          remove_filter( 'bbp_show_lead_topic', '__return_false' );
 572      }
 573  
 574      /**
 575       * @covers ::bbp_reply_class
 576       * @covers ::bbp_get_reply_class
 577       * @todo   Implement test_bbp_get_reply_class().
 578       */
 579  	public function test_bbp_get_reply_class() {
 580          // Remove the following lines when you implement this test.
 581          $this->markTestIncomplete(
 582              'This test has not been implemented yet.'
 583          );
 584      }
 585  
 586      /**
 587       * @covers ::bbp_topic_pagination_count
 588       * @covers ::bbp_get_topic_pagination_count
 589       * @todo   Implement test_bbp_get_topic_pagination_count().
 590       */
 591  	public function test_bbp_get_topic_pagination_count() {
 592          // Remove the following lines when you implement this test.
 593          $this->markTestIncomplete(
 594              'This test has not been implemented yet.'
 595          );
 596      }
 597  }


Generated: Wed Jul 24 01:01:31 2019 Cross-referenced by PHPXref 0.7.1