[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/tests/phpunit/testcases/replies/functions/ -> status.php (source)

   1  <?php
   2  
   3  /**
   4   * Tests for the reply component functions.
   5   *
   6   * @group replies
   7   * @group functions
   8   * @group status
   9   */
  10  class BBP_Tests_Replies_Functions_Status extends BBP_UnitTestCase {
  11  
  12      /**
  13       * @covers ::bbp_get_reply_statuses
  14       * @todo   Implement test_bbp_get_reply_statuses().
  15       */
  16  	public function test_bbp_get_reply_statuses() {
  17          // Remove the following lines when you implement this test.
  18          $this->markTestIncomplete(
  19              'This test has not been implemented yet.'
  20          );
  21      }
  22  
  23      /**
  24       * @covers ::bbp_spam_reply
  25       */
  26  	public function test_bbp_spam_reply() {
  27  
  28          // Create a forum
  29          $f = $this->factory->forum->create();
  30  
  31          // Create a topic
  32          $t = $this->factory->topic->create( array(
  33              'post_parent' => $f,
  34              'topic_meta' => array(
  35                  'forum_id' => $f,
  36              )
  37          ) );
  38  
  39          // Create some replies
  40          $r = $this->factory->reply->create_many( 3, array(
  41              'post_parent' => $t,
  42              'reply_meta' => array(
  43                  'forum_id' => $f,
  44                  'topic_id' => $t,
  45              )
  46          ) );
  47  
  48          bbp_spam_reply( $r[1] );
  49  
  50          $reply_post_status = bbp_get_reply_status( $r[1] );
  51          $this->assertSame( 'spam', $reply_post_status );
  52  
  53          $reply_spam_meta_status = get_post_meta( $r[1], '_bbp_spam_meta_status', true );
  54          $this->assertSame( 'publish', $reply_spam_meta_status );
  55  
  56          $topic_reply_count = bbp_get_topic_reply_count( $t );
  57          $this->assertSame( '2', $topic_reply_count );
  58      }
  59  
  60      /**
  61       * @covers ::bbp_unspam_reply
  62       */
  63  	public function test_bbp_unspam_reply() {
  64  
  65          // Create a forum
  66          $f = $this->factory->forum->create();
  67  
  68          // Create a topic
  69          $t = $this->factory->topic->create( array(
  70              'post_parent' => $f,
  71              'topic_meta' => array(
  72                  'forum_id' => $f,
  73              )
  74          ) );
  75  
  76          // Create some replies
  77          $r = $this->factory->reply->create_many( 3, array(
  78              'post_parent' => $t,
  79              'reply_meta' => array(
  80                  'forum_id' => $f,
  81                  'topic_id' => $t,
  82              )
  83          ) );
  84  
  85          bbp_spam_reply( $r[1] );
  86  
  87          $reply_post_status = bbp_get_reply_status( $r[1] );
  88          $this->assertSame( 'spam', $reply_post_status );
  89  
  90          $reply_spam_meta_status = get_post_meta( $r[1], '_bbp_spam_meta_status', true );
  91          $this->assertSame( 'publish', $reply_spam_meta_status );
  92  
  93          $topic_reply_count = bbp_get_topic_reply_count( $t );
  94          $this->assertSame( '2', $topic_reply_count );
  95  
  96          bbp_unspam_reply( $r[1] );
  97  
  98          $reply_post_status = bbp_get_reply_status( $r[1] );
  99          $this->assertSame( 'publish', $reply_post_status );
 100  
 101          $reply_spam_meta_status = get_post_meta( $r[1], '_bbp_spam_meta_status', true );
 102          $this->assertSame( '', $reply_spam_meta_status );
 103  
 104          $topic_reply_count = bbp_get_topic_reply_count( $t );
 105          $this->assertSame( '3', $topic_reply_count );
 106      }
 107  
 108      /**
 109       * @covers ::bbp_approve_reply
 110       */
 111  	public function test_bbp_approve_reply() {
 112  
 113          // Create a forum.
 114          $f = $this->factory->forum->create();
 115  
 116          // Create a topic.
 117          $t = $this->factory->topic->create( array(
 118              'post_parent' => $f,
 119              'topic_meta' => array(
 120                  'forum_id' => $f,
 121              ),
 122          ) );
 123  
 124          // Create some replies.
 125          $r1 = $this->factory->reply->create( array(
 126              'post_parent' => $t,
 127              'reply_meta' => array(
 128                  'forum_id' => $f,
 129                  'topic_id' => $t,
 130              ),
 131          ) );
 132  
 133          $reply_post_status = bbp_get_reply_status( $r1 );
 134          $this->assertSame( 'publish', $reply_post_status );
 135  
 136          $topic_reply_count = bbp_get_topic_reply_count( $t );
 137          $this->assertSame( '1', $topic_reply_count );
 138  
 139          $r2 = $this->factory->reply->create( array(
 140              'post_parent' => $t,
 141              'post_status' => bbp_get_pending_status_id(),
 142              'reply_meta' => array(
 143                  'forum_id' => $f,
 144                  'topic_id' => $t,
 145              ),
 146          ) );
 147  
 148          $reply_post_status = bbp_get_reply_status( $r2 );
 149          $this->assertSame( 'pending', $reply_post_status );
 150  
 151          $topic_reply_count = bbp_get_topic_reply_count( $t );
 152          $this->assertSame( '1', $topic_reply_count );
 153  
 154          bbp_approve_reply( $r2 );
 155  
 156          $reply_post_status = bbp_get_reply_status( $r2 );
 157          $this->assertSame( 'publish', $reply_post_status );
 158  
 159          $topic_reply_count = bbp_get_topic_reply_count( $t );
 160          $this->assertSame( '2', $topic_reply_count );
 161      }
 162  
 163      /**
 164       * @covers ::bbp_unapprove_reply
 165       */
 166  	public function test_bbp_unapprove_reply() {
 167  
 168          // Create a forum.
 169          $f = $this->factory->forum->create();
 170  
 171          // Create a topic.
 172          $t = $this->factory->topic->create( array(
 173              'post_parent' => $f,
 174              'topic_meta' => array(
 175                  'forum_id' => $f,
 176              ),
 177          ) );
 178  
 179          // Create some replies.
 180          $r1 = $this->factory->reply->create( array(
 181              'post_parent' => $t,
 182              'reply_meta' => array(
 183                  'forum_id' => $f,
 184                  'topic_id' => $t,
 185              ),
 186          ) );
 187  
 188          $reply_post_status = bbp_get_reply_status( $r1 );
 189          $this->assertSame( 'publish', $reply_post_status );
 190  
 191          $topic_reply_count = bbp_get_topic_reply_count( $t );
 192          $this->assertSame( '1', $topic_reply_count );
 193  
 194          $r2 = $this->factory->reply->create( array(
 195              'post_parent' => $t,
 196              'reply_meta' => array(
 197                  'forum_id' => $f,
 198                  'topic_id' => $t,
 199              ),
 200          ) );
 201  
 202          $reply_post_status = bbp_get_reply_status( $r2 );
 203          $this->assertSame( 'publish', $reply_post_status );
 204  
 205          $topic_reply_count = bbp_get_topic_reply_count( $t );
 206          $this->assertSame( '2', $topic_reply_count );
 207  
 208          bbp_unapprove_reply( $r2 );
 209  
 210          $reply_post_status = bbp_get_reply_status( $r2 );
 211          $this->assertSame( 'pending', $reply_post_status );
 212  
 213          $topic_reply_count = bbp_get_topic_reply_count( $t );
 214          $this->assertSame( '1', $topic_reply_count );
 215      }
 216  }


Generated: Thu Sep 24 01:03:34 2020 Cross-referenced by PHPXref 0.7.1