[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   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              if ( function_exists( 'wp_initialize_site' ) ) {
 704                  $this->setExpectedDeprecated( 'wpmu_new_blog' );
 705              }
 706  
 707              $b = self::factory()->blog->create();
 708              switch_to_blog( $b );
 709          }
 710  
 711          $tested_upload_dir = bp_upload_dir();
 712  
 713          if ( is_multisite() ) {
 714              restore_current_blog();
 715          }
 716  
 717          $this->assertSame( $expected_upload_dir, $tested_upload_dir );
 718      }
 719  
 720      /**
 721       * @group bp_is_active
 722       */
 723  	public function test_bp_is_active_component() {
 724          $bp = buddypress();
 725          $reset_active_components = $bp->active_components;
 726  
 727          $this->assertTrue( bp_is_active( 'members' ) );
 728  
 729          $this->assertFalse( bp_is_active( 'foo' ) );
 730  
 731          // Create and activate the foo component
 732          $bp->foo = new BP_Component;
 733          $bp->foo->id   = 'foo';
 734          $bp->foo->slug = 'foo';
 735          $bp->foo->name = 'Foo';
 736          $bp->active_components[ $bp->foo->id ] = 1;
 737  
 738          $this->assertTrue( bp_is_active( 'foo' ) );
 739  
 740          add_filter( 'bp_is_active', '__return_false' );
 741  
 742          $this->assertFalse( bp_is_active( 'foo' ) );
 743  
 744          remove_filter( 'bp_is_active', '__return_false' );
 745  
 746          // Reset buddypress() vars
 747          $bp->active_components = $reset_active_components;
 748      }
 749  
 750      /**
 751       * @group bp_is_active
 752       */
 753  	public function test_bp_is_active_feature() {
 754          $bp = buddypress();
 755          $reset_active_components = $bp->active_components;
 756  
 757          // Create and activate the foo component
 758          $bp->foo = new BP_Component;
 759          $bp->foo->id   = 'foo';
 760          $bp->foo->slug = 'foo';
 761          $bp->foo->name = 'Foo';
 762          $bp->active_components[ $bp->foo->id ] = 1;
 763  
 764          // foo did not register 'bar' as a feature
 765          $this->assertFalse( bp_is_active( 'foo', 'bar' ) );
 766  
 767          // fake registering the 'bar' feature
 768          $bp->foo->features = array( 'bar' );
 769          $this->assertTrue( bp_is_active( 'foo', 'bar' ) );
 770  
 771          // test the feature filter
 772          add_filter( 'bp_is_foo_bar_active', '__return_false' );
 773          $this->assertFalse( bp_is_active( 'foo', 'bar' ) );
 774          remove_filter( 'bp_is_foo_bar_active', '__return_false' );
 775  
 776          // test the main component filter
 777          add_filter( 'bp_is_active', '__return_false' );
 778          $this->assertFalse( bp_is_active( 'foo', 'bar' ) );
 779          remove_filter( 'bp_is_active', '__return_false' );
 780  
 781          // Reset buddypress() vars
 782          $bp->active_components = $reset_active_components;
 783      }
 784  
 785      /**
 786       * @group bp_attachments
 787       */
 788  	public function test_bp_attachments_get_allowed_types() {
 789          $supported = array( 'jpeg', 'gif', 'png' );
 790  
 791          $avatar = bp_attachments_get_allowed_types( 'avatar' );
 792          $this->assertSame( $supported, $avatar );
 793  
 794          $cover_image = bp_attachments_get_allowed_types( 'cover_image' );
 795          $this->assertSame( $supported, $cover_image );
 796  
 797          $images = bp_attachments_get_allowed_types( 'image/' );
 798  
 799          foreach ( $images as $image ) {
 800              if ( 'image' !== wp_ext2type( $image ) ) {
 801                  $not_image = $image;
 802              }
 803          }
 804  
 805          $this->assertTrue( empty( $not_image ) );
 806      }
 807  
 808  	public function test_emails_should_have_correct_link_color() {
 809          $appearance = bp_email_get_appearance_settings();
 810  
 811          $content    = '<a href="http://example.com">example</a>';
 812          $link_color = 'style="color: ' . esc_attr( $appearance['highlight_color'] ) . ';';
 813          $result     = bp_email_add_link_color_to_template( $content, 'template', 'add-content' );
 814          $this->assertContains( $link_color, $result );
 815  
 816          $content     = '<a href="http://example.com" style="display: block">example</a>';
 817          $link_color .= 'display: block';
 818          $result      = bp_email_add_link_color_to_template( $content, 'template', 'add-content' );
 819          $this->assertContains( $link_color, $result );
 820      }
 821  
 822      /**
 823       * @group bp_core_add_page_mappings
 824       */
 825  	public function test_bp_core_add_page_mappings() {
 826          $bp = buddypress();
 827          $reset_bp_pages = $bp->pages;
 828  
 829          $expected = array( 'activity', 'groups', 'members' );
 830          if ( is_multisite() ) {
 831              $expected = array( 'activity', 'blogs', 'groups', 'members' );
 832          }
 833  
 834          bp_core_add_page_mappings( $bp->active_components );
 835          $bp_pages = array_keys( bp_get_option( 'bp-pages' ) );
 836          sort( $bp_pages );
 837  
 838          $this->assertEquals( $expected, $bp_pages );
 839  
 840          $bp->pages = $reset_bp_pages;
 841      }
 842  }


Generated: Mon Nov 11 01:01:38 2019 Cross-referenced by PHPXref 0.7.1