[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/tests/phpunit/testcases/forums/template/ -> counts.php (source)

   1  <?php
   2  
   3  /**
   4   * Tests for the `bbp_*_forum_*_count()` template functions.
   5   *
   6   * @group forums
   7   * @group template
   8   * @group counts
   9   */
  10  class BBP_Tests_Forums_Template_Counts extends BBP_UnitTestCase {
  11  
  12      /**
  13       * @covers ::bbp_forum_subforum_count
  14       * @covers ::bbp_get_forum_subforum_count
  15       */
  16  	public function test_bbp_get_forum_subforum_count() {
  17          $f1 = $this->factory->forum->create();
  18          $int_value = 3;
  19          $formatted_value = bbp_number_format( $int_value );
  20  
  21          $this->factory->forum->create_many( $int_value, array(
  22              'post_parent' => $f1,
  23          ) );
  24  
  25          bbp_update_forum_subforum_count( $f1 );
  26  
  27          // Output.
  28          $count = bbp_get_forum_subforum_count( $f1, false );
  29          $this->expectOutputString( $formatted_value );
  30          bbp_forum_subforum_count( $f1 );
  31  
  32          // Formatted string.
  33          $count = bbp_get_forum_subforum_count( $f1, false );
  34          $this->assertSame( $formatted_value, $count );
  35  
  36          // Integer.
  37          $count = bbp_get_forum_subforum_count( $f1, true );
  38          $this->assertSame( $int_value, $count );
  39  
  40          // Direct query.
  41          $count = count( bbp_forum_query_subforum_ids( $f1 ) );
  42          $this->assertSame( $int_value, $count );
  43      }
  44  
  45      /**
  46       * @covers ::bbp_forum_topic_count
  47       * @covers ::bbp_get_forum_topic_count
  48       */
  49  	public function test_bbp_get_forum_topic_count() {
  50          $c = $this->factory->forum->create( array(
  51              'forum_meta' => array(
  52                  'forum_type' => 'category',
  53              ),
  54          ) );
  55  
  56          $f = $this->factory->forum->create( array(
  57              'post_parent' => $c,
  58              'forum_meta' => array(
  59                  'forum_id'   => $c,
  60              ),
  61          ) );
  62  
  63          $int_value = 3;
  64          $formatted_value = bbp_number_format( $int_value );
  65  
  66          $this->factory->topic->create_many( $int_value, array(
  67              'post_parent' => $f,
  68          ) );
  69  
  70          bbp_update_forum_topic_count( $c );
  71          bbp_update_forum_topic_count( $f );
  72  
  73          // Forum output.
  74          $count = bbp_get_forum_topic_count( $f, true, false );
  75          $this->expectOutputString( $formatted_value );
  76          bbp_forum_topic_count( $f );
  77  
  78          // Forum formatted string.
  79          $count = bbp_get_forum_topic_count( $f, true, false );
  80          $this->assertSame( $formatted_value, $count );
  81  
  82          // Forum integer.
  83          $count = bbp_get_forum_topic_count( $f, true, true );
  84          $this->assertSame( $int_value, $count );
  85  
  86          // Category topic count.
  87          $count = bbp_get_forum_topic_count( $c, false, true );
  88          $this->assertSame( 0, $count );
  89  
  90          // Category total topic count.
  91          $count = bbp_get_forum_topic_count( $c, true, true );
  92          $this->assertSame( $int_value, $count );
  93      }
  94  
  95      /**
  96       * @covers ::bbp_forum_reply_count
  97       * @covers ::bbp_get_forum_reply_count
  98       */
  99  	public function test_bbp_get_forum_reply_count() {
 100          $c = $this->factory->forum->create( array(
 101              'forum_meta' => array(
 102                  'forum_type' => 'category',
 103              ),
 104          ) );
 105  
 106          $f = $this->factory->forum->create( array(
 107              'post_parent' => $c,
 108              'forum_meta' => array(
 109                  'forum_id'   => $c,
 110              ),
 111          ) );
 112  
 113          $t = $this->factory->topic->create( array(
 114              'post_parent' => $f,
 115          ) );
 116  
 117          $int_value = 3;
 118          $formatted_value = bbp_number_format( $int_value );
 119  
 120          $this->factory->reply->create_many( $int_value, array(
 121              'post_parent' => $t,
 122          ) );
 123  
 124          bbp_update_forum_reply_count( $c );
 125          bbp_update_forum_reply_count( $f );
 126  
 127          // Forum Output.
 128          $count = bbp_get_forum_reply_count( $f, true, false );
 129          $this->expectOutputString( $formatted_value );
 130          bbp_forum_reply_count( $f );
 131  
 132          // Forum formatted string.
 133          $count = bbp_get_forum_reply_count( $f, true, false );
 134          $this->assertSame( $formatted_value, $count );
 135  
 136          // Forum integer.
 137          $count = bbp_get_forum_reply_count( $f, true, true );
 138          $this->assertSame( $int_value, $count );
 139  
 140          // Category reply count.
 141          $count = bbp_get_forum_reply_count( $c, false, true );
 142          $this->assertSame( 0, $count );
 143  
 144          // Category total reply count.
 145          $count = bbp_get_forum_reply_count( $c, true, true );
 146          $this->assertSame( $int_value, $count );
 147      }
 148  
 149      /**
 150       * @covers ::bbp_forum_post_count
 151       * @covers ::bbp_get_forum_post_count
 152       */
 153  	public function test_bbp_get_forum_post_count() {
 154          $c = $this->factory->forum->create( array(
 155              'forum_meta' => array(
 156                  'forum_type' => 'category',
 157              ),
 158          ) );
 159  
 160          $f = $this->factory->forum->create( array(
 161              'post_parent' => $c,
 162              'forum_meta' => array(
 163                  'forum_id'   => $c,
 164              ),
 165          ) );
 166  
 167          $t = $this->factory->topic->create( array(
 168              'post_parent' => $f,
 169          ) );
 170  
 171          $int_value = 3;
 172  
 173          // Topic + Replies.
 174          $result = 4;
 175          $formatted_result = bbp_number_format( $result );
 176  
 177          $this->factory->reply->create_many( $int_value, array(
 178              'post_parent' => $t,
 179          ) );
 180  
 181          bbp_update_forum_topic_count( $c );
 182          bbp_update_forum_topic_count( $f );
 183          bbp_update_forum_reply_count( $c );
 184          bbp_update_forum_reply_count( $f );
 185  
 186          // Forum output.
 187          $count = bbp_get_forum_post_count( $f, true, false );
 188          $this->expectOutputString( $formatted_result );
 189          bbp_forum_post_count( $f );
 190  
 191          // Forum formatted string.
 192          $count = bbp_get_forum_post_count( $f, true, false );
 193          $this->assertSame( $formatted_result, $count );
 194  
 195          // Forum integer.
 196          $count = bbp_get_forum_post_count( $f, true, true );
 197          $this->assertSame( $result, $count );
 198  
 199          // Category post count.
 200          $count = bbp_get_forum_post_count( $c, false, true );
 201          $this->assertSame( 0, $count );
 202  
 203          // Category total post count.
 204          $count = bbp_get_forum_post_count( $c, true, true );
 205          $this->assertSame( $result, $count );
 206      }
 207  
 208      /**
 209       * @covers ::bbp_forum_topic_count_hidden
 210       * @covers ::bbp_get_forum_topic_count_hidden
 211       */
 212  	public function test_bbp_get_forum_topic_count_hidden() {
 213          $c = $this->factory->forum->create( array(
 214              'forum_meta' => array(
 215                  'forum_type' => 'category',
 216              ),
 217          ) );
 218  
 219          $f = $this->factory->forum->create( array(
 220              'post_parent' => $c,
 221              'forum_meta' => array(
 222                  'forum_id'   => $c,
 223              ),
 224          ) );
 225  
 226          $int_value = 3;
 227          $formatted_value = bbp_number_format( $int_value );
 228  
 229          $this->factory->topic->create_many( $int_value, array(
 230              'post_parent' => $f,
 231              'post_status' => bbp_get_spam_status_id(),
 232          ) );
 233  
 234          bbp_update_forum_topic_count_hidden( $c );
 235          bbp_update_forum_topic_count_hidden( $f );
 236  
 237          // Forum output.
 238          $count = bbp_get_forum_topic_count_hidden( $f, false );
 239          $this->expectOutputString( $formatted_value );
 240          bbp_forum_topic_count_hidden( $f );
 241  
 242          // Forum formatted string.
 243          $count = bbp_get_forum_topic_count_hidden( $f, false );
 244          $this->assertSame( $formatted_value, $count );
 245  
 246          // Forum integer.
 247          $count = bbp_get_forum_topic_count_hidden( $f, true );
 248          $this->assertSame( $int_value, $count );
 249  
 250          // Category topic count hidden.
 251          $count = bbp_get_forum_topic_count_hidden( $c, true );
 252          $this->assertSame( 0, $count );
 253  
 254          // Category total topic count hidden.
 255          $count = bbp_get_forum_topic_count_hidden( $c, true );
 256          $this->assertSame( 0, $count );
 257      }
 258  }


Generated: Tue Mar 19 01:01:02 2024 Cross-referenced by PHPXref 0.7.1