[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/tests/phpunit/testcases/common/ -> query.php (source)

   1  <?php
   2  
   3  /**
   4   * Tests for the common query functions.
   5   *
   6   * @group common
   7   * @group functions
   8   * @group query
   9   */
  10  class BBP_Tests_Common_Functions_Query extends BBP_UnitTestCase {
  11  
  12       /**
  13       * @covers ::bbp_query_post_parent__in
  14       * @todo   Implement test_bbp_query_post_parent__in().
  15       */
  16  	public function test_bbp_query_post_parent__in() {
  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_get_public_child_last_id
  25       */
  26  	public function test_bbp_get_public_child_last_id() {
  27          $f = $this->factory->forum->create();
  28  
  29          $t = $this->factory->topic->create( array(
  30              'post_parent' => $f,
  31              'topic_meta' => array(
  32                  'forum_id' => $f,
  33              ),
  34          ) );
  35  
  36          $last_id = bbp_get_public_child_last_id( $f, bbp_get_topic_post_type() );
  37          $this->assertSame( $t, $last_id );
  38  
  39          $r = $this->factory->reply->create( array(
  40              'post_parent' => $t,
  41              'reply_meta' => array(
  42                  'forum_id' => $f,
  43                  'topic_id' => $t,
  44              ),
  45          ) );
  46  
  47          $last_id = bbp_get_public_child_last_id( $t, bbp_get_reply_post_type() );
  48          $this->assertSame( $r, $last_id );
  49      }
  50  
  51      /**
  52       * @group  counts
  53       * @covers ::bbp_get_public_child_count
  54       */
  55  	public function test_bbp_get_public_child_count() {
  56  
  57          /* Empty Forum ********************************************************/
  58  
  59          $f = $this->factory->forum->create();
  60  
  61          // Test initial zero forum public child counts
  62          $count = bbp_get_public_child_count( $f, bbp_get_forum_post_type() );
  63          $this->assertSame( 0, $count );
  64  
  65          $count = bbp_get_public_child_count( $f, bbp_get_topic_post_type() );
  66          $this->assertSame( 0, $count );
  67  
  68          /* Sub-Forums *********************************************************/
  69  
  70          // 3 public sub-forums
  71          $this->factory->forum->create_many( 3, array(
  72              'post_parent' => $f,
  73          ) );
  74  
  75          // 1 private sub-forum
  76          $this->factory->forum->create( array(
  77              'post_parent' => $f,
  78              'post_status' => bbp_get_private_status_id(),
  79          ) );
  80  
  81          $count = bbp_get_public_child_count( $f, bbp_get_forum_post_type() );
  82          $this->assertSame( 3, $count );
  83  
  84          $this->factory->forum->create_many( 2, array(
  85              'post_parent' => $f,
  86          ) );
  87  
  88          $count = bbp_get_public_child_count( $f, bbp_get_forum_post_type() );
  89          $this->assertSame( 5, $count );
  90  
  91          /* Topics *************************************************************/
  92  
  93          $t1 = $this->factory->topic->create_many( 3, array(
  94              'post_parent' => $f,
  95              'topic_meta' => array(
  96                  'forum_id' => $f,
  97              ),
  98          ) );
  99  
 100          $this->factory->topic->create( array(
 101              'post_parent' => $f,
 102              'post_status' => bbp_get_spam_status_id(),
 103              'topic_meta' => array(
 104                  'forum_id' => $f,
 105              ),
 106          ) );
 107  
 108          $count = bbp_get_public_child_count( $f, bbp_get_topic_post_type() );
 109          $this->assertSame( 3, $count );
 110  
 111          $this->factory->topic->create_many( 2, array(
 112              'post_parent' => $f,
 113              'topic_meta' => array(
 114                  'forum_id' => $f,
 115              ),
 116          ) );
 117  
 118          $count = bbp_get_public_child_count( $f, bbp_get_topic_post_type() );
 119          $this->assertSame( 5, $count );
 120  
 121          /* Replies ************************************************************/
 122  
 123          $this->factory->reply->create_many( 3, array(
 124              'post_parent' => $t1[0],
 125              'reply_meta' => array(
 126                  'forum_id' => $f,
 127                  'topic_id' => $t1[0],
 128              ),
 129          ) );
 130  
 131          $this->factory->reply->create( array(
 132              'post_parent' => $t1[0],
 133              'post_status' => bbp_get_spam_status_id(),
 134              'reply_meta' => array(
 135                  'forum_id' => $f,
 136                  'topic_id' => $t1[0],
 137              ),
 138          ) );
 139  
 140          $count = bbp_get_public_child_count( $t1[0], bbp_get_reply_post_type() );
 141          $this->assertSame( 3, $count );
 142  
 143          $this->factory->reply->create_many( 2, array(
 144              'post_parent' => $t1[0],
 145              'reply_meta' => array(
 146                  'forum_id' => $f,
 147                  'topic_id' => $t1[0],
 148              ),
 149          ) );
 150  
 151          $count = bbp_get_public_child_count( $t1[0], bbp_get_reply_post_type() );
 152          $this->assertSame( 5, $count );
 153      }
 154  
 155      /**
 156       * @covers ::bbp_get_public_child_ids
 157       */
 158  	public function test_bbp_get_public_child_ids() {
 159          $f = $this->factory->forum->create();
 160  
 161          // Test initial forum public child counts
 162          $count = count( bbp_get_public_child_ids( $f, bbp_get_forum_post_type() ) );
 163          $this->assertSame( 0, $count );
 164  
 165          $count = count( bbp_get_public_child_ids( $f, bbp_get_topic_post_type() ) );
 166          $this->assertSame( 0, $count );
 167  
 168          /* Sub-Forums *********************************************************/
 169  
 170          $this->factory->forum->create_many( 3, array(
 171              'post_parent' => $f,
 172          ) );
 173  
 174          $this->factory->forum->create( array(
 175              'post_parent' => $f,
 176              'post_status' => bbp_get_private_status_id(),
 177          ) );
 178  
 179          $count = count( bbp_get_public_child_ids( $f, bbp_get_forum_post_type() ) );
 180          $this->assertSame( 3, $count );
 181  
 182          $this->factory->forum->create_many( 2, array(
 183              'post_parent' => $f,
 184          ) );
 185  
 186          $count = count( bbp_get_public_child_ids( $f, bbp_get_forum_post_type() ) );
 187          $this->assertSame( 5, $count );
 188  
 189          /* Topics *************************************************************/
 190  
 191          $t1 = $this->factory->topic->create_many( 3, array(
 192              'post_parent' => $f,
 193              'topic_meta' => array(
 194                  'forum_id' => $f,
 195              ),
 196          ) );
 197  
 198          $this->factory->topic->create( array(
 199              'post_parent' => $f,
 200              'post_status' => bbp_get_spam_status_id(),
 201              'topic_meta' => array(
 202                  'forum_id' => $f,
 203              ),
 204          ) );
 205  
 206          $count = count( bbp_get_public_child_ids( $f, bbp_get_topic_post_type() ) );
 207          $this->assertSame( 3, $count );
 208  
 209          $this->factory->topic->create_many( 2, array(
 210              'post_parent' => $f,
 211              'topic_meta' => array(
 212                  'forum_id' => $f,
 213              ),
 214          ) );
 215  
 216          $count = count( bbp_get_public_child_ids( $f, bbp_get_topic_post_type() ) );
 217          $this->assertSame( 5, $count );
 218  
 219          /* Replies ************************************************************/
 220  
 221          $this->factory->reply->create_many( 3, array(
 222              'post_parent' => $t1[0],
 223              'reply_meta' => array(
 224                  'forum_id' => $f,
 225                  'topic_id' => $t1[0],
 226              ),
 227          ) );
 228  
 229          $this->factory->reply->create( array(
 230              'post_parent' => $t1[0],
 231              'post_status' => bbp_get_spam_status_id(),
 232              'reply_meta' => array(
 233                  'forum_id' => $f,
 234                  'topic_id' => $t1[0],
 235              ),
 236          ) );
 237  
 238          $count = count( bbp_get_public_child_ids( $t1[0], bbp_get_reply_post_type() ) );
 239          $this->assertSame( 3, $count );
 240  
 241          $this->factory->reply->create_many( 2, array(
 242              'post_parent' => $t1[0],
 243              'reply_meta' => array(
 244                  'forum_id' => $f,
 245                  'topic_id' => $t1[0],
 246              ),
 247          ) );
 248  
 249          $count = count( bbp_get_public_child_ids( $t1[0], bbp_get_reply_post_type() ) );
 250          $this->assertSame( 5, $count );
 251      }
 252  
 253      /**
 254       * @covers ::bbp_get_all_child_ids
 255       */
 256  	public function test_bbp_get_all_child_ids() {
 257          $f = $this->factory->forum->create();
 258  
 259          // Test initial forum public child counts
 260          $count = count( bbp_get_all_child_ids( $f, bbp_get_forum_post_type() ) );
 261          $this->assertSame( 0, $count );
 262  
 263          $count = count( bbp_get_all_child_ids( $f, bbp_get_topic_post_type() ) );
 264          $this->assertSame( 0, $count );
 265  
 266          /* Sub-Forums *********************************************************/
 267  
 268          $this->factory->forum->create_many( 3, array(
 269              'post_parent' => $f,
 270          ) );
 271  
 272          $this->factory->forum->create( array(
 273              'post_parent' => $f,
 274              'post_status' => bbp_get_private_status_id(),
 275          ) );
 276  
 277          $count = count( bbp_get_all_child_ids( $f, bbp_get_forum_post_type() ) );
 278          $this->assertSame( 4, $count );
 279  
 280          $this->factory->forum->create_many( 2, array(
 281              'post_parent' => $f,
 282          ) );
 283  
 284          $count = count( bbp_get_all_child_ids( $f, bbp_get_forum_post_type() ) );
 285          $this->assertSame( 6, $count );
 286  
 287          /* Topics *************************************************************/
 288  
 289          $t1 = $this->factory->topic->create_many( 3, array(
 290              'post_parent' => $f,
 291              'topic_meta' => array(
 292                  'forum_id' => $f,
 293              ),
 294          ) );
 295  
 296          $this->factory->topic->create( array(
 297              'post_parent' => $f,
 298              'post_status' => bbp_get_spam_status_id(),
 299              'topic_meta' => array(
 300                  'forum_id' => $f,
 301              ),
 302          ) );
 303  
 304          $count = count( bbp_get_all_child_ids( $f, bbp_get_topic_post_type() ) );
 305          $this->assertSame( 4, $count );
 306  
 307          $this->factory->topic->create_many( 2, array(
 308              'post_parent' => $f,
 309              'topic_meta' => array(
 310                  'forum_id' => $f,
 311              ),
 312          ) );
 313  
 314          $count = count( bbp_get_all_child_ids( $f, bbp_get_topic_post_type() ) );
 315          $this->assertSame( 6, $count );
 316  
 317          $this->factory->topic->create( array(
 318              'post_parent' => $f,
 319              'post_status' => bbp_get_pending_status_id(),
 320              'topic_meta' => array(
 321                  'forum_id' => $f,
 322              ),
 323          ) );
 324  
 325          $count = count( bbp_get_all_child_ids( $f, bbp_get_topic_post_type() ) );
 326          $this->assertSame( 7, $count );
 327  
 328          /* Replies ************************************************************/
 329  
 330          $this->factory->reply->create_many( 3, array(
 331              'post_parent' => $t1[0],
 332              'reply_meta' => array(
 333                  'forum_id' => $f,
 334                  'topic_id' => $t1[0],
 335              ),
 336          ) );
 337  
 338          $this->factory->reply->create( array(
 339              'post_parent' => $t1[0],
 340              'post_status' => bbp_get_spam_status_id(),
 341              'reply_meta' => array(
 342                  'forum_id' => $f,
 343                  'topic_id' => $t1[0],
 344              ),
 345          ) );
 346  
 347          $count = count( bbp_get_all_child_ids( $t1[0], bbp_get_reply_post_type() ) );
 348          $this->assertSame( 4, $count );
 349  
 350          $this->factory->reply->create_many( 2, array(
 351              'post_parent' => $t1[0],
 352              'reply_meta' => array(
 353                  'forum_id' => $f,
 354                  'topic_id' => $t1[0],
 355              ),
 356          ) );
 357  
 358          $count = count( bbp_get_all_child_ids( $t1[0], bbp_get_reply_post_type() ) );
 359          $this->assertSame( 6, $count );
 360  
 361          $this->factory->reply->create( array(
 362              'post_parent' => $t1[0],
 363              'post_status' => bbp_get_pending_status_id(),
 364              'reply_meta' => array(
 365                  'forum_id' => $f,
 366                  'topic_id' => $t1[0],
 367              ),
 368          ) );
 369  
 370          $count = count( bbp_get_all_child_ids( $t1[0], bbp_get_reply_post_type() ) );
 371          $this->assertSame( 7, $count );
 372      }
 373  }


Generated: Sat Apr 27 01:00:49 2024 Cross-referenced by PHPXref 0.7.1