[ 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              $original_root_blog = bp_get_root_blog_id();
  45              $blog_id = self::factory()->blog->create( array(
  46                  'path' => '/path' . rand() . time() . '/',
  47              ) );
  48  
  49              buddypress()->root_blog_id = $blog_id;
  50              $blog_url = get_blog_option( $blog_id, 'siteurl' );
  51  
  52              $this->go_to( trailingslashit( $blog_url ) );
  53              switch_to_blog( $blog_id );
  54  
  55              buddypress()->root_blog_id = $original_root_blog;
  56              $ajax_url = bp_core_ajax_url();
  57  
  58              restore_current_blog();
  59              $this->go_to( '/' );
  60  
  61              $this->assertEquals( $blog_url . '/wp-admin/admin-ajax.php', $ajax_url );
  62          }
  63      }
  64  }


Generated: Thu Nov 21 01:00:57 2024 Cross-referenced by PHPXref 0.7.1