[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @group core 5 */ 6 7 class BP_Tests_Core_Functions extends BP_UnitTestCase { 8 /** 9 * @group bp_esc_sql_order 10 */ 11 public function test_bp_esc_sql_order_ASC() { 12 $this->assertEquals( 'ASC', bp_esc_sql_order( 'ASC' ) ); 13 } 14 15 /** 16 * @group bp_esc_sql_order 17 */ 18 public function test_bp_esc_sql_order_DESC() { 19 $this->assertEquals( 'DESC', bp_esc_sql_order( 'DESC' ) ); 20 } 21 22 /** 23 * @group bp_esc_sql_order 24 */ 25 public function test_bp_esc_sql_order_desc_lowercase() { 26 $this->assertEquals( 'DESC', bp_esc_sql_order( 'desc' ) ); 27 } 28 29 /** 30 * @group bp_esc_sql_order 31 */ 32 public function test_bp_esc_sql_order_desc_whitespace() { 33 $this->assertEquals( 'DESC', bp_esc_sql_order( ' desc ' ) ); 34 } 35 36 /** 37 * @group bp_esc_sql_order 38 */ 39 public function test_bp_esc_sql_order_invalid() { 40 $this->assertEquals( 'ASC', bp_esc_sql_order( 'In ur base killin ur d00dz' ) ); 41 } 42 43 /** 44 * @group bp_core_time_since 45 */ 46 public function test_bp_core_time_since_years_months() { 47 $now = time(); 48 $then = $now - ( 3 * YEAR_IN_SECONDS ) - ( 3 * 30 * DAY_IN_SECONDS ); 49 $this->assertEquals( '3 years, 3 months ago', bp_core_time_since( $then, $now ) ); 50 } 51 52 /** 53 * @group bp_core_time_since 54 */ 55 public function test_bp_core_time_since_years_nomonths() { 56 $now = time(); 57 $then = $now - ( 3 * YEAR_IN_SECONDS ); 58 $this->assertEquals( '3 years ago', bp_core_time_since( $then, $now ) ); 59 } 60 61 /** 62 * @group bp_core_time_since 63 */ 64 public function test_bp_core_time_since_months_weeks() { 65 $now = time(); 66 $then = $now - ( 3 * 30 * DAY_IN_SECONDS ) - ( 3 * WEEK_IN_SECONDS ); 67 $this->assertEquals( '3 months, 3 weeks ago', bp_core_time_since( $then, $now ) ); 68 } 69 70 /** 71 * @group bp_core_time_since 72 */ 73 public function test_bp_core_time_since_months_noweeks() { 74 $now = time(); 75 $then = $now - ( 3 * 30 * DAY_IN_SECONDS ); 76 $this->assertEquals( '3 months ago', bp_core_time_since( $then, $now ) ); 77 } 78 79 /** 80 * @group bp_core_time_since 81 */ 82 public function test_bp_core_time_since_weeks_days() { 83 $now = time(); 84 $then = $now - ( 3 * WEEK_IN_SECONDS ) - ( 3 * DAY_IN_SECONDS ); 85 $this->assertEquals( '3 weeks, 3 days ago', bp_core_time_since( $then, $now ) ); 86 } 87 88 /** 89 * @group bp_core_time_since 90 */ 91 public function test_bp_core_time_since_weeks_nodays() { 92 $now = time(); 93 $then = $now - ( 3 * WEEK_IN_SECONDS ); 94 $this->assertEquals( '3 weeks ago', bp_core_time_since( $then, $now ) ); 95 } 96 97 /** 98 * @group bp_core_time_since 99 */ 100 public function test_bp_core_time_since_days_hours() { 101 $now = time(); 102 $then = $now - ( 3 * DAY_IN_SECONDS ) - ( 3 * HOUR_IN_SECONDS ); 103 $this->assertEquals( '3 days, 3 hours ago', bp_core_time_since( $then, $now ) ); 104 } 105 106 /** 107 * @group bp_core_time_since 108 */ 109 public function test_bp_core_time_since_days_nohours() { 110 $now = time(); 111 $then = $now - ( 3 * DAY_IN_SECONDS ); 112 $this->assertEquals( '3 days ago', bp_core_time_since( $then, $now ) ); 113 } 114 115 /** 116 * @group bp_core_time_since 117 */ 118 public function test_bp_core_time_since_hours_minutes() { 119 $now = time(); 120 $then = $now - ( 3 * HOUR_IN_SECONDS ) - ( 3 * MINUTE_IN_SECONDS ); 121 $this->assertEquals( '3 hours, 3 minutes ago', bp_core_time_since( $then, $now ) ); 122 } 123 124 /** 125 * @group bp_core_time_since 126 */ 127 public function test_bp_core_time_since_hours_nominutes() { 128 $now = time(); 129 $then = $now - ( 3 * HOUR_IN_SECONDS ); 130 $this->assertEquals( '3 hours ago', bp_core_time_since( $then, $now ) ); 131 } 132 133 /** 134 * @group bp_core_time_since 135 * @ticket BP5017 136 */ 137 public function test_bp_core_time_since_minutes_seconds() { 138 $now = time(); 139 $then = $now - ( 3 * MINUTE_IN_SECONDS ) - 3; 140 $this->assertEquals( '3 minutes ago', bp_core_time_since( $then, $now ) ); 141 } 142 143 /** 144 * @group bp_core_time_since 145 */ 146 public function test_bp_core_time_since_minutes_noseconds() { 147 $now = time(); 148 $then = $now - ( 3 * MINUTE_IN_SECONDS ); 149 $this->assertEquals( '3 minutes ago', bp_core_time_since( $then, $now ) ); 150 } 151 152 /** 153 * @group bp_core_time_since 154 */ 155 public function test_bp_core_time_since_seconds() { 156 $now = time(); 157 $then = $now - 3; 158 $this->assertEquals( '3 seconds ago', bp_core_time_since( $then, $now ) ); 159 } 160 161 /** 162 * Sanity check for the singular version of 'year' 163 * 164 * @group bp_core_time_since 165 */ 166 public function test_bp_core_time_since_year() { 167 $now = time(); 168 $then = $now - YEAR_IN_SECONDS; 169 $this->assertEquals( '1 year ago', bp_core_time_since( $then, $now ) ); 170 } 171 172 /** 173 * @group bp_core_time_since 174 */ 175 public function test_bp_core_time_since_rightnow() { 176 $now = time(); 177 $then = $now; 178 $this->assertEquals( 'right now', bp_core_time_since( $then, $now ) ); 179 } 180 181 /** 182 * @group bp_core_time_since 183 */ 184 public function test_bp_core_time_since_future() { 185 $now = time(); 186 $then = $now + 100; 187 $this->assertEquals( 'sometime ago', bp_core_time_since( $then, $now ) ); 188 } 189 190 /** 191 * @group bp_format_time 192 */ 193 public function test_bp_format_time_gmt_offset_no_timezone_string() { 194 $time = 1395169200; 195 $gmt_offset = '-6'; 196 $just_date = false; 197 $localize_time = true; 198 199 update_option( 'date_format', 'F j, Y' ); 200 update_option( 'time_format', 'g:i a' ); 201 update_option( 'gmt_offset', $gmt_offset ); 202 update_option( 'timezone_string', '' ); 203 204 $this->assertEquals( 'March 18, 2014 at 1:00 pm', bp_format_time( $time, $just_date, $localize_time ) ); 205 } 206 207 /** 208 * @group bp_format_time 209 */ 210 public function test_bp_format_time_timezone_string_no_gmt_offset() { 211 $time = 1395169200; 212 $timzone_string = 'America/Chicago'; 213 $just_date = false; 214 $localize_time = true; 215 216 update_option( 'date_format', 'F j, Y' ); 217 update_option( 'time_format', 'g:i a' ); 218 update_option( 'timezone_string', $timzone_string ); 219 update_option( 'gmt_offset', '0' ); 220 221 $this->assertEquals( 'March 18, 2014 at 2:00 pm', bp_format_time( $time, $just_date, $localize_time ) ); 222 } 223 224 /** 225 * @group bp_format_time 226 */ 227 public function test_bp_format_time_gmt_offset_no_localize() { 228 $time = 1395169200; 229 $gmt_offset = '-6'; 230 $just_date = false; 231 $localize_time = false; 232 233 update_option( 'date_format', 'F j, Y' ); 234 update_option( 'time_format', 'g:i a' ); 235 update_option( 'gmt_offset', $gmt_offset ); 236 update_option( 'timezone_string', '' ); 237 238 $this->assertEquals( 'March 18, 2014 at 7:00 pm', bp_format_time( $time, $just_date, $localize_time ) ); 239 } 240 241 /** 242 * @group bp_format_time 243 */ 244 public function test_bp_format_time_timezone_string_no_localize() { 245 $time = 1395169200; 246 $timzone_string = 'America/Chicago'; 247 $just_date = false; 248 $localize_time = false; 249 250 update_option( 'date_format', 'F j, Y' ); 251 update_option( 'time_format', 'g:i a' ); 252 update_option( 'timezone_string', $timzone_string ); 253 update_option( 'gmt_offset', '0' ); 254 255 $this->assertEquals( 'March 18, 2014 at 7:00 pm', bp_format_time( $time, $just_date, $localize_time ) ); 256 } 257 258 /** 259 * @group bp_core_get_iso8601_date 260 */ 261 public function test_bp_core_get_iso8601_date_invalid_date() { 262 $this->assertEquals( '', bp_core_get_iso8601_date( 'Not a date' ) ); 263 } 264 265 /** 266 * @group bp_sort_by_key 267 */ 268 public function test_bp_sort_by_key_arrays_num() { 269 $items = array( 270 array( 271 'foo' => 'bar', 272 'value' => 5, 273 ), 274 array( 275 'foo' => 'bar', 276 'value' => 10, 277 ), 278 array( 279 'foo' => 'bar', 280 'value' => 1, 281 ), 282 ); 283 284 $expected = array( 285 array( 286 'foo' => 'bar', 287 'value' => 1, 288 ), 289 array( 290 'foo' => 'bar', 291 'value' => 5, 292 ), 293 array( 294 'foo' => 'bar', 295 'value' => 10, 296 ), 297 ); 298 299 $this->assertEquals( $expected, bp_sort_by_key( $items, 'value', 'num' ) ); 300 } 301 302 /** 303 * @group bp_sort_by_key 304 */ 305 public function test_bp_sort_by_key_objects_num() { 306 $items = array( 307 new stdClass, 308 new stdClass, 309 new stdClass, 310 ); 311 $items[0]->foo = 'bar'; 312 $items[0]->value = 5; 313 $items[1]->foo = 'bar'; 314 $items[1]->value = 10; 315 $items[2]->foo = 'bar'; 316 $items[2]->value = 1; 317 318 $expected = array( 319 new stdClass, 320 new stdClass, 321 new stdClass, 322 ); 323 $expected[0]->foo = 'bar'; 324 $expected[0]->value = 1; 325 $expected[1]->foo = 'bar'; 326 $expected[1]->value = 5; 327 $expected[2]->foo = 'bar'; 328 $expected[2]->value = 10; 329 330 $this->assertEquals( $expected, bp_sort_by_key( $items, 'value', 'num' ) ); 331 } 332 333 /** 334 * @group bp_sort_by_key 335 */ 336 public function test_bp_sort_by_key_num_should_respect_0() { 337 $items = array( 338 array( 339 'foo' => 'bar', 340 'value' => 2, 341 ), 342 array( 343 'foo' => 'bar', 344 'value' => 0, 345 ), 346 array( 347 'foo' => 'bar', 348 'value' => 4, 349 ), 350 ); 351 352 $expected = array( 353 array( 354 'foo' => 'bar', 355 'value' => 0, 356 ), 357 array( 358 'foo' => 'bar', 359 'value' => 2, 360 ), 361 array( 362 'foo' => 'bar', 363 'value' => 4, 364 ), 365 ); 366 367 $this->assertEquals( $expected, bp_sort_by_key( $items, 'value', 'num' ) ); 368 } 369 370 /** 371 * @group bp_alpha_sort_by_key 372 */ 373 public function test_bp_alpha_sort_by_key_arrays() { 374 $items = array( 375 array( 376 'foo' => 'bar', 377 'name' => 'alpha', 378 ), 379 array( 380 'foo' => 'bar', 381 'name' => 'charlie', 382 ), 383 array( 384 'foo' => 'bar', 385 'name' => 'beta', 386 ), 387 ); 388 389 $expected = array( 390 array( 391 'foo' => 'bar', 392 'name' => 'alpha', 393 ), 394 array( 395 'foo' => 'bar', 396 'name' => 'beta', 397 ), 398 array( 399 'foo' => 'bar', 400 'name' => 'charlie', 401 ), 402 ); 403 404 $this->assertEquals( $expected, bp_alpha_sort_by_key( $items, 'name' ) ); 405 } 406 407 /** 408 * @group bp_alpha_sort_by_key 409 */ 410 public function test_bp_alpha_sort_by_key_objects() { 411 $items = array( 412 new stdClass, 413 new stdClass, 414 new stdClass, 415 ); 416 $items[0]->foo = 'bar'; 417 $items[0]->name = 'alpha'; 418 $items[1]->foo = 'bar'; 419 $items[1]->name = 'charlie'; 420 $items[2]->foo = 'bar'; 421 $items[2]->name = 'beta'; 422 423 $expected = array( 424 new stdClass, 425 new stdClass, 426 new stdClass, 427 ); 428 $expected[0]->foo = 'bar'; 429 $expected[0]->name = 'alpha'; 430 $expected[1]->foo = 'bar'; 431 $expected[1]->name = 'beta'; 432 $expected[2]->foo = 'bar'; 433 $expected[2]->name = 'charlie'; 434 435 $this->assertEquals( $expected, bp_alpha_sort_by_key( $items, 'name' ) ); 436 } 437 438 /** 439 * @group bp_sort_by_key 440 */ 441 public function test_bp_sort_by_key_arrays_num_preserve_keys() { 442 $items = array( 443 'p' => array( 444 'foo' => 'bar', 445 'value' => 5, 446 ), 447 'q' => array( 448 'foo' => 'bar', 449 'value' => 10, 450 ), 451 'r' => array( 452 'foo' => 'bar', 453 'value' => 1, 454 ), 455 ); 456 457 $expected = array( 458 'r' => array( 459 'foo' => 'bar', 460 'value' => 1, 461 ), 462 'p' => array( 463 'foo' => 'bar', 464 'value' => 5, 465 ), 466 'q' => array( 467 'foo' => 'bar', 468 'value' => 10, 469 ), 470 ); 471 472 $this->assertEquals( $expected, bp_sort_by_key( $items, 'value', 'num', true ) ); 473 } 474 475 /** 476 * @group bp_sort_by_key 477 */ 478 public function test_bp_sort_by_key_num_should_respect_0_preserve_keys() { 479 $items = array( 480 's' => array( 481 'foo' => 'bar', 482 'value' => 2, 483 ), 484 't' => array( 485 'foo' => 'bar', 486 'value' => 0, 487 ), 488 'u' => array( 489 'foo' => 'bar', 490 'value' => 4, 491 ), 492 ); 493 494 $expected = array( 495 't' => array( 496 'foo' => 'bar', 497 'value' => 0, 498 ), 499 's' => array( 500 'foo' => 'bar', 501 'value' => 2, 502 ), 503 'u' => array( 504 'foo' => 'bar', 505 'value' => 4, 506 ), 507 ); 508 509 $this->assertEquals( $expected, bp_sort_by_key( $items, 'value', 'num', true ) ); 510 } 511 512 /** 513 * @group pagination 514 * @group bp_sanitize_pagination_arg 515 */ 516 public function test_bp_sanitize_pagination_arg_zero() { 517 $request = $_REQUEST; 518 $arg = 'bp_pagination_test'; 519 $page = 1; 520 $_REQUEST[ $arg ] = '0'; 521 $value = bp_sanitize_pagination_arg( $arg, $page ); 522 523 $this->assertEquals( $value, $page ); 524 525 $_REQUEST = $request; 526 } 527 528 /** 529 * @group pagination 530 * @group bp_sanitize_pagination_arg 531 */ 532 public function test_bp_sanitize_pagination_arg_negative() { 533 $request = $_REQUEST; 534 $arg = 'bp_pagination_test'; 535 $page = 25; 536 $_REQUEST[ $arg ] = '-25'; 537 $value = bp_sanitize_pagination_arg( $arg, $page ); 538 539 $this->assertEquals( $value, $page ); 540 541 $_REQUEST = $request; 542 } 543 544 /** 545 * @group bp_core_get_directory_pages 546 */ 547 public function test_bp_core_get_directory_pages_after_page_edit() { 548 // Set the cache 549 $pages = bp_core_get_directory_pages(); 550 551 // Update one of the posts 552 switch_to_blog( bp_get_root_blog_id() ); 553 554 // grab the first one 555 foreach ( $pages as $page ) { 556 $p = $page; 557 break; 558 } 559 560 $post = get_post( $p->id ); 561 $post->post_title .= ' Foo'; 562 wp_update_post( $post ); 563 564 restore_current_blog(); 565 566 $this->assertFalse( wp_cache_get( 'directory_pages', 'bp' ) ); 567 } 568 569 /** 570 * @group bp_core_get_root_options 571 */ 572 public function test_bp_core_get_root_options_cache_invalidate() { 573 $keys = array_keys( bp_get_default_options() ); 574 $keys[] = 'registration'; 575 $keys[] = 'avatar_default'; 576 577 foreach ( $keys as $key ) { 578 // prime cache 579 $root_options = bp_core_get_root_options(); 580 581 bp_update_option( $key, 'foo' ); 582 583 $this->assertFalse( wp_cache_get( 'root_blog_options', 'bp' ), 'Cache not invalidated after updating "' . $key . '"' ); 584 } 585 586 if ( is_multisite() ) { 587 $ms_keys = array( 588 'tags_blog_id', 589 'sitewide_tags_blog', 590 'registration', 591 'fileupload_mask', 592 ); 593 594 foreach ( $ms_keys as $ms_key ) { 595 $root_options = bp_core_get_root_options(); 596 597 update_site_option( $ms_key, 'foooooooo' ); 598 599 $this->assertFalse( wp_cache_get( 'root_blog_options', 'bp' ), 'Cache not invalidated after updating "' . $ms_key . '"' ); 600 } 601 } 602 } 603 604 /** 605 * @group bp_core_get_root_option 606 */ 607 public function test_bp_core_get_root_option_with_unpopulated_cache() { 608 // Back up and unset global cache. 609 $old_options = buddypress()->site_options; 610 unset( buddypress()->site_options ); 611 612 $this->assertSame( $old_options['avatar_default'], bp_core_get_root_option( 'avatar_default' ) ); 613 614 // Clean up. 615 buddypress()->site_options = $old_options; 616 } 617 618 /** 619 * @group bp_core_get_root_option 620 */ 621 public function test_bp_core_get_root_option_with_populated_cache() { 622 // Back up and unset global cache. 623 $old_options = buddypress()->site_options; 624 buddypress()->site_options = bp_core_get_root_options(); 625 $expected = buddypress()->site_options['avatar_default']; 626 627 $this->assertSame( $expected, bp_core_get_root_option( 'avatar_default' ) ); 628 } 629 630 /** 631 * @group bp_core_add_root_component 632 */ 633 public function test_add_root_component_not_in_bp_pages() { 634 buddypress()->foo = new stdClass; 635 buddypress()->foo->id = 'foo'; 636 buddypress()->foo->slug = 'foo'; 637 638 bp_core_add_root_component( 'foo' ); 639 640 $this->assertTrue( in_array( 'foo', buddypress()->add_root ) ); 641 $this->assertTrue( buddypress()->foo->has_directory ); 642 $this->assertNotEmpty( buddypress()->loaded_components['foo'] ); 643 } 644 645 /** 646 * @group bp_core_time_since 647 * @group bp_core_current_time 648 */ 649 public function test_bp_core_time_since_timezone_minute_ago() { 650 // backup timezone 651 $tz_backup = date_default_timezone_get(); 652 653 // set timezone to something other than UTC 654 date_default_timezone_set( 'Europe/Paris' ); 655 656 $this->assertSame( '1 minute ago', bp_core_time_since( time() - 60 ) ); 657 658 // revert timezone back to normal 659 if ( $tz_backup ) { 660 date_default_timezone_set( $tz_backup ); 661 } 662 } 663 664 /** 665 * @group bp_core_time_since 666 * @group bp_core_current_time 667 */ 668 public function test_bp_core_time_since_timezone() { 669 // backup timezone 670 $tz_backup = date_default_timezone_get(); 671 672 // set timezone to something other than UTC 673 date_default_timezone_set( 'Europe/Paris' ); 674 675 $this->assertSame( '1 hour ago', bp_core_time_since( time() - 60*60 ) ); 676 677 // revert timezone back to normal 678 if ( $tz_backup ) { 679 date_default_timezone_set( $tz_backup ); 680 } 681 } 682 683 /** 684 * @group bp_core_time_since 685 */ 686 public function test_bp_core_time_since_mysql_and_unix_timestamp_return_same_value() { 687 $mysql_date = '2008-03-25 17:13:55'; 688 689 $ts_mysql = bp_core_time_since( $mysql_date ); 690 $ts_timestamp = bp_core_time_since( strtotime( $mysql_date ) ); 691 692 $this->assertSame( $ts_mysql, $ts_timestamp ); 693 } 694 695 /** 696 * @group bp_attachments 697 * @group bp_upload_dir 698 */ 699 public function test_bp_upload_dir() { 700 $expected_upload_dir = wp_upload_dir(); 701 702 if ( is_multisite() ) { 703 $b = self::factory()->blog->create(); 704 switch_to_blog( $b ); 705 } 706 707 $tested_upload_dir = bp_upload_dir(); 708 709 if ( is_multisite() ) { 710 restore_current_blog(); 711 } 712 713 $this->assertSame( $expected_upload_dir, $tested_upload_dir ); 714 } 715 716 /** 717 * @group bp_is_active 718 */ 719 public function test_bp_is_active_component() { 720 $bp = buddypress(); 721 $reset_active_components = $bp->active_components; 722 723 $this->assertTrue( bp_is_active( 'members' ) ); 724 725 $this->assertFalse( bp_is_active( 'foo' ) ); 726 727 // Create and activate the foo component 728 $bp->foo = new BP_Component; 729 $bp->foo->id = 'foo'; 730 $bp->foo->slug = 'foo'; 731 $bp->foo->name = 'Foo'; 732 $bp->active_components[ $bp->foo->id ] = 1; 733 734 $this->assertTrue( bp_is_active( 'foo' ) ); 735 736 add_filter( 'bp_is_active', '__return_false' ); 737 738 $this->assertFalse( bp_is_active( 'foo' ) ); 739 740 remove_filter( 'bp_is_active', '__return_false' ); 741 742 // Reset buddypress() vars 743 $bp->active_components = $reset_active_components; 744 } 745 746 /** 747 * @group bp_is_active 748 */ 749 public function test_bp_is_active_feature() { 750 $bp = buddypress(); 751 $reset_active_components = $bp->active_components; 752 753 // Create and activate the foo component 754 $bp->foo = new BP_Component; 755 $bp->foo->id = 'foo'; 756 $bp->foo->slug = 'foo'; 757 $bp->foo->name = 'Foo'; 758 $bp->active_components[ $bp->foo->id ] = 1; 759 760 // foo did not register 'bar' as a feature 761 $this->assertFalse( bp_is_active( 'foo', 'bar' ) ); 762 763 // fake registering the 'bar' feature 764 $bp->foo->features = array( 'bar' ); 765 $this->assertTrue( bp_is_active( 'foo', 'bar' ) ); 766 767 // test the feature filter 768 add_filter( 'bp_is_foo_bar_active', '__return_false' ); 769 $this->assertFalse( bp_is_active( 'foo', 'bar' ) ); 770 remove_filter( 'bp_is_foo_bar_active', '__return_false' ); 771 772 // test the main component filter 773 add_filter( 'bp_is_active', '__return_false' ); 774 $this->assertFalse( bp_is_active( 'foo', 'bar' ) ); 775 remove_filter( 'bp_is_active', '__return_false' ); 776 777 // Reset buddypress() vars 778 $bp->active_components = $reset_active_components; 779 } 780 781 /** 782 * @group bp_attachments 783 */ 784 public function test_bp_attachments_get_allowed_types() { 785 $supported = array( 'jpeg', 'gif', 'png' ); 786 787 $avatar = bp_attachments_get_allowed_types( 'avatar' ); 788 $this->assertSame( $supported, $avatar ); 789 790 $cover_image = bp_attachments_get_allowed_types( 'cover_image' ); 791 $this->assertSame( $supported, $cover_image ); 792 793 $images = bp_attachments_get_allowed_types( 'image/' ); 794 795 foreach ( $images as $image ) { 796 if ( 'image' !== wp_ext2type( $image ) ) { 797 $not_image = $image; 798 } 799 } 800 801 $this->assertTrue( empty( $not_image ) ); 802 } 803 804 public function test_emails_should_have_correct_link_color() { 805 $appearance = bp_email_get_appearance_settings(); 806 807 $content = '<a href="http://example.com">example</a>'; 808 $link_color = 'style="color: ' . esc_attr( $appearance['highlight_color'] ) . ';'; 809 $result = bp_email_add_link_color_to_template( $content, 'template', 'add-content' ); 810 $this->assertContains( $link_color, $result ); 811 812 $content = '<a href="http://example.com" style="display: block">example</a>'; 813 $link_color .= 'display: block'; 814 $result = bp_email_add_link_color_to_template( $content, 'template', 'add-content' ); 815 $this->assertContains( $link_color, $result ); 816 } 817 818 /** 819 * @group bp_core_add_page_mappings 820 */ 821 public function test_bp_core_add_page_mappings() { 822 $bp = buddypress(); 823 $reset_bp_pages = $bp->pages; 824 825 $expected = array( 'activity', 'groups', 'members' ); 826 if ( is_multisite() ) { 827 $expected = array( 'activity', 'blogs', 'groups', 'members' ); 828 } 829 830 bp_core_add_page_mappings( $bp->active_components ); 831 $bp_pages = array_keys( bp_get_option( 'bp-pages' ) ); 832 sort( $bp_pages ); 833 834 $this->assertEquals( $expected, $bp_pages ); 835 836 $bp->pages = $reset_bp_pages; 837 } 838 839 /** 840 * @group bp_core_add_page_mappings 841 * @ticket 8187 842 */ 843 public function test_bp_core_add_page_mappings_in_multisite_subdirectory() { 844 if ( ! is_multisite() || is_subdomain_install() ) { 845 $this->markTestSkipped(); 846 } 847 848 $bp = buddypress(); 849 $reset_bp_pages = $bp->pages; 850 $reset_bp_active_components = $bp->active_components; 851 $reset_option = bp_get_option( 'bp-pages' ); 852 853 $b = self::factory()->blog->create( array( 854 'path' => '/newcomponent/', 855 ) ); 856 857 $bp->active_components['newcomponent'] = 1; 858 add_filter( 'bp_core_get_directory_page_default_titles', array( $this, 'add_newcomponent_page_title' ) ); 859 860 bp_core_add_page_mappings( $bp->active_components ); 861 862 remove_filter( 'bp_core_get_directory_page_default_titles', array( $this, 'add_newcomponent_page_title' ) ); 863 $bp_pages = bp_get_option( 'bp-pages' ); 864 865 $new_component_page_id = $bp_pages['newcomponent']; 866 $this->assertNotSame( 'newcomponent', get_post_field( 'post_name', $new_component_page_id ), 'The component slug should not conflict with subsite name.' ); 867 868 // Reset the page mapping. 869 bp_update_option( 'bp-pages', $reset_option ); 870 wp_delete_post( $bp_pages['newcomponent'], true ); 871 $bp->pages = $reset_bp_pages; 872 $bp->active_components = $reset_bp_active_components; 873 } 874 875 public function add_newcomponent_page_title( $page_default_titles = array() ) { 876 return array_merge( $page_default_titles, array( 'newcomponent' => 'NewComponent' ) ); 877 } 878 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |