Skip to content

Commit

Permalink
Sync: Default to using raw home and siteurl values
Browse files Browse the repository at this point in the history
  • Loading branch information
ebinnion committed Jul 18, 2017
1 parent 8be4bea commit e54dbeb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
4 changes: 2 additions & 2 deletions sync/class.jetpack-sync-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static function file_system_write_access() {

public static function home_url() {
if (
Jetpack_Constants::is_defined( 'JETPACK_SYNC_USE_RAW_URL' ) &&
! Jetpack_Constants::is_defined( 'JETPACK_SYNC_USE_RAW_URL' ) ||
Jetpack_Constants::get_constant( 'JETPACK_SYNC_USE_RAW_URL' )
) {
$home_url = self::get_raw_url( 'home' );
Expand All @@ -168,7 +168,7 @@ public static function home_url() {

public static function site_url() {
if (
Jetpack_Constants::is_defined( 'JETPACK_SYNC_USE_RAW_URL' ) &&
! Jetpack_Constants::is_defined( 'JETPACK_SYNC_USE_RAW_URL' ) ||
Jetpack_Constants::get_constant( 'JETPACK_SYNC_USE_RAW_URL' )
) {
$site_url = self::get_raw_url( 'siteurl' );
Expand Down
35 changes: 8 additions & 27 deletions tests/php/sync/test_class.jetpack-sync-callables.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,8 @@ function test_sync_jetpack_sync_unlock_sync_callable_action_allows_syncing_siteu

$this->server_replica_storage->reset();

// We set the filters here to simulate how setting the WP_HOME and WP_SITEURL constant works.
add_filter( 'option_home', array( $this, 'return_https_site_com_blog' ) );
add_filter( 'option_siteurl', array( $this, 'return_https_site_com_blog' ) );
update_option( 'home', $this->return_https_site_com_blog() );
update_option( 'siteurl', $this->return_https_site_com_blog() );

/**
* Used to signal that the callables await transient should be cleared. Clearing the await transient is useful
Expand All @@ -228,8 +227,9 @@ function test_sync_jetpack_sync_unlock_sync_callable_action_allows_syncing_siteu

// Cleanup
unset( $_SERVER['HTTPS'] );
remove_filter( 'option_home', array( $this, 'return_https_site_com_blog' ) );
remove_filter( 'option_siteurl', array( $this, 'return_https_site_com_blog' ) );

update_option( 'home', $original_home_option );
update_option( 'siteurl', $original_siteurl_option );
}

function test_home_site_urls_synced_while_migrate_for_idc_set() {
Expand Down Expand Up @@ -270,25 +270,6 @@ function test_home_site_urls_synced_while_migrate_for_idc_set() {
Jetpack_Options::delete_option( 'migrate_for_idc' );
}

function test_scheme_switching_does_not_cause_sync() {
$this->setSyncClientDefaults();
delete_transient( Jetpack_Sync_Module_Callables::CALLABLES_AWAIT_TRANSIENT_NAME );
delete_option( Jetpack_Sync_Module_Callables::CALLABLES_CHECKSUM_OPTION_NAME );
$_SERVER['HTTPS'] = 'off';
$home_url = home_url();
$this->sender->do_sync();

$this->assertEquals( $home_url, $this->server_replica_storage->get_callable( 'home_url' ) );

// this sets is_ssl() to return true.
$_SERVER['HTTPS'] = 'on';
delete_transient( Jetpack_Sync_Module_Callables::CALLABLES_AWAIT_TRANSIENT_NAME );
$this->sender->do_sync();

unset( $_SERVER['HTTPS'] );
$this->assertEquals( $home_url, $this->server_replica_storage->get_callable( 'home_url' ) );
}

function return_example_com() {
return 'http://example.com';
}
Expand Down Expand Up @@ -553,17 +534,17 @@ function test_get_raw_url_returns_with_https_if_is_ssl() {
unset( $_SERVER['HTTPS'] );
}

function test_urls_are_raw_with_use_raw_url_constant() {
function test_user_can_stop_raw_urls() {
add_filter( 'option_home', array( $this, '__return_filtered_url' ) );
add_filter( 'option_siteurl', array( $this, '__return_filtered_url' ) );

// Test with constant first
Jetpack_Constants::set_constant( 'JETPACK_SYNC_USE_RAW_URL', true );
$this->assertTrue( 'http://filteredurl.com' !== Jetpack_Sync_Functions::home_url() );
Jetpack_Constants::clear_constants();

// Now, without, which should return the filtered URL
Jetpack_Constants::set_constant( 'JETPACK_SYNC_USE_RAW_URL', false );
$this->assertEquals( $this->__return_filtered_url(), Jetpack_Sync_Functions::home_url() );
Jetpack_Constants::clear_constants();

remove_filter( 'option_home', array( $this, '__return_filtered_url' ) );
remove_filter( 'option_siteurl', array( $this, '__return_filtered_url' ) );
Expand Down

0 comments on commit e54dbeb

Please sign in to comment.