Ticket #2801: 2801.01.patch
File 2801.01.patch, 49.2 KB (added by , 10 years ago) |
---|
-
new file tests/phpunit/testcases/common/query.php
diff --git tests/phpunit/testcases/common/query.php tests/phpunit/testcases/common/query.php new file mode 100644 index 0000000..9eeb7b6
- + 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_get_public_child_count 14 * @group counts 15 */ 16 public function test_bbp_get_public_child_count() { 17 $f = $this->factory->forum->create(); 18 19 // Test initial forum public child counts 20 $count = bbp_get_public_child_count( $f, bbp_get_forum_post_type() ); 21 $this->assertSame( 0, $count ); 22 23 $count = bbp_get_public_child_count( $f, bbp_get_topic_post_type() ); 24 $this->assertSame( 0, $count ); 25 26 /* Sub-Forums **************************************************************/ 27 28 $this->factory->forum->create_many( 3, array( 29 'post_parent' => $f, 30 ) ); 31 32 $this->factory->forum->create( array( 33 'post_parent' => $f, 34 'post_status' => bbp_get_private_status_id(), 35 ) ); 36 37 wp_cache_flush(); 38 $count = bbp_get_public_child_count( $f, bbp_get_forum_post_type() ); 39 $this->assertSame( 3, $count ); 40 41 $this->factory->forum->create_many( 2, array( 42 'post_parent' => $f, 43 ) ); 44 45 // Test that previous value was cached 46 $count = bbp_get_public_child_count( $f, bbp_get_forum_post_type() ); 47 $this->assertSame( 3, $count ); 48 49 // Test with a fresh count 50 wp_cache_flush(); 51 $count = bbp_get_public_child_count( $f, bbp_get_forum_post_type() ); 52 $this->assertSame( 5, $count ); 53 54 /* Topics ******************************************************************/ 55 56 $t1 = $this->factory->topic->create_many( 3, array( 57 'post_parent' => $f, 58 ) ); 59 60 $this->factory->topic->create( array( 61 'post_parent' => $f, 62 'post_status' => bbp_get_spam_status_id(), 63 ) ); 64 65 $count = bbp_get_public_child_count( $f, bbp_get_topic_post_type() ); 66 $this->assertSame( 3, $count ); 67 68 $this->factory->topic->create_many( 2, array( 69 'post_parent' => $f, 70 ) ); 71 72 // Test that previous value was cached 73 $count = bbp_get_public_child_count( $f, bbp_get_topic_post_type() ); 74 $this->assertSame( 3, $count ); 75 76 // Test with a fresh count 77 wp_cache_flush(); 78 $count = bbp_get_public_child_count( $f, bbp_get_topic_post_type() ); 79 $this->assertSame( 5, $count ); 80 81 /* Replies *****************************************************************/ 82 83 $this->factory->reply->create_many( 3, array( 84 'post_parent' => $t1[0], 85 ) ); 86 87 $this->factory->reply->create( array( 88 'post_parent' => $t1[0], 89 'post_status' => bbp_get_spam_status_id(), 90 ) ); 91 92 $count = bbp_get_public_child_count( $t1[0], bbp_get_reply_post_type() ); 93 $this->assertSame( 3, $count ); 94 95 $this->factory->reply->create_many( 2, array( 96 'post_parent' => $t1[0], 97 ) ); 98 99 // Test that previous value was cached 100 $count = bbp_get_public_child_count( $t1[0], bbp_get_reply_post_type() ); 101 $this->assertSame( 3, $count ); 102 103 // Test with a fresh count 104 wp_cache_flush(); 105 $count = bbp_get_public_child_count( $t1[0], bbp_get_reply_post_type() ); 106 $this->assertSame( 5, $count ); 107 } 108 109 /** 110 * @covers ::bbp_get_public_child_ids 111 */ 112 public function test_bbp_get_public_child_ids() { 113 $f = $this->factory->forum->create(); 114 115 // Test initial forum public child counts 116 $count = count( bbp_get_public_child_ids( $f, bbp_get_forum_post_type() ) ); 117 $this->assertSame( 0, $count ); 118 119 $count = count( bbp_get_public_child_ids( $f, bbp_get_topic_post_type() ) ); 120 $this->assertSame( 0, $count ); 121 122 /* Sub-Forums **************************************************************/ 123 124 $this->factory->forum->create_many( 3, array( 125 'post_parent' => $f, 126 ) ); 127 128 $this->factory->forum->create( array( 129 'post_parent' => $f, 130 'post_status' => bbp_get_private_status_id(), 131 ) ); 132 133 wp_cache_flush(); 134 $count = count( bbp_get_public_child_ids( $f, bbp_get_forum_post_type() ) ); 135 $this->assertSame( 3, $count ); 136 137 $this->factory->forum->create_many( 2, array( 138 'post_parent' => $f, 139 ) ); 140 141 // Test that previous value was cached 142 $count = count( bbp_get_public_child_ids( $f, bbp_get_forum_post_type() ) ); 143 $this->assertSame( 3, $count ); 144 145 // Test with a fresh count 146 wp_cache_flush(); 147 $count = count( bbp_get_public_child_ids( $f, bbp_get_forum_post_type() ) ); 148 $this->assertSame( 5, $count ); 149 150 /* Topics ******************************************************************/ 151 152 $t1 = $this->factory->topic->create_many( 3, array( 153 'post_parent' => $f, 154 ) ); 155 156 $this->factory->topic->create( array( 157 'post_parent' => $f, 158 'post_status' => bbp_get_spam_status_id(), 159 ) ); 160 161 $count = count( bbp_get_public_child_ids( $f, bbp_get_topic_post_type() ) ); 162 $this->assertSame( 3, $count ); 163 164 $this->factory->topic->create_many( 2, array( 165 'post_parent' => $f, 166 ) ); 167 168 // Test that previous value was cached 169 $count = count( bbp_get_public_child_ids( $f, bbp_get_topic_post_type() ) ); 170 $this->assertSame( 3, $count ); 171 172 // Test with a fresh count 173 wp_cache_flush(); 174 $count = count( bbp_get_public_child_ids( $f, bbp_get_topic_post_type() ) ); 175 $this->assertSame( 5, $count ); 176 177 /* Replies *****************************************************************/ 178 179 $this->factory->reply->create_many( 3, array( 180 'post_parent' => $t1[0], 181 ) ); 182 183 $this->factory->reply->create( array( 184 'post_parent' => $t1[0], 185 'post_status' => bbp_get_spam_status_id(), 186 ) ); 187 188 $count = count( bbp_get_public_child_ids( $t1[0], bbp_get_reply_post_type() ) ); 189 $this->assertSame( 3, $count ); 190 191 $this->factory->reply->create_many( 2, array( 192 'post_parent' => $t1[0], 193 ) ); 194 195 // Test that previous value was cached 196 $count = count( bbp_get_public_child_ids( $t1[0], bbp_get_reply_post_type() ) ); 197 $this->assertSame( 3, $count ); 198 199 // Test with a fresh count 200 wp_cache_flush(); 201 $count = count( bbp_get_public_child_ids( $t1[0], bbp_get_reply_post_type() ) ); 202 $this->assertSame( 5, $count ); 203 } 204 205 /** 206 * @covers ::bbp_get_all_child_ids 207 */ 208 public function test_bbp_get_all_child_ids() { 209 $f = $this->factory->forum->create(); 210 211 // Test initial forum public child counts 212 $count = count( bbp_get_all_child_ids( $f, bbp_get_forum_post_type() ) ); 213 $this->assertSame( 0, $count ); 214 215 $count = count( bbp_get_all_child_ids( $f, bbp_get_topic_post_type() ) ); 216 $this->assertSame( 0, $count ); 217 218 /* Sub-Forums **************************************************************/ 219 220 $this->factory->forum->create_many( 3, array( 221 'post_parent' => $f, 222 ) ); 223 224 $this->factory->forum->create( array( 225 'post_parent' => $f, 226 'post_status' => bbp_get_private_status_id(), 227 ) ); 228 229 wp_cache_flush(); 230 $count = count( bbp_get_all_child_ids( $f, bbp_get_forum_post_type() ) ); 231 $this->assertSame( 4, $count ); 232 233 $this->factory->forum->create_many( 2, array( 234 'post_parent' => $f, 235 ) ); 236 237 // Test that previous value was cached 238 $count = count( bbp_get_all_child_ids( $f, bbp_get_forum_post_type() ) ); 239 $this->assertSame( 4, $count ); 240 241 // Test with a fresh count 242 wp_cache_flush(); 243 $count = count( bbp_get_all_child_ids( $f, bbp_get_forum_post_type() ) ); 244 $this->assertSame( 6, $count ); 245 246 /* Topics ******************************************************************/ 247 248 $t1 = $this->factory->topic->create_many( 3, array( 249 'post_parent' => $f, 250 ) ); 251 252 $this->factory->topic->create( array( 253 'post_parent' => $f, 254 'post_status' => bbp_get_spam_status_id(), 255 ) ); 256 257 wp_cache_flush(); 258 $count = count( bbp_get_all_child_ids( $f, bbp_get_topic_post_type() ) ); 259 $this->assertSame( 4, $count ); 260 261 $this->factory->topic->create_many( 2, array( 262 'post_parent' => $f, 263 ) ); 264 265 // Test that previous value was cached 266 $count = count( bbp_get_all_child_ids( $f, bbp_get_topic_post_type() ) ); 267 $this->assertSame( 4, $count ); 268 269 // Test with a fresh count 270 wp_cache_flush(); 271 $count = count( bbp_get_all_child_ids( $f, bbp_get_topic_post_type() ) ); 272 $this->assertSame( 6, $count ); 273 274 /* Replies *****************************************************************/ 275 276 $this->factory->reply->create_many( 3, array( 277 'post_parent' => $t1[0], 278 ) ); 279 280 $this->factory->reply->create( array( 281 'post_parent' => $t1[0], 282 'post_status' => bbp_get_spam_status_id(), 283 ) ); 284 285 $count = count( bbp_get_all_child_ids( $t1[0], bbp_get_reply_post_type() ) ); 286 $this->assertSame( 4, $count ); 287 288 $this->factory->reply->create_many( 2, array( 289 'post_parent' => $t1[0], 290 ) ); 291 292 // Test that previous value was cached 293 $count = count( bbp_get_all_child_ids( $t1[0], bbp_get_reply_post_type() ) ); 294 $this->assertSame( 4, $count ); 295 296 // Test with a fresh count 297 wp_cache_flush(); 298 $count = count( bbp_get_all_child_ids( $t1[0], bbp_get_reply_post_type() ) ); 299 $this->assertSame( 6, $count ); 300 } 301 } -
tests/phpunit/testcases/forums/functions/counts.php
diff --git tests/phpunit/testcases/forums/functions/counts.php tests/phpunit/testcases/forums/functions/counts.php index 74f83eb..ea4b157 100644
10 10 class BBP_Tests_Forums_Functions_Counts extends BBP_UnitTestCase { 11 11 12 12 /** 13 * Generic function to test the counts on a new topic 14 */ 15 public function test_bbp_forum_new_topic_counts() { 16 $f = $this->factory->forum->create(); 17 $t1 = $this->factory->topic->create( array( 18 'post_parent' => $f, 19 'post_author' => bbp_get_current_user_id(), 20 'topic_meta' => array( 21 'forum_id' => $f, 22 ), 23 ) ); 24 $u = $this->factory->user->create(); 25 26 // Cheating here, but we need $_SERVER['SERVER_NAME'] to be set 27 $this->setUp_wp_mail( false ); 28 29 // Simulate the 'bbp_new_topic' action 30 do_action( 'bbp_new_topic', $t1, $f, false, get_post_field( 'post_author', $t1 ) ); 31 32 // Reverse our changes 33 $this->tearDown_wp_mail( false ); 34 35 $count = bbp_get_forum_topic_count( $f, true, true ); 36 $this->assertSame( 1, $count ); 37 38 $count = bbp_get_forum_topic_count_hidden( $f, true, true ); 39 $this->assertSame( 0, $count ); 40 41 $t2 = $this->factory->topic->create( array( 42 'post_parent' => $f, 43 'post_author' => $u, 44 'topic_meta' => array( 45 'forum_id' => $f, 46 ), 47 ) ); 48 49 bbp_clean_post_cache( $t2 ); 50 51 // Cheating here, but we need $_SERVER['SERVER_NAME'] to be set 52 $this->setUp_wp_mail( false ); 53 54 // Simulate the 'bbp_new_topic' action 55 do_action( 'bbp_new_topic', $t2, $f, false, get_post_field( 'post_author', $t2 ) ); 56 57 // Reverse our changes 58 $this->tearDown_wp_mail( false ); 59 60 $count = bbp_get_forum_topic_count( $f, true, true ); 61 $this->assertSame( 2, $count ); 62 63 $count = bbp_get_forum_topic_count_hidden( $f, true, true ); 64 $this->assertSame( 0, $count ); 65 } 66 67 /** 68 * Generic function to test the counts on a deleted topic 69 */ 70 public function test_bbp_forum_deleted_topic_counts() { 71 $f = $this->factory->forum->create(); 72 $t = $this->factory->topic->create_many( 3, array( 73 'post_parent' => $f, 74 'topic_meta' => array( 75 'forum_id' => $f, 76 ), 77 ) ); 78 $r1 = $this->factory->reply->create_many( 2, array( 79 'post_parent' => $t[0], 80 'reply_meta' => array( 81 'forum_id' => $f, 82 'topic_id' => $t[0], 83 ), 84 ) ); 85 $r2 = $this->factory->reply->create_many( 2, array( 86 'post_parent' => $t[1], 87 'reply_meta' => array( 88 'forum_id' => $f, 89 'topic_id' => $t[1], 90 ), 91 ) ); 92 93 bbp_clean_post_cache( $f ); 94 95 $count = bbp_update_forum_topic_count( $f ); 96 $this->assertSame( 3, $count ); 97 98 $count = bbp_update_forum_topic_count_hidden( $f ); 99 $this->assertSame( 0, $count ); 100 101 $count = bbp_update_forum_reply_count( $f ); 102 $this->assertSame( 4, $count ); 103 104 bbp_clean_post_cache( $t[2] ); 105 bbp_spam_topic( $t[2] ); 106 107 $count = bbp_get_forum_topic_count( $f, true, true ); 108 $this->assertSame( 2, $count ); 109 110 $count = bbp_get_forum_topic_count_hidden( $f, true, true ); 111 $this->assertSame( 1, $count ); 112 113 $count = bbp_get_forum_reply_count( $f, true, true ); 114 $this->assertSame( 4, $count ); 115 116 wp_delete_post( $t[1], true ); 117 wp_delete_post( $t[2], true ); 118 119 $count = bbp_get_forum_topic_count( $f, true, true ); 120 $this->assertSame( 1, $count ); 121 122 $count = bbp_get_forum_topic_count_hidden( $f, true, true ); 123 $this->assertSame( 0, $count ); 124 125 $count = bbp_get_forum_reply_count( $f, true, true ); 126 $this->assertSame( 2, $count ); 127 } 128 129 /** 130 * Generic function to test the counts on a trashed/untrashed topic 131 */ 132 public function test_bbp_forum_trashed_untrashed_topic_counts() { 133 $f = $this->factory->forum->create(); 134 $t = $this->factory->topic->create_many( 3, array( 135 'post_parent' => $f, 136 'topic_meta' => array( 137 'forum_id' => $f, 138 ), 139 ) ); 140 $r1 = $this->factory->reply->create_many( 2, array( 141 'post_parent' => $t[1], 142 'reply_meta' => array( 143 'forum_id' => $f, 144 'topic_id' => $t[1], 145 ), 146 ) ); 147 $r2 = $this->factory->reply->create_many( 2, array( 148 'post_parent' => $t[2], 149 'reply_meta' => array( 150 'forum_id' => $f, 151 'topic_id' => $t[2], 152 ), 153 ) ); 154 155 bbp_clean_post_cache( $f ); 156 157 $count = bbp_update_forum_topic_count( $f ); 158 $this->assertSame( 3, $count ); 159 160 $count = bbp_update_forum_topic_count_hidden( $f ); 161 $this->assertSame( 0, $count ); 162 163 $count = bbp_update_forum_reply_count( $f ); 164 $this->assertSame( 4, $count ); 165 166 wp_trash_post( $t[2] ); 167 168 $count = bbp_get_forum_topic_count( $f, true, true ); 169 $this->assertSame( 2, $count ); 170 171 $count = bbp_get_forum_topic_count_hidden( $f, true, true ); 172 $this->assertSame( 1, $count ); 173 174 $count = bbp_get_forum_reply_count( $f, true, true ); 175 $this->assertSame( 2, $count ); 176 177 $count = bbp_get_forum_reply_count( $f, true, true ); 178 $this->assertSame( 2, $count ); 179 180 wp_untrash_post( $t[2] ); 181 182 $count = bbp_get_forum_topic_count( $f, true, true ); 183 $this->assertSame( 3, $count ); 184 185 $count = bbp_get_forum_topic_count_hidden( $f, true, true ); 186 $this->assertSame( 0, $count ); 187 188 $count = bbp_get_forum_reply_count( $f, true, true ); 189 $this->assertSame( 4, $count ); 190 } 191 192 /** 193 * Generic function to test the counts on a spammed/unspammed topic 194 */ 195 public function test_bbp_forum_spammed_unspammed_topic_counts() { 196 $f = $this->factory->forum->create(); 197 $t = $this->factory->topic->create_many( 3, array( 198 'post_parent' => $f, 199 'topic_meta' => array( 200 'forum_id' => $f, 201 ), 202 ) ); 203 $r1 = $this->factory->reply->create_many( 2, array( 204 'post_parent' => $t[1], 205 'reply_meta' => array( 206 'forum_id' => $f, 207 'topic_id' => $t[1], 208 ), 209 ) ); 210 $r2 = $this->factory->reply->create_many( 2, array( 211 'post_parent' => $t[2], 212 'reply_meta' => array( 213 'forum_id' => $f, 214 'topic_id' => $t[2], 215 ), 216 ) ); 217 218 bbp_clean_post_cache( $f ); 219 220 $count = bbp_update_forum_topic_count( $f ); 221 $this->assertSame( 3, $count ); 222 223 $count = bbp_update_forum_topic_count_hidden( $f ); 224 $this->assertSame( 0, $count ); 225 226 $count = bbp_update_forum_reply_count( $f ); 227 $this->assertSame( 4, $count ); 228 229 bbp_spam_topic( $t[2] ); 230 231 $count = bbp_get_forum_topic_count( $f, true, true ); 232 $this->assertSame( 2, $count ); 233 234 $count = bbp_get_forum_topic_count_hidden( $f, true, true ); 235 $this->assertSame( 1, $count ); 236 237 $count = bbp_get_forum_reply_count( $f, true, true ); 238 $this->assertSame( 2, $count ); 239 240 bbp_unspam_topic( $t[2] ); 241 242 $count = bbp_get_forum_topic_count( $f, true, true ); 243 $this->assertSame( 3, $count ); 244 245 $count = bbp_get_forum_topic_count_hidden( $f, true, true ); 246 $this->assertSame( 0, $count ); 247 248 $count = bbp_get_forum_reply_count( $f, true, true ); 249 $this->assertSame( 4, $count ); 250 } 251 252 /** 253 * Generic function to test the counts on a approved/unapproved topic 254 */ 255 public function test_bbp_forum_approved_unapproved_topic_counts() { 256 $f = $this->factory->forum->create(); 257 $t = $this->factory->topic->create_many( 3, array( 258 'post_parent' => $f, 259 'topic_meta' => array( 260 'forum_id' => $f, 261 ), 262 ) ); 263 $r1 = $this->factory->reply->create_many( 2, array( 264 'post_parent' => $t[1], 265 'reply_meta' => array( 266 'forum_id' => $f, 267 'topic_id' => $t[1], 268 ), 269 ) ); 270 $r2 = $this->factory->reply->create_many( 2, array( 271 'post_parent' => $t[2], 272 'reply_meta' => array( 273 'forum_id' => $f, 274 'topic_id' => $t[2], 275 ), 276 ) ); 277 278 bbp_clean_post_cache( $f ); 279 280 $count = bbp_update_forum_topic_count( $f ); 281 $this->assertSame( 3, $count ); 282 283 $count = bbp_update_forum_topic_count_hidden( $f ); 284 $this->assertSame( 0, $count ); 285 286 $count = bbp_update_forum_reply_count( $f ); 287 $this->assertSame( 4, $count ); 288 289 bbp_clean_post_cache( $t[2] ); 290 bbp_unapprove_topic( $t[2] ); 291 292 $count = bbp_get_forum_topic_count( $f, true, true ); 293 $this->assertSame( 2, $count ); 294 295 $count = bbp_get_forum_topic_count_hidden( $f, true, true ); 296 $this->assertSame( 1, $count ); 297 298 $count = bbp_get_forum_reply_count( $f, true, true ); 299 $this->assertSame( 2, $count ); 300 301 bbp_approve_topic( $t[2] ); 302 303 $count = bbp_get_forum_topic_count( $f, true, true ); 304 $this->assertSame( 3, $count ); 305 306 $count = bbp_get_forum_topic_count_hidden( $f, true, true ); 307 $this->assertSame( 0, $count ); 308 309 $count = bbp_get_forum_reply_count( $f, true, true ); 310 $this->assertSame( 4, $count ); 311 } 312 313 public function test_bbp_move_topic_counts() { 314 $f = $this->factory->forum->create_many( 2 ); 315 $t1 = $this->factory->topic->create( array( 316 'post_parent' => $f[0], 317 'topic_meta' => array( 318 'forum_id' => $f[0], 319 ), 320 ) ); 321 $t2 = $this->factory->topic->create_many( 2, array( 322 'post_parent' => $f[1], 323 'topic_meta' => array( 324 'forum_id' => $f[1], 325 ), 326 ) ); 327 $r1 = $this->factory->reply->create_many( 2, array( 328 'post_parent' => $t2[0], 329 'reply_meta' => array( 330 'forum_id' => $f[1], 331 'topic_id' => $t2[0], 332 ), 333 ) ); 334 $r2 = $this->factory->reply->create_many( 2, array( 335 'post_parent' => $t2[1], 336 'reply_meta' => array( 337 'forum_id' => $f[1], 338 'topic_id' => $t2[1], 339 ), 340 ) ); 341 342 bbp_clean_post_cache( $f[0] ); 343 bbp_clean_post_cache( $f[1] ); 344 345 $count = bbp_update_forum_topic_count( $f[0] ); 346 $this->assertSame( 1, $count ); 347 348 $count = bbp_update_forum_topic_count_hidden( $f[0] ); 349 $this->assertSame( 0, $count ); 350 351 $count = bbp_update_forum_reply_count( $f[0] ); 352 $this->assertSame( 0, $count ); 353 354 $count = bbp_update_forum_topic_count( $f[1] ); 355 $this->assertSame( 2, $count ); 356 357 $count = bbp_update_forum_topic_count_hidden( $f[1] ); 358 $this->assertSame( 0, $count ); 359 360 $count = bbp_update_forum_reply_count( $f[1] ); 361 $this->assertSame( 4, $count ); 362 363 wp_update_post( array( 364 'ID' => $t2[0], 365 'post_parent' => $f[0], 366 ) ); 367 368 bbp_move_topic_handler( $t2[0], $f[1], $f[0] ); 369 370 $count = bbp_get_forum_topic_count( $f[0], true, true ); 371 $this->assertSame( 2, $count ); 372 373 $count = bbp_get_forum_topic_count_hidden( $f[0], true, true ); 374 $this->assertSame( 0, $count ); 375 376 $count = bbp_get_forum_reply_count( $f[0], true, true ); 377 $this->assertSame( 2, $count ); 378 379 $count = bbp_get_forum_topic_count( $f[1], true, true ); 380 $this->assertSame( 1, $count ); 381 382 $count = bbp_get_forum_topic_count_hidden( $f[1], true, true ); 383 $this->assertSame( 0, $count ); 384 385 $count = bbp_get_forum_reply_count( $f[1], true, true ); 386 $this->assertSame( 2, $count ); 387 } 388 389 /** 13 390 * @covers ::bbp_bump_forum_topic_count 14 391 */ 15 392 public function test_bbp_bump_forum_topic_count() { … … class BBP_Tests_Forums_Functions_Counts extends BBP_UnitTestCase { 60 437 public function test_bbp_update_forum_subforum_count() { 61 438 $f1 = $this->factory->forum->create(); 62 439 63 $f2 = $this->factory->forum->create_many( 9, array(440 $f2 = $this->factory->forum->create_many( 3, array( 64 441 'post_parent' => $f1, 65 442 ) ); 66 443 67 $count = bbp_get_forum_subforum_count( $f1, $integer =true );444 $count = bbp_get_forum_subforum_count( $f1, true ); 68 445 $this->assertSame( 0, $count ); 69 446 70 $count = count( bbp_forum_query_subforum_ids( $f1 ) );71 $this->assertSame( 9, $count );72 73 447 bbp_update_forum_subforum_count( $f1 ); 74 448 75 $count = bbp_get_forum_subforum_count( $f1, $integer = true ); 76 $this->assertSame( 9, $count ); 77 78 $count = count( bbp_forum_query_subforum_ids( $f1 ) ); 79 $this->assertSame( 9, $count ); 449 $count = bbp_get_forum_subforum_count( $f1, true ); 450 $this->assertSame( 3, $count ); 80 451 } 81 452 82 453 /** … … class BBP_Tests_Forums_Functions_Counts extends BBP_UnitTestCase { 111 482 'post_parent' => $f1, 112 483 ) ); 113 484 114 bbp_update_forum_subforum_count( $f1 ); 485 bbp_update_forum_topic_count( $f1 ); 486 bbp_update_forum_topic_count( $f2 ); 487 bbp_update_forum_topic_count( $f3 ); 115 488 116 489 $count = bbp_get_forum_topic_count( $f1 ); 117 490 $this->assertSame( '3', $count ); … … class BBP_Tests_Forums_Functions_Counts extends BBP_UnitTestCase { 127 500 'post_parent' => $f2, 128 501 ) ); 129 502 503 bbp_clean_post_cache( $f1 ); 504 bbp_clean_post_cache( $f2 ); 505 bbp_clean_post_cache( $f3 ); 506 507 bbp_update_forum_topic_count( $f1 ); 130 508 bbp_update_forum_topic_count( $f2 ); 509 bbp_update_forum_topic_count( $f3 ); 131 510 132 511 $count = bbp_get_forum_topic_count( $f1 ); 133 $this->assertSame( ' 3', $count );512 $this->assertSame( '7', $count ); 134 513 135 514 $count = bbp_get_forum_topic_count( $f2 ); 136 515 $this->assertSame( '4', $count ); … … class BBP_Tests_Forums_Functions_Counts extends BBP_UnitTestCase { 143 522 'post_parent' => $f3, 144 523 ) ); 145 524 525 bbp_clean_post_cache( $f1 ); 526 bbp_clean_post_cache( $f2 ); 527 bbp_clean_post_cache( $f3 ); 528 529 bbp_update_forum_topic_count( $f1 ); 530 bbp_update_forum_topic_count( $f2 ); 146 531 bbp_update_forum_topic_count( $f3 ); 147 532 148 533 $count = bbp_get_forum_topic_count( $f1 ); 149 $this->assertSame( ' 3', $count );534 $this->assertSame( '12', $count ); 150 535 151 536 $count = bbp_get_forum_topic_count( $f2 ); 152 537 $this->assertSame( '4', $count ); … … class BBP_Tests_Forums_Functions_Counts extends BBP_UnitTestCase { 164 549 $count = bbp_get_forum_topic_count( $f ); 165 550 $this->assertSame( '0', $count ); 166 551 167 $t = $this->factory->topic->create_many( 15, array(552 $t = $this->factory->topic->create_many( 3, array( 168 553 'post_parent' => $f, 169 554 ) ); 170 555 … … class BBP_Tests_Forums_Functions_Counts extends BBP_UnitTestCase { 173 558 $count = bbp_get_forum_topic_count_hidden( $f ); 174 559 $this->assertSame( '0', $count );; 175 560 176 bbp_spam_topic( $t[ 11] );561 bbp_spam_topic( $t[2] ); 177 562 178 563 bbp_update_forum_topic_count_hidden( $f ); 179 564 180 565 $count = bbp_get_forum_topic_count_hidden( $f ); 181 566 $this->assertSame( '1', $count );; 182 567 183 bbp_unapprove_topic( $t[ 7] );568 bbp_unapprove_topic( $t[0] ); 184 569 185 570 bbp_update_forum_topic_count_hidden( $f ); 186 571 … … class BBP_Tests_Forums_Functions_Counts extends BBP_UnitTestCase { 192 577 * @covers ::bbp_update_forum_reply_count 193 578 */ 194 579 public function test_bbp_update_forum_reply_count() { 195 $f = $this->factory->forum->create();580 $f1 = $this->factory->forum->create(); 196 581 197 $count = bbp_get_forum_reply_count( $f ); 198 $this->assertSame( '0', $count ); 582 $f2 = $this->factory->forum->create( array( 583 'post_parent' => $f1, 584 ) ); 199 585 200 $t = $this->factory->topic->create( array(201 'post_parent' => $f ,586 $t1 = $this->factory->topic->create( array( 587 'post_parent' => $f1, 202 588 ) ); 203 589 204 bbp_update_forum_reply_count( $f ); 590 $t2 = $this->factory->topic->create( array( 591 'post_parent' => $f2, 592 ) ); 205 593 206 $count = bbp_get_forum_reply_count( $f );594 $count = bbp_get_forum_reply_count( $f1 ); 207 595 $this->assertSame( '0', $count ); 208 596 209 $r = $this->factory->reply->create_many( 15, array( 210 'post_parent' => $t, 597 $count = bbp_update_forum_reply_count( $f1 ); 598 $this->assertSame( 0, $count ); 599 600 $this->factory->reply->create_many( 3, array( 601 'post_parent' => $t1, 211 602 ) ); 212 603 213 bbp_update_forum_reply_count( $f ); 604 $count = bbp_update_forum_reply_count( $f1 ); 605 $this->assertSame( 3, $count ); 214 606 215 $count = bbp_get_forum_reply_count( $f ); 216 $this->assertSame( '15', $count ); 607 $this->factory->reply->create_many( 3, array( 608 'post_parent' => $t2, 609 ) ); 610 611 $count = bbp_update_forum_reply_count( $f1 ); 612 $this->assertSame( 6, $count ); 613 614 $count = bbp_update_forum_reply_count( $f2 ); 615 $this->assertSame( 3, $count ); 217 616 } 218 617 } -
tests/phpunit/testcases/forums/functions/query.php
diff --git tests/phpunit/testcases/forums/functions/query.php tests/phpunit/testcases/forums/functions/query.php index 2dca836..f180658 100644
class BBP_Tests_Forums_Functions_Query extends BBP_UnitTestCase { 30 30 'post_parent' => $f, 31 31 ) ); 32 32 33 bbp_update_forum_topic_count( $f ); 33 $count = count( bbp_forum_query_topic_ids( $f ) ); 34 $this->assertSame( 9, $count ); 35 36 $this->factory->topic->create_many( 9, array( 37 'post_parent' => $f, 38 ) ); 34 39 40 // Test that previous value was cached 35 41 $count = count( bbp_forum_query_topic_ids( $f ) ); 36 $this->assertSame( 9, $count );; 42 $this->assertSame( 9, $count ); 43 44 // Test with a fresh count 45 wp_cache_flush(); 46 $count = count( bbp_forum_query_topic_ids( $f, true ) ); 47 $this->assertSame( 18, $count ); 37 48 } 38 49 39 50 /** … … class BBP_Tests_Forums_Functions_Query extends BBP_UnitTestCase { 47 58 ) ); 48 59 49 60 $count = count( bbp_forum_query_subforum_ids( $f1 ) ); 50 $this->assertSame( 9, $count );; 61 $this->assertSame( 9, $count ); 62 63 $f3 = $this->factory->forum->create_many( 9, array( 64 'post_parent' => $f1, 65 ) ); 66 67 // Test that previous value was cached 68 $count = count( bbp_forum_query_subforum_ids( $f1 ) ); 69 $this->assertSame( 9, $count ); 70 71 // Test with a fresh count 72 wp_cache_flush(); 73 $count = count( bbp_forum_query_subforum_ids( $f1, true ) ); 74 $this->assertSame( 18, $count ); 51 75 } 52 76 53 77 /** -
tests/phpunit/testcases/forums/template/counts.php
diff --git tests/phpunit/testcases/forums/template/counts.php tests/phpunit/testcases/forums/template/counts.php index 16a018f..0a35dde 100644
class BBP_Tests_Forums_Template_Counts extends BBP_UnitTestCase { 15 15 */ 16 16 public function test_bbp_get_forum_subforum_count() { 17 17 $f1 = $this->factory->forum->create(); 18 $int_value = 9;18 $int_value = 3; 19 19 $formatted_value = bbp_number_format( $int_value ); 20 20 21 21 $this->factory->forum->create_many( $int_value, array( … … class BBP_Tests_Forums_Template_Counts extends BBP_UnitTestCase { 48 48 */ 49 49 public function test_bbp_get_forum_topic_count() { 50 50 $f = $this->factory->forum->create(); 51 $int_value = 9;51 $int_value = 3; 52 52 $formatted_value = bbp_number_format( $int_value ); 53 53 54 54 $this->factory->topic->create_many( $int_value, array( … … class BBP_Tests_Forums_Template_Counts extends BBP_UnitTestCase { 81 81 'post_parent' => $f 82 82 ) ); 83 83 84 $int_value = 9;84 $int_value = 3; 85 85 $formatted_value = bbp_number_format( $int_value ); 86 86 87 87 $this->factory->reply->create_many( $int_value, array( … … class BBP_Tests_Forums_Template_Counts extends BBP_UnitTestCase { 114 114 'post_parent' => $f 115 115 ) ); 116 116 117 $int_value = 9;117 $int_value = 3; 118 118 119 119 // Topic + Replies 120 $result = 10;120 $result = 4; 121 121 $formatted_result = bbp_number_format( $result ); 122 122 123 123 $this->factory->reply->create_many( $int_value, array( … … class BBP_Tests_Forums_Template_Counts extends BBP_UnitTestCase { 147 147 */ 148 148 public function test_bbp_get_forum_topic_count_hidden() { 149 149 $f = $this->factory->forum->create(); 150 $int_value = 9;150 $int_value = 3; 151 151 $formatted_value = bbp_number_format( $int_value ); 152 152 153 153 $this->factory->topic->create_many( $int_value, array( -
tests/phpunit/testcases/topics/functions/counts.php
diff --git tests/phpunit/testcases/topics/functions/counts.php tests/phpunit/testcases/topics/functions/counts.php index 1ba566c..1363386 100644
10 10 class BBP_Tests_Topics_Functions_Counts extends BBP_UnitTestCase { 11 11 12 12 /** 13 * Generic function to test the counts on a new reply 14 */ 15 public function test_bbp_topic_new_reply_counts() { 16 $f = $this->factory->forum->create(); 17 $t = $this->factory->topic->create( array( 18 'post_parent' => $f, 19 'post_author' => bbp_get_current_user_id(), 20 'topic_meta' => array( 21 'forum_id' => $f, 22 ), 23 ) ); 24 $r1 = $this->factory->reply->create( array( 25 'post_parent' => $t, 26 'post_author' => bbp_get_current_user_id(), 27 'reply_meta' => array( 28 'forum_id' => $f, 29 'topic_id' => $t, 30 ), 31 ) ); 32 $u = $this->factory->user->create(); 33 34 // Cheating here, but we need $_SERVER['SERVER_NAME'] to be set 35 $this->setUp_wp_mail( false ); 36 37 // Simulate the 'bbp_new_reply' action 38 do_action( 'bbp_new_reply', $r1, $t, $f, false, bbp_get_current_user_id() ); 39 40 // Reverse our changes 41 $this->tearDown_wp_mail( false ); 42 43 $count = bbp_get_topic_reply_count( $t, true ); 44 $this->assertSame( 1, $count ); 45 46 $count = bbp_get_topic_reply_count_hidden( $t, true ); 47 $this->assertSame( 0, $count ); 48 49 $count = bbp_get_topic_voice_count( $t, true ); 50 $this->assertSame( 1, $count ); 51 52 $r2 = $this->factory->reply->create( array( 53 'post_parent' => $t, 54 'post_author' => $u, 55 'reply_meta' => array( 56 'forum_id' => $f, 57 'topic_id' => $t, 58 ), 59 ) ); 60 61 bbp_clean_post_cache( $r2 ); 62 63 // Cheating here, but we need $_SERVER['SERVER_NAME'] to be set 64 $this->setUp_wp_mail( false ); 65 66 // Simulate the 'bbp_new_topic' action 67 do_action( 'bbp_new_reply', $r2, $t, $f, false, $u ); 68 69 // Reverse our changes 70 $this->tearDown_wp_mail( false ); 71 72 $count = bbp_get_topic_reply_count( $t, true ); 73 $this->assertSame( 2, $count ); 74 75 $count = bbp_get_topic_reply_count_hidden( $t, true ); 76 $this->assertSame( 0, $count ); 77 78 $count = bbp_get_topic_voice_count( $t, true ); 79 $this->assertSame( 2, $count ); 80 } 81 82 /** 83 * Generic function to test the counts on a deleted reply 84 */ 85 public function test_bbp_topic_deleted_reply_counts() { 86 $f = $this->factory->forum->create(); 87 $t = $this->factory->topic->create( array( 88 'post_parent' => $f, 89 'post_author' => bbp_get_current_user_id(), 90 'topic_meta' => array( 91 'forum_id' => $f, 92 ), 93 ) ); 94 $r1 = $this->factory->reply->create( array( 95 'post_parent' => $t, 96 'post_author' => bbp_get_current_user_id(), 97 'reply_meta' => array( 98 'forum_id' => $f, 99 'topic_id' => $t, 100 ), 101 ) ); 102 $u = $this->factory->user->create(); 103 104 bbp_clean_post_cache( $r1 ); 105 106 $count = bbp_update_topic_reply_count( $t ); 107 $this->assertSame( 1, $count ); 108 109 $count = bbp_update_topic_reply_count_hidden( $t ); 110 $this->assertSame( 0, $count ); 111 112 $count = bbp_update_topic_voice_count( $t ); 113 $this->assertSame( 1, $count ); 114 115 $r2 = $this->factory->reply->create( array( 116 'post_parent' => $t, 117 'post_author' => $u, 118 'reply_meta' => array( 119 'forum_id' => $f, 120 'topic_id' => $t, 121 ), 122 ) ); 123 124 bbp_clean_post_cache( $r2 ); 125 126 $count = bbp_update_topic_reply_count( $t ); 127 $this->assertSame( 2, $count ); 128 129 $count = bbp_update_topic_reply_count_hidden( $t ); 130 $this->assertSame( 0, $count ); 131 132 $count = bbp_update_topic_voice_count( $t ); 133 $this->assertSame( 2, $count ); 134 135 bbp_clean_post_cache( $r2 ); 136 wp_delete_post( $r2, true ); 137 138 $count = bbp_get_topic_reply_count( $t, true ); 139 $this->assertSame( 1, $count ); 140 141 $count = bbp_get_topic_reply_count_hidden( $t, true ); 142 $this->assertSame( 0, $count ); 143 144 $count = bbp_get_topic_voice_count( $t, true ); 145 $this->assertSame( 1, $count ); 146 } 147 148 /** 149 * Generic function to test the counts on a trashed/untrashed topic 150 */ 151 public function test_bbp_topic_trashed_untrashed_reply_counts() { 152 $u = $this->factory->user->create(); 153 $f = $this->factory->forum->create(); 154 $t = $this->factory->topic->create( array( 155 'post_parent' => $f, 156 'topic_meta' => array( 157 'forum_id' => $f, 158 ), 159 ) ); 160 $r = $this->factory->reply->create_many( 2, array( 161 'post_parent' => $t, 162 'reply_meta' => array( 163 'forum_id' => $f, 164 'topic_id' => $t, 165 ), 166 ) ); 167 $r3 = $this->factory->reply->create( array( 168 'post_parent' => $t, 169 'post_author' => $u, 170 'reply_meta' => array( 171 'forum_id' => $f, 172 'topic_id' => $t, 173 ), 174 ) ); 175 176 177 bbp_clean_post_cache( $t ); 178 179 $count = bbp_update_topic_reply_count( $t ); 180 $this->assertSame( 3, $count ); 181 182 $count = bbp_update_topic_reply_count_hidden( $t ); 183 $this->assertSame( 0, $count ); 184 185 $count = bbp_update_topic_voice_count( $t ); 186 $this->assertSame( 2, $count ); 187 188 bbp_clean_post_cache( $r3 ); 189 wp_trash_post( $r3 ); 190 191 $count = bbp_get_topic_reply_count( $t, true ); 192 $this->assertSame( 2, $count ); 193 194 $count = bbp_get_topic_reply_count_hidden( $t, true ); 195 $this->assertSame( 1, $count ); 196 197 $count = bbp_get_topic_voice_count( $t, true ); 198 $this->assertSame( 1, $count ); 199 200 bbp_clean_post_cache( $r3 ); 201 wp_untrash_post( $r3 ); 202 203 $count = bbp_get_topic_reply_count( $t, true ); 204 $this->assertSame( 3, $count ); 205 206 $count = bbp_get_topic_reply_count_hidden( $t, true ); 207 $this->assertSame( 0, $count ); 208 209 $count = bbp_get_topic_voice_count( $t, true ); 210 $this->assertSame( 2, $count ); 211 } 212 213 /** 214 * Generic function to test the counts on a spammed/unspammed topic 215 */ 216 public function test_bbp_topic_spammed_unspammed_reply_counts() { 217 $u = $this->factory->user->create(); 218 $f = $this->factory->forum->create(); 219 $t = $this->factory->topic->create( array( 220 'post_parent' => $f, 221 'topic_meta' => array( 222 'forum_id' => $f, 223 ), 224 ) ); 225 $r = $this->factory->reply->create_many( 2, array( 226 'post_parent' => $t, 227 'reply_meta' => array( 228 'forum_id' => $f, 229 'topic_id' => $t, 230 ), 231 ) ); 232 $r3 = $this->factory->reply->create( array( 233 'post_parent' => $t, 234 'post_author' => $u, 235 'reply_meta' => array( 236 'forum_id' => $f, 237 'topic_id' => $t, 238 ), 239 ) ); 240 241 bbp_clean_post_cache( $t ); 242 243 $count = bbp_update_topic_reply_count( $t ); 244 $this->assertSame( 3, $count ); 245 246 $count = bbp_update_topic_reply_count_hidden( $t ); 247 $this->assertSame( 0, $count ); 248 249 $count = bbp_update_topic_voice_count( $t ); 250 $this->assertSame( 2, $count ); 251 252 bbp_clean_post_cache( $r3 ); 253 bbp_spam_reply( $r3 ); 254 255 $count = bbp_get_topic_reply_count( $t, true ); 256 $this->assertSame( 2, $count ); 257 258 $count = bbp_get_topic_reply_count_hidden( $t, true ); 259 $this->assertSame( 1, $count ); 260 261 $count = bbp_get_topic_voice_count( $t, true ); 262 $this->assertSame( 1, $count ); 263 264 bbp_clean_post_cache( $r3 ); 265 bbp_unspam_reply( $r3 ); 266 267 $count = bbp_get_topic_reply_count( $t, true ); 268 $this->assertSame( 3, $count ); 269 270 $count = bbp_get_topic_reply_count_hidden( $t, true ); 271 $this->assertSame( 0, $count ); 272 273 $count = bbp_get_topic_voice_count( $t, true ); 274 $this->assertSame( 2, $count ); 275 } 276 277 /** 278 * Generic function to test the counts on a approved/unapproved topic 279 */ 280 public function test_bbp_topic_approved_unapproved_reply_counts() { 281 $u = $this->factory->user->create(); 282 $f = $this->factory->forum->create(); 283 $t = $this->factory->topic->create( array( 284 'post_parent' => $f, 285 'topic_meta' => array( 286 'forum_id' => $f, 287 ), 288 ) ); 289 $r = $this->factory->reply->create_many( 2, array( 290 'post_parent' => $t, 291 'reply_meta' => array( 292 'forum_id' => $f, 293 'topic_id' => $t, 294 ), 295 ) ); 296 $r3 = $this->factory->reply->create( array( 297 'post_parent' => $t, 298 'post_author' => $u, 299 'reply_meta' => array( 300 'forum_id' => $f, 301 'topic_id' => $t, 302 ), 303 ) ); 304 305 bbp_clean_post_cache( $t ); 306 307 $count = bbp_update_topic_reply_count( $t ); 308 $this->assertSame( 3, $count ); 309 310 $count = bbp_update_topic_reply_count_hidden( $t ); 311 $this->assertSame( 0, $count ); 312 313 $count = bbp_update_topic_voice_count( $t ); 314 $this->assertSame( 2, $count ); 315 316 bbp_clean_post_cache( $r3 ); 317 bbp_unapprove_reply( $r3 ); 318 319 $count = bbp_get_topic_reply_count( $t, true ); 320 $this->assertSame( 2, $count ); 321 322 $count = bbp_get_topic_reply_count_hidden( $t, true ); 323 $this->assertSame( 1, $count ); 324 325 $count = bbp_get_topic_voice_count( $t, true ); 326 $this->assertSame( 1, $count ); 327 328 bbp_clean_post_cache( $r3 ); 329 bbp_approve_reply( $r3 ); 330 331 $count = bbp_get_topic_reply_count( $t, true ); 332 $this->assertSame( 3, $count ); 333 334 $count = bbp_get_topic_reply_count_hidden( $t, true ); 335 $this->assertSame( 0, $count ); 336 337 $count = bbp_get_topic_voice_count( $t, true ); 338 $this->assertSame( 2, $count ); 339 } 340 341 /** 13 342 * @covers ::bbp_bump_topic_reply_count 14 343 */ 15 344 public function test_bbp_bump_topic_reply_count() { … … class BBP_Tests_Topics_Functions_Counts extends BBP_UnitTestCase { 18 347 $count = bbp_get_topic_reply_count( $t ); 19 348 $this->assertSame( '0', $count ); 20 349 21 bbp_bump_topic_reply_count( $t ); 350 $count = bbp_bump_topic_reply_count( $t ); 351 $this->assertSame( 1, $count ); 22 352 23 $count = bbp_get_topic_reply_count( $t ); 24 $this->assertSame( '1', $count ); 353 $count = bbp_bump_topic_reply_count( $t, 3 ); 354 $this->assertSame( 4, $count ); 355 356 $count = bbp_bump_topic_reply_count( $t, '1' ); 357 $this->assertSame( 5, $count ); 358 359 $count = bbp_get_topic_reply_count( $t, true ); 360 $this->assertSame( 5, $count ); 25 361 } 26 362 27 363 /** … … class BBP_Tests_Topics_Functions_Counts extends BBP_UnitTestCase { 33 369 $count = bbp_get_topic_reply_count_hidden( $t ); 34 370 $this->assertSame( '0', $count ); 35 371 36 bbp_bump_topic_reply_count_hidden( $t ); 372 $count = bbp_bump_topic_reply_count_hidden( $t ); 373 $this->assertSame( 1, $count ); 37 374 38 $count = bbp_get_topic_reply_count_hidden( $t ); 39 $this->assertSame( '1', $count ); 375 $count = bbp_bump_topic_reply_count_hidden( $t, 3 ); 376 $this->assertSame( 4, $count ); 377 378 $count = bbp_bump_topic_reply_count_hidden( $t, '1' ); 379 $this->assertSame( 5, $count ); 380 381 $count = bbp_get_topic_reply_count_hidden( $t, true ); 382 $this->assertSame( 5, $count ); 40 383 } 41 384 42 385 /** … … class BBP_Tests_Topics_Functions_Counts extends BBP_UnitTestCase { 66 409 ) 67 410 ) ); 68 411 69 // @todo Investigate caching issues in bbp_get_public_child_count() 70 wp_cache_flush(); 71 72 bbp_update_topic_reply_count( $t ); 73 74 // @todo Investigate caching issues in bbp_get_public_child_count() 75 wp_cache_flush(); 76 77 $count = bbp_get_topic_reply_count( $t ); 78 $this->assertSame( '3', $count ); 412 bbp_clean_post_cache( $t ); 413 $count = bbp_update_topic_reply_count( $t ); 414 $this->assertSame( 3, $count ); 79 415 80 416 // Create another reply 81 417 $r2 = $this->factory->reply->create( array( … … class BBP_Tests_Topics_Functions_Counts extends BBP_UnitTestCase { 87 423 ) ); 88 424 89 425 // Test update using reply id 90 bbp_update_topic_reply_count( $r2 ); 426 bbp_clean_post_cache( $t ); 427 $count = bbp_update_topic_reply_count( $r2 ); 428 $this->assertSame( 4, $count ); 429 430 bbp_spam_reply( $r2 ); 431 432 bbp_clean_post_cache( $r2 ); 433 $count = bbp_update_topic_reply_count( $t ); 434 $this->assertSame( 3, $count ); 91 435 92 436 $count = bbp_get_topic_reply_count( $t ); 93 $this->assertSame( ' 4', $count );437 $this->assertSame( '3', $count ); 94 438 } 95 439 96 440 /** 97 441 * @covers ::bbp_update_topic_reply_count_hidden 98 442 */ 99 443 public function test_bbp_update_topic_reply_count_hidden() { 100 $t = $this->factory->topic->create(); 444 $f = $this->factory->forum->create(); 445 $t = $this->factory->topic->create( array( 446 'post_parent' => $f, 447 ) ); 101 448 102 449 $count = bbp_get_topic_reply_count_hidden( $t ); 103 450 $this->assertSame( '0', $count ); 104 451 105 $r = $this->factory->reply->create_many( 15, array(452 $r = $this->factory->reply->create_many( 3, array( 106 453 'post_parent' => $t, 107 454 ) ); 108 455 109 bbp_update_topic_reply_count_hidden( $t ); 456 $count = bbp_update_topic_reply_count_hidden( $t ); 457 $this->assertSame( 0, $count ); 110 458 111 $count = bbp_get_topic_reply_count_hidden( $t ); 112 $this->assertSame( '0', $count ); 113 114 bbp_spam_reply( $r[11] ); 115 116 bbp_update_topic_reply_count_hidden( $t ); 117 118 $count = bbp_get_topic_reply_count_hidden( $t ); 119 $this->assertSame( '1', $count ); 459 bbp_spam_reply( $r[2] ); 120 460 121 bbp_unapprove_reply( $r[7] ); 461 $count = bbp_update_topic_reply_count_hidden( $t ); 462 $this->assertSame( 1, $count ); 122 463 123 bbp_u pdate_topic_reply_count_hidden( $t);464 bbp_unapprove_reply( $r[0] ); 124 465 125 $count = bbp_ get_topic_reply_count_hidden( $t );126 $this->assertSame( '2', $count );466 $count = bbp_update_topic_reply_count_hidden( $t ); 467 $this->assertSame( 2, $count ); 127 468 } 128 469 129 470 /** … … class BBP_Tests_Topics_Functions_Counts extends BBP_UnitTestCase { 141 482 'post_parent' => $t, 142 483 ) ); 143 484 144 bbp_update_topic_voice_count( $t ); 145 146 $count = bbp_get_topic_voice_count( $t ); 147 $this->assertSame( '2', $count ); 485 $count = bbp_update_topic_voice_count( $t ); 486 $this->assertSame( 2, $count ); 148 487 149 488 $r = $this->factory->reply->create( array( 150 489 'post_author' => $u[1], 151 490 'post_parent' => $t, 152 491 ) ); 153 492 154 bbp_update_topic_voice_count( $t ); 155 156 $count = bbp_get_topic_voice_count( $t ); 157 $this->assertSame( '3', $count ); 493 $count = bbp_update_topic_voice_count( $t ); 494 $this->assertSame( 3, $count ); 158 495 } 159 496 160 497 /** -
tests/phpunit/testcases/topics/template/counts.php
diff --git tests/phpunit/testcases/topics/template/counts.php tests/phpunit/testcases/topics/template/counts.php index 05063ef..c0212b7 100644
class BBP_Tests_Topics_Template_Counts extends BBP_UnitTestCase { 22 22 ) 23 23 ) ); 24 24 25 $int_value = 9;25 $int_value = 3; 26 26 $formatted_value = bbp_number_format( $int_value ); 27 27 28 28 $this->factory->reply->create_many( $int_value, array( … … class BBP_Tests_Topics_Template_Counts extends BBP_UnitTestCase { 33 33 ) 34 34 ) ); 35 35 36 // @todo Investigate caching issues in bbp_get_public_child_count() 37 wp_cache_flush(); 38 36 bbp_clean_post_cache( $t ); 39 37 bbp_update_topic_reply_count( $t ); 40 38 41 39 // Output … … class BBP_Tests_Topics_Template_Counts extends BBP_UnitTestCase { 59 57 $f = $this->factory->forum->create(); 60 58 61 59 $int_topics = 1; 62 $int_replies = 9;60 $int_replies = 3; 63 61 $int_value = $int_topics + $int_replies; 64 62 $formatted_value = bbp_number_format( $int_value ); 65 63 … … class BBP_Tests_Topics_Template_Counts extends BBP_UnitTestCase { 78 76 ) 79 77 ) ); 80 78 81 // @todo Investigate caching issues in bbp_get_public_child_count() 82 wp_cache_flush(); 83 79 bbp_clean_post_cache( $t ); 84 80 bbp_update_topic_reply_count( $t ); 85 81 86 82 // Output … … class BBP_Tests_Topics_Template_Counts extends BBP_UnitTestCase { 103 99 public function test_bbp_get_topic_reply_count_hidden() { 104 100 $f = $this->factory->forum->create(); 105 101 106 $int_value = 9;102 $int_value = 3; 107 103 $formatted_value = bbp_number_format( $int_value ); 108 104 109 105 $t = $this->factory->topic->create( array( … … class BBP_Tests_Topics_Template_Counts extends BBP_UnitTestCase { 124 120 125 121 bbp_update_topic_reply_count_hidden( $t ); 126 122 127 bbp_spam_reply( $r[ 7] );123 bbp_spam_reply( $r[1] ); 128 124 129 125 // Output 130 126 $this->expectOutputString( $formatted_value ); -
tests/phpunit/testcases/users/functions/counts.php
diff --git tests/phpunit/testcases/users/functions/counts.php tests/phpunit/testcases/users/functions/counts.php index b8a7123..488554c 100644
class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 14 14 */ 15 15 function test_bbp_update_user_topic_count() { 16 16 $u = $this->factory->user->create(); 17 $int_value = 9;17 $int_value = 3; 18 18 19 19 bbp_update_user_topic_count( $u, $int_value ); 20 20 … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 27 27 */ 28 28 function test_bbp_update_user_reply_count() { 29 29 $u = $this->factory->user->create(); 30 $int_value = 9;30 $int_value = 3; 31 31 32 32 bbp_update_user_reply_count( $u, $int_value ); 33 33 … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 41 41 */ 42 42 function test_bbp_get_user_topic_count() { 43 43 $u = $this->factory->user->create(); 44 $int_value = 9;44 $int_value = 3; 45 45 $formatted_value = bbp_number_format( $int_value ); 46 46 47 47 bbp_update_user_topic_count( $u, $int_value ); … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 62 62 */ 63 63 function test_bbp_get_user_reply_count() { 64 64 $u = $this->factory->user->create(); 65 $int_value = 9;65 $int_value = 3; 66 66 $formatted_value = bbp_number_format( $int_value ); 67 67 68 68 bbp_update_user_reply_count( $u, $int_value ); … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 83 83 */ 84 84 function test_bbp_get_user_post_count() { 85 85 $u = $this->factory->user->create(); 86 $int_value = 9;86 $int_value = 3; 87 87 $integer = true; 88 88 89 89 // Add reply count … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 116 116 $has_topics = bbp_get_user_topics_started( $u ); 117 117 $this->assertFalse( $has_topics ); 118 118 119 $t = $this->factory->topic->create_many( 15, array(119 $t = $this->factory->topic->create_many( 3, array( 120 120 'post_author' => $u, 121 121 ) ); 122 122 … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 137 137 $has_replies = bbp_get_user_replies_created( $u ); 138 138 $this->assertFalse( $has_replies ); 139 139 140 $r = $this->factory->reply->create_many( 15, array(140 $r = $this->factory->reply->create_many( 3, array( 141 141 'post_author' => $u, 142 142 ) ); 143 143 … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 153 153 * @covers ::bbp_get_total_users 154 154 */ 155 155 public function test_bbp_get_total_users() { 156 $this->factory->user->create_many( 15);156 $this->factory->user->create_many( 3 ); 157 157 158 158 $users = (int) bbp_get_total_users(); 159 159 160 160 // 15 + 1, the + 1 is the default admin user 161 $this->assertSame( 16, $users );161 $this->assertSame( 4, $users ); 162 162 } 163 163 164 164 /** … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 167 167 public function test_bbp_get_user_topic_count_raw() { 168 168 $u = $this->factory->user->create(); 169 169 170 $t = $this->factory->topic->create_many( 15, array(170 $t = $this->factory->topic->create_many( 3, array( 171 171 'post_author' => $u, 172 172 ) ); 173 173 174 174 $count = bbp_get_user_topic_count_raw( $u ); 175 $this->assertSame( 15, $count );175 $this->assertSame( 3, $count ); 176 176 177 $t = $this->factory->topic->create_many( 15, array(177 $t = $this->factory->topic->create_many( 3, array( 178 178 'post_author' => $u, 179 179 ) ); 180 180 181 181 $count = bbp_get_user_topic_count_raw( $u ); 182 $this->assertSame( 30, $count );182 $this->assertSame( 6, $count ); 183 183 } 184 184 185 185 /** … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 188 188 public function test_bbp_get_user_reply_count_raw() { 189 189 $u = $this->factory->user->create(); 190 190 191 $r = $this->factory->reply->create_many( 15, array(191 $r = $this->factory->reply->create_many( 3, array( 192 192 'post_author' => $u, 193 193 ) ); 194 194 195 195 $count = bbp_get_user_reply_count_raw( $u ); 196 $this->assertSame( 15, $count );196 $this->assertSame( 3, $count ); 197 197 198 $r = $this->factory->reply->create_many( 15, array(198 $r = $this->factory->reply->create_many( 3, array( 199 199 'post_author' => $u, 200 200 ) ); 201 201 202 202 $count = bbp_get_user_reply_count_raw( $u ); 203 $this->assertSame( 30, $count );203 $this->assertSame( 6, $count ); 204 204 } 205 205 206 206 /** … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 208 208 */ 209 209 public function test_bbp_bump_user_topic_count() { 210 210 $u = $this->factory->user->create(); 211 $int_value = 9;211 $int_value = 3; 212 212 $integer = true; 213 213 214 214 bbp_update_user_topic_count( $u, $int_value ); … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 227 227 */ 228 228 public function test_bbp_bump_user_reply_count() { 229 229 $u = $this->factory->user->create(); 230 $int_value = 9;230 $int_value = 3; 231 231 $integer = true; 232 232 233 233 bbp_update_user_reply_count( $u, $int_value ); … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 246 246 */ 247 247 public function test_bbp_increase_user_topic_count() { 248 248 $u = $this->factory->user->create(); 249 $int_value = 9;249 $int_value = 3; 250 250 $integer = true; 251 251 252 252 bbp_update_user_topic_count( $u, $int_value ); … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 269 269 */ 270 270 public function test_bbp_increase_user_reply_count() { 271 271 $u = $this->factory->user->create(); 272 $int_value = 9;272 $int_value = 3; 273 273 $integer = true; 274 274 275 275 bbp_update_user_reply_count( $u, $int_value ); … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 294 294 */ 295 295 public function test_bbp_decrease_user_topic_count() { 296 296 $u = $this->factory->user->create(); 297 $int_value = 9;297 $int_value = 3; 298 298 $integer = true; 299 299 300 300 bbp_bump_user_topic_count( $u, $int_value ); … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 325 325 public function test_bbp_decrease_user_reply_count() { 326 326 $u = $this->factory->user->create(); 327 327 328 bbp_bump_user_reply_count( $u, 15);328 bbp_bump_user_reply_count( $u, 3 ); 329 329 330 330 $count = bbp_get_user_reply_count( $u, true ); 331 $this->assertSame( 15, $count );331 $this->assertSame( 3, $count ); 332 332 333 333 $r = $this->factory->reply->create( array( 334 334 'post_author' => $u, … … class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 337 337 bbp_decrease_user_reply_count( $r ); 338 338 339 339 $count = bbp_get_user_reply_count( $u ); 340 $this->assertSame( ' 14', $count );340 $this->assertSame( '2', $count ); 341 341 342 342 bbp_decrease_user_reply_count( $r ); 343 343 344 344 $count = bbp_get_user_reply_count( $u, true ); 345 $this->assertSame( 1 3, $count );345 $this->assertSame( 1, $count ); 346 346 } 347 347 }