1
0
Fork 0
mirror of https://github.com/buddypress/buddypress.git synced 2026-07-21 20:54:17 +08:00
buddypress/tests/phpunit/testcases/routing/url.php
Boone B Gorges 0c08251ea5 Tests: Move wpmu_new_blog and delete_blog expectedDeprecated calls into test logic.
Use of the `@expectedDeprecated` annotation means that the deprecation notice is
expected across all versions of WordPress, while we in fact need to suppress the
notices only on WP 5.0+.

See #7984.

git-svn-id: https://buddypress.svn.wordpress.org/trunk@12246 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2018-10-05 17:24:17 +00:00

68 lines
1.9 KiB
PHP

<?php
/**
* @group url
*/
class BP_Tests_URL extends BP_UnitTestCase {
function test_bp_core_ajax_url() {
$forced = force_ssl_admin();
$old_https = isset( $_SERVER['HTTPS'] ) ? $_SERVER['HTTPS'] : null;
// (1) HTTPS off
force_ssl_admin( false );
$_SERVER['HTTPS'] = 'off';
// (1a) Front-end
$this->go_to( '/' );
$this->assertEquals( bp_core_ajax_url(), get_site_url( bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'http' ) );
// (1b) Dashboard
$this->go_to( '/wp-admin' );
$this->assertEquals( bp_core_ajax_url(), get_site_url( bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'http' ) );
// (2) FORCE_SSL_ADMIN
force_ssl_admin( true );
// (2a) Front-end
$this->go_to( '/' );
$this->assertEquals( bp_core_ajax_url(), get_site_url( bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'http' ) );
// (2b) Dashboard
$_SERVER['HTTPS'] = 'on';
$this->go_to( '/wp-admin' );
$this->assertEquals( bp_core_ajax_url(), get_site_url( bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'https' ) );
// Restore to defaults.
force_ssl_admin( $forced );
if ( is_null( $old_https ) ) {
unset( $_SERVER['HTTPS'] );
} else {
$_SERVER['HTTPS'] = $old_https;
}
// (3) Multisite, root blog other than 1
if ( is_multisite() ) {
if ( function_exists( 'wp_initialize_site' ) ) {
$this->setExpectedDeprecated( 'wpmu_new_blog' );
}
$original_root_blog = bp_get_root_blog_id();
$blog_id = self::factory()->blog->create( array(
'path' => '/path' . rand() . time() . '/',
) );
buddypress()->root_blog_id = $blog_id;
$blog_url = get_blog_option( $blog_id, 'siteurl' );
$this->go_to( trailingslashit( $blog_url ) );
switch_to_blog( $blog_id );
buddypress()->root_blog_id = $original_root_blog;
$ajax_url = bp_core_ajax_url();
restore_current_blog();
$this->go_to( '/' );
$this->assertEquals( $blog_url . '/wp-admin/admin-ajax.php', $ajax_url );
}
}
}