[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @group blogs 5 */ 6 class BP_Tests_Blogs_Template extends BP_UnitTestCase { 7 /** 8 * @group bp_get_blog_last_active 9 */ 10 public function test_bp_get_blog_last_active_default_params() { 11 // Fake the global 12 global $blogs_template; 13 14 $time = date( 'Y-m-d h:i:s', time() - 24 * 60 * 60 ); 15 $blogs_template = new stdClass; 16 $blogs_template->blog = new stdClass; 17 $blogs_template->blog->last_activity = $time; 18 19 $this->assertEquals( bp_core_get_last_activity( $time, __( 'active %s', 'buddypress' ) ), bp_get_blog_last_active() ); 20 21 $blogs_template->blog = null; 22 } 23 24 /** 25 * @group bp_get_blog_last_active 26 */ 27 public function test_bp_get_blog_last_active_active_format_true() { 28 // Fake the global 29 global $blogs_template; 30 31 $time = date( 'Y-m-d h:i:s', time() - 24 * 60 * 60 ); 32 $blogs_template = new stdClass; 33 $blogs_template->blog = new stdClass; 34 $blogs_template->blog->last_activity = $time; 35 36 $this->assertEquals( bp_core_get_last_activity( $time, __( 'active %s', 'buddypress' ) ), bp_get_blog_last_active( array( 'active_format' => true, ) ) ); 37 38 $blogs_template->blog = null; 39 } 40 41 /** 42 * @group bp_get_blog_last_active 43 */ 44 public function test_bp_get_blog_last_active_active_format_false() { 45 // Fake the global 46 global $blogs_template; 47 48 $time = date( 'Y-m-d h:i:s', time() - 24 * 60 * 60 ); 49 $blogs_template = new stdClass; 50 $blogs_template->blog = new stdClass; 51 $blogs_template->blog->last_activity = $time; 52 53 $this->assertEquals( bp_core_time_since( $time ), bp_get_blog_last_active( array( 'active_format' => false, ) ) ); 54 55 $blogs_template->blog = null; 56 } 57 58 /** 59 * @group bp_get_blog_last_active 60 */ 61 public function test_bp_get_blog_last_active_active_no_last_activity() { 62 $this->assertEquals( __( 'Never active', 'buddypress' ), bp_get_blog_last_active() ); 63 } 64 65 /** 66 * @group bp_get_blog_latest_post 67 */ 68 public function test_bp_get_blog_latest_post_default_params() { 69 // Fake the global 70 global $blogs_template; 71 72 $blogs_template = new stdClass; 73 $blogs_template->blog = new stdClass; 74 $blogs_template->blog->latest_post = new stdClass; 75 $blogs_template->blog->latest_post->guid = 'foo'; 76 $blogs_template->blog->latest_post->post_title = 'bar'; 77 78 $this->assertSame( sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="foo">bar</a>' ), bp_get_blog_latest_post() ); 79 80 $blogs_template->blog = null; 81 } 82 83 /** 84 * @group bp_get_blog_latest_post 85 */ 86 public function test_bp_get_blog_latest_post_latest_format_true() { 87 // Fake the global 88 global $blogs_template; 89 90 $blogs_template = new stdClass; 91 $blogs_template->blog = new stdClass; 92 $blogs_template->blog->latest_post = new stdClass; 93 $blogs_template->blog->latest_post->guid = 'foo'; 94 $blogs_template->blog->latest_post->post_title = 'bar'; 95 96 $this->assertSame( sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="foo">bar</a>' ), bp_get_blog_latest_post( array( 'latest_format' => true, ) ) ); 97 98 $blogs_template->blog = null; 99 } 100 101 /** 102 * @group bp_get_blog_latest_post 103 */ 104 public function test_bp_get_blog_latest_post_latest_format_false() { 105 // Fake the global 106 global $blogs_template; 107 108 $blogs_template = new stdClass; 109 $blogs_template->blog = new stdClass; 110 $blogs_template->blog->latest_post = new stdClass; 111 $blogs_template->blog->latest_post->guid = 'foo'; 112 $blogs_template->blog->latest_post->post_title = 'bar'; 113 114 $this->assertSame( '<a href="foo">bar</a>', bp_get_blog_latest_post( array( 'latest_format' => false, ) ) ); 115 116 $blogs_template->blog = null; 117 } 118 119 /** 120 * @group bp_blog_signup_enabled 121 */ 122 public function test_bp_signup_enabled_when_registration_setting_does_not_exist_should_default_to_true() { 123 $old_settings = $settings = buddypress()->site_options; 124 if ( is_array( $settings ) && isset( $settings['registration'] ) ) { 125 unset( $settings['registration'] ); 126 } 127 buddypress()->site_options = $settings; 128 129 $this->assertTrue( bp_blog_signup_enabled() ); 130 131 buddypress()->site_options = $old_settings; 132 } 133 134 /** 135 * @group bp_blog_signup_enabled 136 */ 137 public function test_bp_signup_enabled_when_registration_setting_is_all_should_return_true() { 138 $old_settings = $settings = buddypress()->site_options; 139 140 if ( ! is_array( $settings ) ) { 141 $settings = array(); 142 } 143 144 $settings['registration'] = 'all'; 145 buddypress()->site_options = $settings; 146 147 $this->assertTrue( bp_blog_signup_enabled() ); 148 149 buddypress()->site_options = $old_settings; 150 } 151 152 /** 153 * @group bp_blog_signup_enabled 154 */ 155 public function test_bp_signup_enabled_when_registration_setting_is_blog_should_return_true() { 156 $old_settings = $settings = buddypress()->site_options; 157 158 if ( ! is_array( $settings ) ) { 159 $settings = array(); 160 } 161 162 $settings['registration'] = 'blog'; 163 buddypress()->site_options = $settings; 164 165 $this->assertTrue( bp_blog_signup_enabled() ); 166 167 buddypress()->site_options = $old_settings; 168 } 169 170 /** 171 * @group bp_blog_signup_enabled 172 */ 173 public function test_bp_signup_enabled_when_registration_setting_is_user_should_return_false() { 174 $old_settings = $settings = buddypress()->site_options; 175 176 if ( ! is_array( $settings ) ) { 177 $settings = array(); 178 } 179 180 $settings['registration'] = 'user'; 181 buddypress()->site_options = $settings; 182 183 $this->assertFalse( bp_blog_signup_enabled() ); 184 185 buddypress()->site_options = $old_settings; 186 } 187 188 /** 189 * @group bp_blog_signup_enabled 190 */ 191 public function test_bp_signup_enabled_when_registration_setting_is_none_should_return_false() { 192 $old_settings = $settings = buddypress()->site_options; 193 194 if ( ! is_array( $settings ) ) { 195 $settings = array(); 196 } 197 198 $settings['registration'] = 'none'; 199 buddypress()->site_options = $settings; 200 201 $this->assertFalse( bp_blog_signup_enabled() ); 202 203 buddypress()->site_options = $old_settings; 204 } 205 206 /** 207 * @group pagination 208 * @group BP_Blogs_Template 209 */ 210 public function test_bp_blogs_template_should_give_precedence_to_bpage_URL_param() { 211 if ( ! is_multisite() ) { 212 $this->markTestSkipped(); 213 } 214 215 $request = $_REQUEST; 216 $_REQUEST['bpage'] = '5'; 217 218 $r = array( 219 'type' => 'active', 220 'page_arg' => 'bpage', 221 'page' => 8, 222 'per_page' => 20, 223 'max' => false, 224 'user_id' => 0, 225 'include_blog_ids' => false, 226 'search_terms' => '', 227 'update_meta_cache' => true 228 ); 229 230 $at = new BP_Blogs_Template( 231 $r['type'], 232 $r['page'], 233 $r['per_page'], 234 $r['max'], 235 $r['user_id'], 236 $r['search_terms'], 237 $r['page_arg'], 238 $r['update_meta_cache'], 239 $r['include_blog_ids'] 240 ); 241 242 $this->assertEquals( 5, $at->pag_page ); 243 244 $_REQUEST = $request; 245 } 246 247 /** 248 * @group pagination 249 * @group BP_Blogs_Template 250 */ 251 public function test_bp_blogs_template_should_reset_0_pag_page_URL_param_to_default_pag_page_value() { 252 if ( ! is_multisite() ) { 253 $this->markTestSkipped(); 254 } 255 256 $request = $_REQUEST; 257 $_REQUEST['bpage'] = '0'; 258 259 $r = array( 260 'type' => 'active', 261 'page_arg' => 'bpage', 262 'page' => 8, 263 'per_page' => 20, 264 'max' => false, 265 'user_id' => 0, 266 'include_blog_ids' => false, 267 'search_terms' => '', 268 'update_meta_cache' => true 269 ); 270 271 $at = new BP_Blogs_Template( 272 $r['type'], 273 $r['page'], 274 $r['per_page'], 275 $r['max'], 276 $r['user_id'], 277 $r['search_terms'], 278 $r['page_arg'], 279 $r['update_meta_cache'], 280 $r['include_blog_ids'] 281 ); 282 283 $this->assertEquals( 8, $at->pag_page ); 284 285 $_REQUEST = $request; 286 } 287 288 /** 289 * @group pagination 290 * @group BP_Blogs_Template 291 */ 292 public function test_bp_blogs_template_should_give_precedence_to_num_URL_param() { 293 if ( ! is_multisite() ) { 294 $this->markTestSkipped(); 295 } 296 297 $request = $_REQUEST; 298 $_REQUEST['num'] = '14'; 299 300 $r = array( 301 'type' => 'active', 302 'page_arg' => 'bpage', 303 'page' => 1, 304 'per_page' => 13, 305 'max' => false, 306 'user_id' => 0, 307 'include_blog_ids' => false, 308 'search_terms' => '', 309 'update_meta_cache' => true 310 ); 311 312 $at = new BP_Blogs_Template( 313 $r['type'], 314 $r['page'], 315 $r['per_page'], 316 $r['max'], 317 $r['user_id'], 318 $r['search_terms'], 319 $r['page_arg'], 320 $r['update_meta_cache'], 321 $r['include_blog_ids'] 322 ); 323 324 $this->assertEquals( 14, $at->pag_num ); 325 326 $_REQUEST = $request; 327 } 328 329 /** 330 * @group pagination 331 * @group BP_Blogs_Template 332 */ 333 public function test_bp_blogs_template_should_reset_0_pag_num_URL_param_to_default_pag_num_value() { 334 if ( ! is_multisite() ) { 335 $this->markTestSkipped(); 336 } 337 338 $request = $_REQUEST; 339 $_REQUEST['num'] = '0'; 340 341 $r = array( 342 'type' => 'active', 343 'page_arg' => 'bpage', 344 'page' => 1, 345 'per_page' => 13, 346 'max' => false, 347 'user_id' => 0, 348 'include_blog_ids' => false, 349 'search_terms' => '', 350 'update_meta_cache' => true 351 ); 352 353 $at = new BP_Blogs_Template( 354 $r['type'], 355 $r['page'], 356 $r['per_page'], 357 $r['max'], 358 $r['user_id'], 359 $r['search_terms'], 360 $r['page_arg'], 361 $r['update_meta_cache'], 362 $r['include_blog_ids'] 363 ); 364 365 $this->assertEquals( 13, $at->pag_num ); 366 367 $_REQUEST = $request; 368 } 369 370 /** 371 * @group avatar 372 * @group BP_Blogs_Template 373 * @group bp_get_blog_avatar 374 */ 375 public function test_bp_get_blog_avatar_ids_provided() { 376 if ( ! is_multisite() ) { 377 $this->markTestSkipped(); 378 } 379 380 if ( function_exists( 'wp_initialize_site' ) ) { 381 $this->setExpectedDeprecated( 'wpmu_new_blog' ); 382 } 383 384 global $blogs_template; 385 $reset_blogs_template = $blogs_template; 386 $blogs_template = null; 387 388 $u = self::factory()->user->create(); 389 $b = self::factory()->blog->create( array( 390 'title' => 'The Foo Bar Blog', 391 'user_id' => $u, 392 ) ); 393 394 $avatar = bp_get_blog_avatar( array( 395 'type' => 'full', 396 'admin_user_id' => $u, 397 'blog_id' => $b, 398 'alt' => 'test', 399 'no_grav' => true, 400 'class' => 'avatar', 401 ) ); 402 403 $blogs_template = $reset_blogs_template; 404 405 $this->assertTrue( $avatar === bp_core_fetch_avatar( array( 406 'type' => 'full', 407 'item_id' => $u, 408 'alt' => 'test', 409 'no_grav' => true, 410 'class' => 'avatar', 411 ) ) ); 412 } 413 414 /** 415 * @group avatar 416 * @group BP_Blogs_Template 417 * @group bp_get_blog_avatar 418 */ 419 public function test_bp_get_blog_avatar_has_site_icon() { 420 if ( ! is_multisite() ) { 421 $this->markTestSkipped(); 422 } 423 424 if ( function_exists( 'wp_initialize_site' ) ) { 425 $this->setExpectedDeprecated( 'wpmu_new_blog' ); 426 } 427 428 global $blogs_template; 429 $reset_blogs_template = $blogs_template; 430 $blogs_template = null; 431 432 $u = self::factory()->user->create(); 433 $b = self::factory()->blog->create( array( 434 'title' => 'The Bar Foo Blog', 435 'user_id' => $u, 436 ) ); 437 438 add_filter( 'get_site_icon_url', array( $this, 'filter_blog_avatar' ) ); 439 440 $avatar = bp_get_blog_avatar( array( 441 'type' => 'full', 442 'admin_user_id' => $u, 443 'blog_id' => $b, 444 'alt' => 'test', 445 'no_grav' => true, 446 'class' => 'avatar', 447 ) ); 448 449 remove_filter( 'get_site_icon_url', array( $this, 'filter_blog_avatar' ) ); 450 $blogs_template = $reset_blogs_template; 451 452 $this->assertTrue( false !== strpos( $avatar, BP_TESTS_DIR . 'assets/upside-down.jpg' ) ); 453 } 454 455 public function filter_blog_avatar() { 456 return BP_TESTS_DIR . 'assets/upside-down.jpg'; 457 } 458 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Dec 5 01:01:36 2019 | Cross-referenced by PHPXref 0.7.1 |