[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/tests/phpunit/testcases/topics/template/ -> get-last-thing.php (source)

   1  <?php
   2  
   3  /**
   4   * Tests for the `bbp_get_topic__last_*()` template functions.
   5   *
   6   * @group topics
   7   * @group template
   8   * @group get_last_thing
   9   */
  10  class BBP_Tests_Topics_Template_Get_Topic_Last_Thing extends BBP_UnitTestCase {
  11  
  12      /**
  13       * @covers ::bbp_topic_last_active_id
  14       * @covers ::bbp_get_topic_last_active_id
  15       */
  16  	public function test_bbp_get_topic_last_active_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          $topic_last_active_id = bbp_get_topic_last_active_id( $t );
  26          $this->assertSame( $t, $topic_last_active_id );
  27  
  28          $r = $this->factory->reply->create( array(
  29              'post_parent' => $t,
  30              'reply_meta' => array(
  31                  'forum_id' => $f,
  32                  'topic_id' => $t,
  33              )
  34          ) );
  35  
  36          $topic_last_active_id = bbp_get_topic_last_active_id( $t );
  37          $this->assertSame( $r, $topic_last_active_id );
  38      }
  39  
  40      /**
  41       * @covers ::bbp_topic_last_active_time
  42       * @covers ::bbp_get_topic_last_active_time
  43       */
  44  	public function test_bbp_get_topic_last_active_time() {
  45          $f = $this->factory->forum->create();
  46  
  47          $now = time();
  48          $post_date_topic = date( 'Y-m-d H:i:s', $now - 60 * 60 * 100 );
  49          $post_date_reply = date( 'Y-m-d H:i:s', $now - 60 * 60 * 80 );
  50  
  51          $topic_time = '4 days, 4 hours ago';
  52          $reply_time = '3 days, 8 hours ago';
  53  
  54          $t = $this->factory->topic->create( array(
  55              'post_parent' => $f,
  56              'post_date' => $post_date_topic,
  57              'topic_meta' => array(
  58                  'forum_id' => $f,
  59              ),
  60          ) );
  61  
  62          // Output.
  63          $this->expectOutputString( $topic_time );
  64          bbp_topic_last_active_time( $t );
  65  
  66          // Topic time.
  67          $datetime = bbp_get_topic_last_active_time( $t );
  68          $this->assertSame( $topic_time, $datetime );
  69  
  70          $this->factory->reply->create( array(
  71              'post_parent' => $t,
  72              'post_date' => $post_date_reply,
  73              'reply_meta' => array(
  74                  'forum_id' => $f,
  75                  'topic_id' => $t,
  76              ),
  77          ) );
  78  
  79          // Reply time.
  80          $datetime = bbp_get_topic_last_active_time( $t );
  81          $this->assertSame( '3 days, 8 hours ago', $datetime );
  82  
  83      }
  84  
  85      /**
  86       * @covers ::bbp_topic_last_reply_id
  87       * @covers ::bbp_get_topic_last_reply_id
  88       */
  89  	public function test_bbp_get_topic_last_reply_id() {
  90          $f = $this->factory->forum->create();
  91          $t = $this->factory->topic->create( array(
  92              'post_parent' => $f,
  93              'topic_meta' => array(
  94                  'forum_id' => $f,
  95              )
  96          ) );
  97  
  98          $topic_last_reply_id = bbp_get_topic_last_reply_id( $t );
  99          $this->assertSame( 0, $topic_last_reply_id );
 100  
 101          $r = $this->factory->reply->create( array(
 102              'post_parent' => $t,
 103              'reply_meta' => array(
 104                  'forum_id' => $f,
 105                  'topic_id' => $t,
 106              )
 107          ) );
 108  
 109          $topic_last_reply_id = bbp_get_topic_last_reply_id( $t );
 110          $this->assertSame( $r, $topic_last_reply_id );
 111      }
 112  
 113      /**
 114       * @covers ::bbp_topic_last_reply_title
 115       * @covers ::bbp_get_topic_last_reply_title
 116       */
 117  	public function test_bbp_get_topic_last_reply_title() {
 118          $f = $this->factory->forum->create();
 119          $t = $this->factory->topic->create( array(
 120              'post_parent' => $f,
 121              'topic_meta' => array(
 122                  'forum_id' => $f,
 123              )
 124          ) );
 125  
 126          $title = bbp_get_topic_last_reply_title( $t );
 127          $this->assertSame( '', $title );
 128  
 129          $this->factory->reply->create( array(
 130              'post_parent' => $t,
 131              'reply_meta' => array(
 132                  'forum_id' => $f,
 133                  'topic_id' => $t,
 134              )
 135          ) );
 136  
 137          $title = bbp_get_topic_last_reply_title( $t );
 138          $this->assertSame( 'Reply To: ' . bbp_get_topic_title( $t ), $title );
 139      }
 140  
 141      /**
 142       * @covers ::bbp_topic_last_reply_permalink
 143       * @covers ::bbp_get_topic_last_reply_permalink
 144       */
 145  	public function test_bbp_get_topic_last_reply_permalink() {
 146          if ( is_multisite() ) {
 147              $this->markTestSkipped( 'Skipping URL tests in multiste for now.' );
 148          }
 149  
 150          $f = $this->factory->forum->create();
 151  
 152          $t = $this->factory->topic->create( array(
 153              'post_parent' => $f,
 154              'topic_meta' => array(
 155                  'forum_id' => $f,
 156              )
 157          ) );
 158  
 159          $topic_last_reply_permalink = bbp_get_forum_last_topic_permalink( $f );
 160          $this->assertSame( bbp_get_topic_permalink( $t ), $topic_last_reply_permalink );
 161  
 162          $r = $this->factory->reply->create( array(
 163              'post_parent' => $t,
 164              'reply_meta' => array(
 165                  'forum_id' => $f,
 166                  'topic_id' => $t,
 167              )
 168          ) );
 169  
 170          $topic_last_reply_permalink = bbp_get_topic_last_reply_permalink( $t );
 171          $this->assertSame( bbp_get_reply_permalink( $r ), $topic_last_reply_permalink );
 172      }
 173  
 174      /**
 175       * @covers ::bbp_topic_last_reply_url
 176       * @covers ::bbp_get_topic_last_reply_url
 177       */
 178  	public function test_bbp_get_topic_last_reply_url() {
 179          if ( is_multisite() ) {
 180              $this->markTestSkipped( 'Skipping URL tests in multiste for now.' );
 181          }
 182  
 183          $f = $this->factory->forum->create();
 184  
 185          $t = $this->factory->topic->create( array(
 186              'post_parent' => $f,
 187              'topic_meta' => array(
 188                  'forum_id' => $f,
 189              )
 190          ) );
 191  
 192          $topic_last_reply_url = bbp_get_topic_last_reply_url( $t );
 193          $this->assertSame( get_permalink( $t ), $topic_last_reply_url );
 194  
 195          $r = $this->factory->reply->create( array(
 196              'post_parent' => $t,
 197              'reply_meta' => array(
 198                  'forum_id' => $f,
 199                  'topic_id' => $t,
 200              )
 201          ) );
 202  
 203          $topic_last_reply_url = bbp_get_topic_last_reply_url( $t );
 204          $this->assertSame( bbp_get_reply_url( $r ), $topic_last_reply_url );
 205      }
 206  }


Generated: Mon Sep 16 01:01:26 2019 Cross-referenced by PHPXref 0.7.1