[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/tests/phpunit/testcases/forums/functions/ -> update-last-thing.php (source)

   1  <?php
   2  /**
   3   * Tests for the `bbp_update_forum_last_*()` functions.
   4   *
   5   * @group forums
   6   * @group functions
   7   * @group update_last_thing
   8   */
   9  
  10  class BBP_Tests_Forums_Functions_Update_Forum_Last_Thing extends BBP_UnitTestCase {
  11  
  12      /**
  13       * @covers ::bbp_update_forum_last_topic_id
  14       */
  15  	public function test_bbp_update_forum_last_topic_id() {
  16          $f1 = $this->factory->forum->create();
  17          $f2 = $this->factory->forum->create( array(
  18              'post_parent' => $f1,
  19          ) );
  20  
  21          $t1 = $this->factory->topic->create( array(
  22              'post_parent' => $f1,
  23              'topic_meta' => array(
  24                  'forum_id' => $f1,
  25              ),
  26          ) );
  27  
  28          $id = bbp_update_forum_last_topic_id( $f1, $t1 );
  29          $this->assertSame( $t1, $id );
  30  
  31          $id = bbp_get_forum_last_topic_id( $f1 );
  32          $this->assertSame( $t1, $id );
  33  
  34          $t2 = $this->factory->topic->create( array(
  35              'post_parent' => $f2,
  36              'topic_meta' => array(
  37                  'forum_id' => $f2,
  38              ),
  39          ) );
  40  
  41          bbp_update_forum_last_topic_id( $f2 );
  42          $id = bbp_get_forum_last_topic_id( $f2 );
  43          $this->assertSame( $t2, $id );
  44  
  45          bbp_update_forum_last_topic_id( $f1 );
  46          $id = bbp_get_forum_last_topic_id( $f1 );
  47          $this->assertSame( $t2, $id );
  48      }
  49  
  50      /**
  51       * @covers ::bbp_update_forum_last_reply_id
  52       */
  53  	public function test_bbp_update_forum_last_reply_id() {
  54          $f1 = $this->factory->forum->create();
  55          $f2 = $this->factory->forum->create( array(
  56              'post_parent' => $f1,
  57          ) );
  58  
  59          $t1 = $this->factory->topic->create( array(
  60              'post_parent' => $f1,
  61              'topic_meta' => array(
  62                  'forum_id' => $f1,
  63              ),
  64          ) );
  65          $t2 = $this->factory->topic->create( array(
  66              'post_parent' => $f2,
  67              'topic_meta' => array(
  68                  'forum_id' => $f2,
  69              ),
  70          ) );
  71  
  72          $r1 = $this->factory->reply->create( array(
  73              'post_parent' => $t1,
  74              'reply_meta' => array(
  75                  'forum_id' => $f1,
  76                  'topic_id' => $t1,
  77              ),
  78          ) );
  79  
  80          $id = bbp_update_forum_last_reply_id( $f1, $r1 );
  81          $this->assertSame( $r1, $id );
  82  
  83          $id = bbp_get_forum_last_reply_id( $f1 );
  84          $this->assertSame( $r1, $id );
  85  
  86          $r2 = $this->factory->reply->create( array(
  87              'post_parent' => $t2,
  88              'reply_meta' => array(
  89                  'forum_id' => $f2,
  90                  'topic_id' => $t2,
  91              ),
  92          ) );
  93  
  94          bbp_update_forum_last_reply_id( $f2 );
  95          $id = bbp_get_forum_last_reply_id( $f2 );
  96          $this->assertSame( $r2, $id );
  97  
  98          bbp_update_forum_last_reply_id( $f1 );
  99          $id = bbp_get_forum_last_reply_id( $f1 );
 100          $this->assertSame( $r2, $id );
 101      }
 102  
 103      /**
 104       * @covers ::bbp_update_forum_last_active_id
 105       */
 106  	public function test_bbp_update_forum_last_active_id() {
 107          $f1 = $this->factory->forum->create();
 108          $f2 = $this->factory->forum->create( array(
 109              'post_parent' => $f1,
 110          ) );
 111  
 112          $t1 = $this->factory->topic->create( array(
 113              'post_parent' => $f1,
 114              'topic_meta' => array(
 115                  'forum_id' => $f1,
 116              ),
 117          ) );
 118          $r1 = $this->factory->reply->create( array(
 119              'post_parent' => $t1,
 120              'reply_meta' => array(
 121                  'forum_id' => $f1,
 122                  'topic_id' => $t1,
 123              ),
 124          ) );
 125  
 126          $id = bbp_update_forum_last_active_id( $f1, $r1 );
 127          $this->assertSame( $r1, $id );
 128  
 129          $id = bbp_get_forum_last_active_id( $f1 );
 130          $this->assertSame( $r1, $id );
 131  
 132          $t2 = $this->factory->topic->create( array(
 133              'post_parent' => $f2,
 134              'topic_meta' => array(
 135                  'forum_id' => $f2,
 136              ),
 137          ) );
 138          $r2 = $this->factory->reply->create( array(
 139              'post_parent' => $t2,
 140              'reply_meta' => array(
 141                  'forum_id' => $f2,
 142                  'topic_id' => $t2,
 143              ),
 144          ) );
 145  
 146          bbp_update_forum_last_active_id( $f2 );
 147          $id = bbp_get_forum_last_active_id( $f2 );
 148          $this->assertSame( $r2, $id );
 149  
 150          bbp_update_forum_last_active_id( $f1 );
 151          $id = bbp_get_forum_last_active_id( $f1 );
 152          $this->assertSame( $r2, $id );
 153      }
 154  
 155      /**
 156       * @covers ::bbp_update_forum_last_active_time
 157       */
 158  	public function test_bbp_update_forum_last_active_time() {
 159          $f1 = $this->factory->forum->create();
 160          $f2 = $this->factory->forum->create( array(
 161              'post_parent' => $f1,
 162          ) );
 163  
 164          $t1 = $this->factory->topic->create( array(
 165              'post_parent' => $f1,
 166              'topic_meta' => array(
 167                  'forum_id' => $f1,
 168              ),
 169          ) );
 170          $r1 = $this->factory->reply->create( array(
 171              'post_parent' => $t1,
 172              'reply_meta' => array(
 173                  'forum_id' => $f1,
 174                  'topic_id' => $t1,
 175              ),
 176          ) );
 177  
 178          $r1_time_raw       = get_post_field( 'post_date', $r1 );
 179          $r1_time_formatted = bbp_get_time_since( bbp_convert_date( $r1_time_raw ) );
 180  
 181          $time = bbp_update_forum_last_active_time( $f1, $r1_time_raw );
 182          $this->assertSame( $r1_time_raw, $time );
 183  
 184          $time = bbp_get_forum_last_active_time( $f1 );
 185          $this->assertSame( $r1_time_formatted, $time );
 186  
 187          $t2 = $this->factory->topic->create( array(
 188              'post_parent' => $f2,
 189              'topic_meta' => array(
 190                  'forum_id' => $f2,
 191              ),
 192          ) );
 193          $r2 = $this->factory->reply->create( array(
 194              'post_parent' => $t2,
 195              'reply_meta' => array(
 196                  'forum_id' => $f2,
 197                  'topic_id' => $t2,
 198              ),
 199          ) );
 200  
 201          $r2_time_raw       = get_post_field( 'post_date', $r2 );
 202          $r2_time_formatted = bbp_get_time_since( bbp_convert_date( $r2_time_raw ) );
 203  
 204          bbp_update_forum_last_active_time( $f2 );
 205          $time = bbp_get_forum_last_active_time( $f2 );
 206          $this->assertSame( $r2_time_formatted, $time );
 207  
 208          bbp_update_forum_last_active_time( $f1 );
 209          $time = bbp_get_forum_last_active_time( $f1 );
 210          $this->assertSame( $r2_time_formatted, $time );
 211      }
 212  }


Generated: Sat Dec 21 01:00:52 2024 Cross-referenced by PHPXref 0.7.1