[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/tests/phpunit/testcases/users/functions/ -> counts.php (source)

   1  <?php
   2  
   3  /**
   4   * Tests for the user component count functions.
   5   *
   6   * @group users
   7   * @group functions
   8   * @group counts
   9   */
  10  class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase {
  11  
  12      /**
  13       * @covers ::bbp_update_user_reply_count
  14       */
  15  	function test_bbp_update_user_topic_count() {
  16          $u = $this->factory->user->create();
  17          $int_value = 3;
  18  
  19          bbp_update_user_topic_count( $u, $int_value );
  20  
  21          $count = bbp_get_user_topic_count( $u, true );
  22          $this->assertSame( $int_value, $count );
  23      }
  24  
  25      /**
  26       * @covers ::bbp_update_user_reply_count
  27       */
  28  	function test_bbp_update_user_reply_count() {
  29          $u = $this->factory->user->create();
  30          $int_value = 3;
  31  
  32          bbp_update_user_reply_count( $u, $int_value );
  33  
  34          $count = bbp_get_user_reply_count( $u, true );
  35          $this->assertSame( $int_value, $count );
  36      }
  37  
  38      /**
  39       * @covers ::bbp_user_topic_count
  40       * @covers ::bbp_get_user_topic_count
  41       */
  42  	function test_bbp_get_user_topic_count() {
  43          $u = $this->factory->user->create();
  44          $int_value = 3;
  45          $formatted_value = bbp_number_format( $int_value );
  46  
  47          bbp_update_user_topic_count( $u, $int_value );
  48  
  49          $this->expectOutputString( $formatted_value );
  50          bbp_user_topic_count( $u );
  51  
  52          $count = bbp_get_user_topic_count( $u, false );
  53          $this->assertSame( $formatted_value, $count );
  54  
  55          $count = bbp_get_user_topic_count( $u, true );
  56          $this->assertSame( (int) $int_value, $count );
  57      }
  58  
  59      /**
  60       * @covers ::bbp_user_reply_count
  61       * @covers ::bbp_get_user_reply_count
  62       */
  63  	function test_bbp_get_user_reply_count() {
  64          $u = $this->factory->user->create();
  65          $int_value = 3;
  66          $formatted_value = bbp_number_format( $int_value );
  67  
  68          bbp_update_user_reply_count( $u, $int_value );
  69  
  70          $this->expectOutputString( $formatted_value );
  71          bbp_user_reply_count( $u );
  72  
  73          $count = bbp_get_user_reply_count( $u, false );
  74          $this->assertSame( $formatted_value, $count );
  75  
  76          $count = bbp_get_user_reply_count( $u, true );
  77          $this->assertSame( (int) $int_value, $count );
  78      }
  79  
  80      /**
  81       * @covers ::bbp_user_post_count
  82       * @covers ::bbp_get_user_post_count
  83       */
  84  	function test_bbp_get_user_post_count() {
  85          $u = $this->factory->user->create();
  86          $int_value = 3;
  87          $integer = true;
  88  
  89          // Add reply count
  90          bbp_update_user_reply_count( $u, $int_value );
  91  
  92          // Count
  93          $count = bbp_get_user_post_count( $u, $integer );
  94          $this->assertSame( $int_value, $count );
  95  
  96          // Add topic count
  97          bbp_update_user_topic_count( $u, $int_value );
  98          $double_value = $int_value * 2;
  99  
 100          // Count + Count
 101          $double_count = bbp_get_user_post_count( $u, true );
 102          $this->assertSame( $double_value, $double_count );
 103  
 104          // Output
 105          $double_formatted_value = bbp_number_format( $double_value );
 106          $this->expectOutputString( $double_formatted_value );
 107          bbp_user_post_count( $u );
 108      }
 109  
 110      /**
 111       * @covers ::bbp_get_user_topics_started
 112       */
 113  	public function test_bbp_get_user_topics_started() {
 114          $u = $this->factory->user->create();
 115  
 116          $has_topics = bbp_get_user_topics_started( $u );
 117          $this->assertFalse( $has_topics );
 118  
 119          $t = $this->factory->topic->create_many( 3, array(
 120              'post_author' => $u,
 121          ) );
 122  
 123          bbp_update_topic( array(
 124              'topic_id' => $t,
 125          ) );
 126  
 127          $has_topics = bbp_get_user_topics_started( $u );
 128          $this->assertTrue( $has_topics );
 129      }
 130  
 131      /**
 132       * @covers ::bbp_get_user_replies_created
 133       */
 134  	public function test_bbp_get_user_replies_created() {
 135          $u = $this->factory->user->create();
 136  
 137          $t = $this->factory->topic->create();
 138  
 139          $has_replies = bbp_get_user_replies_created( $u );
 140          $this->assertFalse( $has_replies );
 141  
 142          $r = $this->factory->reply->create_many( 3, array(
 143              'post_parent' => $t,
 144              'post_author' => $u,
 145              'reply_meta' => array(
 146                  'topic_id' => $t,
 147              ),
 148          ) );
 149  
 150          $has_replies = bbp_get_user_replies_created( $u );
 151          $this->assertTrue( $has_replies );
 152      }
 153  
 154      /**
 155       * @covers ::bbp_get_total_users
 156       */
 157  	public function test_bbp_get_total_users() {
 158          $this->factory->user->create_many( 3 );
 159  
 160          $users = (int) bbp_get_total_users();
 161  
 162          // 15 + 1, the + 1 is the default admin user
 163          $this->assertSame( 4, $users );
 164      }
 165  
 166      /**
 167       * @covers ::bbp_get_user_topic_count_raw
 168       */
 169  	public function test_bbp_get_user_topic_count_raw() {
 170          $u = $this->factory->user->create();
 171  
 172          $t = $this->factory->topic->create_many( 3, array(
 173              'post_author' => $u,
 174          ) );
 175  
 176          $count = bbp_get_user_topic_count_raw( $u );
 177          $this->assertSame( 3, $count );
 178  
 179          $t = $this->factory->topic->create_many( 3, array(
 180              'post_author' => $u,
 181          ) );
 182  
 183          $count = bbp_get_user_topic_count_raw( $u );
 184          $this->assertSame( 6, $count );
 185  
 186          $t = $this->factory->topic->create( array(
 187              'post_author' => $u,
 188          ) );
 189  
 190          bbp_close_topic( $t );
 191  
 192          $count = bbp_get_user_topic_count_raw( $u );
 193          $this->assertSame( 7, $count );
 194      }
 195  
 196      /**
 197       * @covers ::bbp_get_user_reply_count_raw
 198       */
 199  	public function test_bbp_get_user_reply_count_raw() {
 200          $u = $this->factory->user->create();
 201  
 202          $t = $this->factory->topic->create();
 203  
 204          $r = $this->factory->reply->create_many( 3, array(
 205              'post_parent' => $t,
 206              'post_author' => $u,
 207              'reply_meta' => array(
 208                  'topic_id' => $t,
 209              ),
 210          ) );
 211  
 212          $count = bbp_get_user_reply_count_raw( $u );
 213          $this->assertSame( 3, $count );
 214  
 215          $r = $this->factory->reply->create_many( 3, array(
 216              'post_parent' => $t,
 217              'post_author' => $u,
 218              'reply_meta' => array(
 219                  'topic_id' => $t,
 220              ),
 221          ) );
 222  
 223          $count = bbp_get_user_reply_count_raw( $u );
 224          $this->assertSame( 6, $count );
 225      }
 226  
 227      /**
 228       * @covers ::bbp_bump_user_topic_count
 229       */
 230  	public function test_bbp_bump_user_topic_count() {
 231          $u = $this->factory->user->create();
 232          $int_value = 3;
 233          $integer = true;
 234  
 235          bbp_update_user_topic_count( $u, $int_value );
 236  
 237          $count = bbp_get_user_topic_count( $u, $integer );
 238          $this->assertSame( $int_value, $count );
 239  
 240          bbp_bump_user_topic_count( $u );
 241  
 242          $count = bbp_get_user_topic_count( $u, $integer );
 243          $this->assertSame( $int_value + 1, $count );
 244      }
 245  
 246      /**
 247       * @covers ::bbp_bump_user_reply_count
 248       */
 249  	public function test_bbp_bump_user_reply_count() {
 250          $u = $this->factory->user->create();
 251          $int_value = 3;
 252          $integer = true;
 253  
 254          bbp_update_user_reply_count( $u, $int_value );
 255  
 256          $count = bbp_get_user_reply_count( $u, $integer );
 257          $this->assertSame( $int_value, $count );
 258  
 259          bbp_bump_user_reply_count( $u );
 260  
 261          $count = bbp_get_user_reply_count( $u, $integer );
 262          $this->assertSame( $int_value + 1, $count );
 263      }
 264  
 265      /**
 266       * @covers ::bbp_increase_user_topic_count
 267       */
 268  	public function test_bbp_increase_user_topic_count() {
 269          $u = $this->factory->user->create();
 270          $int_value = 3;
 271          $integer = true;
 272  
 273          bbp_update_user_topic_count( $u, $int_value );
 274  
 275          $count = bbp_get_user_topic_count( $u, $integer );
 276          $this->assertSame( $int_value, $count );
 277  
 278          $t = $this->factory->topic->create( array(
 279              'post_author' => $u,
 280          ) );
 281  
 282          bbp_increase_user_topic_count( $t );
 283  
 284          $count = bbp_get_user_topic_count( $u, $integer );
 285          $this->assertSame( $int_value + 1, $count );
 286      }
 287  
 288      /**
 289       * @covers ::bbp_increase_user_reply_count
 290       */
 291  	public function test_bbp_increase_user_reply_count() {
 292          $u = $this->factory->user->create();
 293          $int_value = 3;
 294          $integer = true;
 295  
 296          bbp_update_user_reply_count( $u, $int_value );
 297  
 298          $count = bbp_get_user_reply_count( $u, $integer );
 299          $this->assertSame( $int_value, $count );
 300  
 301          $t = $this->factory->topic->create();
 302  
 303          $r = $this->factory->reply->create_many( $int_value, array(
 304              'post_parent' => $t,
 305              'post_author' => $u,
 306              'reply_meta' => array(
 307                  'topic_id' => $t,
 308              ),
 309          ) );
 310  
 311          bbp_increase_user_reply_count( $r );
 312  
 313          $count = bbp_get_user_reply_count( $u, $integer );
 314          $this->assertSame( $int_value, $count );
 315      }
 316  
 317      /**
 318       * @covers ::bbp_decrease_user_topic_count
 319       */
 320  	public function test_bbp_decrease_user_topic_count() {
 321          $u = $this->factory->user->create();
 322          $int_value = 3;
 323          $integer = true;
 324  
 325          bbp_update_user_topic_count( $u, $int_value );
 326  
 327          $count = bbp_get_user_topic_count( $u, $integer );
 328          $this->assertSame( $int_value, $count );
 329  
 330          $t = $this->factory->topic->create( array(
 331              'post_author' => $u,
 332          ) );
 333  
 334          // Minus 1
 335          bbp_decrease_user_topic_count( $t );
 336  
 337          $count = bbp_get_user_topic_count( $u, $integer );
 338          $this->assertSame( $int_value - 1, $count );
 339  
 340          // Minus 2
 341          bbp_decrease_user_topic_count( $t );
 342  
 343          $count = bbp_get_user_topic_count( $u, $integer );
 344          $this->assertSame( $int_value - 2, $count );
 345      }
 346  
 347      /**
 348       * @covers ::bbp_decrease_user_reply_count
 349       */
 350  	public function test_bbp_decrease_user_reply_count() {
 351          $u = $this->factory->user->create();
 352          $int_value = 3;
 353          $integer = true;
 354  
 355          bbp_update_user_reply_count( $u, $int_value );
 356  
 357          $count = bbp_get_user_reply_count( $u, $integer );
 358          $this->assertSame( $int_value, $count );
 359  
 360          $t = $this->factory->topic->create();
 361  
 362          $r = $this->factory->reply->create( array(
 363              'post_parent' => $t,
 364              'post_author' => $u,
 365              'reply_meta' => array(
 366                  'topic_id' => $t,
 367              ),
 368          ) );
 369  
 370          // Minus 1
 371          bbp_decrease_user_reply_count( $r );
 372  
 373          $count = bbp_get_user_reply_count( $u, $integer );
 374          $this->assertSame( $int_value - 1, $count );
 375  
 376          // Minus 2
 377          bbp_decrease_user_reply_count( $r );
 378  
 379          $count = bbp_get_user_reply_count( $u, $integer );
 380          $this->assertSame( $int_value - 2, $count );
 381      }
 382  }


Generated: Sat Dec 5 01:01:32 2020 Cross-referenced by PHPXref 0.7.1