[ Index ] |
PHP Cross Reference of BBPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Tests for the topic component count template functions. 5 * 6 * @group topics 7 * @group template 8 * @group counts 9 */ 10 class BBP_Tests_Topics_Template_Counts extends BBP_UnitTestCase { 11 12 /** 13 * @covers ::bbp_topic_reply_count 14 * @covers ::bbp_get_topic_reply_count 15 */ 16 public function test_bbp_get_topic_reply_count() { 17 $f = $this->factory->forum->create(); 18 $t = $this->factory->topic->create( array( 19 'post_parent' => $f, 20 'topic_meta' => array( 21 'forum_id' => $f, 22 ) 23 ) ); 24 25 $int_value = 3; 26 $formatted_value = bbp_number_format( $int_value ); 27 28 $this->factory->reply->create_many( $int_value, array( 29 'post_parent' => $t, 30 'reply_meta' => array( 31 'forum_id' => $f, 32 'topic_id' => $t, 33 ) 34 ) ); 35 36 bbp_update_topic_reply_count( $t ); 37 38 // Output 39 $this->expectOutputString( $formatted_value ); 40 bbp_topic_reply_count( $t ); 41 42 // Formatted string 43 $count = bbp_get_topic_reply_count( $t, false ); 44 $this->assertSame( $formatted_value, $count ); 45 46 // Integer 47 $count = bbp_get_topic_reply_count( $t, true ); 48 $this->assertSame( $int_value, $count ); 49 } 50 51 /** 52 * @covers ::bbp_topic_post_count 53 * @covers ::bbp_get_topic_post_count 54 */ 55 public function test_bbp_get_topic_post_count() { 56 $f = $this->factory->forum->create(); 57 58 $int_topics = 1; 59 $int_replies = 3; 60 $int_value = $int_topics + $int_replies; 61 $formatted_value = bbp_number_format( $int_value ); 62 63 $t = $this->factory->topic->create( array( 64 'post_parent' => $f, 65 'topic_meta' => array( 66 'forum_id' => $f, 67 ) 68 ) ); 69 70 $this->factory->reply->create_many( $int_replies, array( 71 'post_parent' => $t, 72 'reply_meta' => array( 73 'forum_id' => $f, 74 'topic_id' => $t, 75 ) 76 ) ); 77 78 bbp_update_topic_reply_count( $t ); 79 80 // Output 81 $this->expectOutputString( $formatted_value ); 82 bbp_topic_post_count( $t ); 83 84 // Formatted string 85 $count = bbp_get_topic_post_count( $t, false ); 86 $this->assertSame( $formatted_value, $count ); 87 88 // Integer 89 $count = bbp_get_topic_post_count( $t, true ); 90 $this->assertSame( $int_value, $count ); 91 } 92 93 /** 94 * @covers ::bbp_topic_reply_count_hidden 95 * @covers ::bbp_get_topic_reply_count_hidden 96 */ 97 public function test_bbp_get_topic_reply_count_hidden() { 98 $f = $this->factory->forum->create(); 99 100 $int_value = 3; 101 $formatted_value = bbp_number_format( $int_value ); 102 103 $t = $this->factory->topic->create( array( 104 'post_parent' => $f, 105 'topic_meta' => array( 106 'forum_id' => $f, 107 ) 108 ) ); 109 110 $r = $this->factory->reply->create_many( $int_value, array( 111 'post_parent' => $t, 112 'post_status' => bbp_get_spam_status_id(), 113 'reply_meta' => array( 114 'forum_id' => $f, 115 'topic_id' => $t, 116 ) 117 ) ); 118 119 bbp_update_topic_reply_count_hidden( $t ); 120 121 bbp_spam_reply( $r[1] ); 122 123 // Output 124 $this->expectOutputString( $formatted_value ); 125 bbp_topic_reply_count_hidden( $t ); 126 127 // Formatted string 128 $count = bbp_get_topic_reply_count_hidden( $t, false ); 129 $this->assertSame( $formatted_value, $count ); 130 131 // Integer 132 $count = bbp_get_topic_reply_count_hidden( $t, true ); 133 $this->assertSame( $int_value, $count ); 134 } 135 136 /** 137 * @covers ::bbp_topic_voice_count 138 * @covers ::bbp_get_topic_voice_count 139 */ 140 public function test_bbp_get_topic_voice_count() { 141 $u = $this->factory->user->create_many( 2 ); 142 $f = $this->factory->forum->create(); 143 $t = $this->factory->topic->create( array( 144 'post_parent' => $f, 145 'post_author' => $u[0], 146 'topic_meta' => array( 147 'forum_id' => $f, 148 ) 149 ) ); 150 151 $int_value = 2; 152 $formatted_value = bbp_number_format( $int_value ); 153 154 $this->factory->reply->create_many( 3, array( 155 'post_parent' => $t, 156 'post_author' => $u[0], 157 'reply_meta' => array( 158 'forum_id' => $f, 159 'topic_id' => $t, 160 ) 161 ) ); 162 163 $this->factory->reply->create_many( 3, array( 164 'post_parent' => $t, 165 'post_author' => $u[1], 166 'reply_meta' => array( 167 'forum_id' => $f, 168 'topic_id' => $t, 169 ) 170 ) ); 171 172 bbp_update_topic_voice_count( $t ); 173 174 // Output 175 $this->expectOutputString( $formatted_value ); 176 bbp_topic_voice_count( $t ); 177 178 // Formatted string 179 $count = bbp_get_topic_voice_count( $t, false ); 180 $this->assertSame( $formatted_value, $count ); 181 182 // Integer 183 $count = bbp_get_topic_voice_count( $t, true ); 184 $this->assertSame( $int_value, $count ); 185 } 186 187 /** 188 * @covers ::bbp_topic_voice_count 189 * @covers ::bbp_get_topic_voice_count 190 */ 191 public function test_bbp_get_topic_voice_count_with_pending_reply() { 192 $u = $this->factory->user->create_many( 2 ); 193 $f = $this->factory->forum->create(); 194 $t = $this->factory->topic->create( array( 195 'post_parent' => $f, 196 'post_parent' => $u[0], 197 'topic_meta' => array( 198 'forum_id' => $f, 199 ) 200 ) ); 201 202 $this->factory->reply->create( array( 203 'post_parent' => $t, 204 'post_author' => $u[0], 205 'reply_meta' => array( 206 'forum_id' => $f, 207 'topic_id' => $t, 208 ) 209 ) ); 210 211 $count = bbp_update_topic_voice_count( $t ); 212 $this->assertSame( 1, $count ); 213 214 $r2 = $this->factory->reply->create( array( 215 'post_parent' => $t, 216 'post_author' => $u[1], 217 'post_status' => bbp_get_pending_status_id(), 218 'reply_meta' => array( 219 'forum_id' => $f, 220 'topic_id' => $t, 221 ) 222 ) ); 223 224 $count = bbp_update_topic_voice_count( $t ); 225 $this->assertSame( 1, $count ); 226 227 bbp_approve_reply( $r2 ); 228 229 $count = bbp_update_topic_voice_count( $t ); 230 $this->assertSame( 2, $count ); 231 } 232 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sat Dec 21 01:00:52 2024 | Cross-referenced by PHPXref 0.7.1 |