[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/routing/ -> url.php (source)

   1  <?php
   2  /**
   3   * @group url
   4   */
   5  class BP_Tests_URL extends BP_UnitTestCase {
   6  	function test_bp_core_ajax_url() {
   7          $forced = force_ssl_admin();
   8          $old_https = isset( $_SERVER['HTTPS'] ) ? $_SERVER['HTTPS'] : null;
   9  
  10          // (1) HTTPS off
  11          force_ssl_admin( false );
  12          $_SERVER['HTTPS'] = 'off';
  13  
  14          // (1a) Front-end
  15          $this->go_to( '/' );
  16          $this->assertEquals( bp_core_ajax_url(), get_site_url( bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'http' ) );
  17  
  18          // (1b) Dashboard
  19          $this->go_to( '/wp-admin' );
  20          $this->assertEquals( bp_core_ajax_url(), get_site_url( bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'http' ) );
  21  
  22          // (2) FORCE_SSL_ADMIN
  23          force_ssl_admin( true );
  24  
  25          // (2a) Front-end
  26          $this->go_to( '/' );
  27          $this->assertEquals( bp_core_ajax_url(), get_site_url( bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'http' ) );
  28  
  29          // (2b) Dashboard
  30          $_SERVER['HTTPS'] = 'on';
  31          $this->go_to( '/wp-admin' );
  32          $this->assertEquals( bp_core_ajax_url(), get_site_url( bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'https' ) );
  33  
  34          // Restore to defaults.
  35          force_ssl_admin( $forced );
  36          if ( is_null( $old_https ) ) {
  37              unset( $_SERVER['HTTPS'] );
  38          } else {
  39              $_SERVER['HTTPS'] = $old_https;
  40          }
  41  
  42          // (3) Multisite, root blog other than 1
  43          if ( is_multisite() ) {
  44              if ( function_exists( 'wp_initialize_site' ) ) {
  45                  $this->setExpectedDeprecated( 'wpmu_new_blog' );
  46              }
  47  
  48              $original_root_blog = bp_get_root_blog_id();
  49              $blog_id = self::factory()->blog->create( array(
  50                  'path' => '/path' . rand() . time() . '/',
  51              ) );
  52  
  53              buddypress()->root_blog_id = $blog_id;
  54              $blog_url = get_blog_option( $blog_id, 'siteurl' );
  55  
  56              $this->go_to( trailingslashit( $blog_url ) );
  57              switch_to_blog( $blog_id );
  58  
  59              buddypress()->root_blog_id = $original_root_blog;
  60              $ajax_url = bp_core_ajax_url();
  61  
  62              restore_current_blog();
  63              $this->go_to( '/' );
  64  
  65              $this->assertEquals( $blog_url . '/wp-admin/admin-ajax.php', $ajax_url );
  66          }
  67      }
  68  }


Generated: Sat Jul 20 01:01:39 2019 Cross-referenced by PHPXref 0.7.1