Skip to content

Commit e54dbeb

Browse files
committed
Sync: Default to using raw home and siteurl values
1 parent 8be4bea commit e54dbeb

2 files changed

Lines changed: 10 additions & 29 deletions

File tree

sync/class.jetpack-sync-functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public static function file_system_write_access() {
146146

147147
public static function home_url() {
148148
if (
149-
Jetpack_Constants::is_defined( 'JETPACK_SYNC_USE_RAW_URL' ) &&
149+
! Jetpack_Constants::is_defined( 'JETPACK_SYNC_USE_RAW_URL' ) ||
150150
Jetpack_Constants::get_constant( 'JETPACK_SYNC_USE_RAW_URL' )
151151
) {
152152
$home_url = self::get_raw_url( 'home' );
@@ -168,7 +168,7 @@ public static function home_url() {
168168

169169
public static function site_url() {
170170
if (
171-
Jetpack_Constants::is_defined( 'JETPACK_SYNC_USE_RAW_URL' ) &&
171+
! Jetpack_Constants::is_defined( 'JETPACK_SYNC_USE_RAW_URL' ) ||
172172
Jetpack_Constants::get_constant( 'JETPACK_SYNC_USE_RAW_URL' )
173173
) {
174174
$site_url = self::get_raw_url( 'siteurl' );

tests/php/sync/test_class.jetpack-sync-callables.php

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,8 @@ function test_sync_jetpack_sync_unlock_sync_callable_action_allows_syncing_siteu
204204

205205
$this->server_replica_storage->reset();
206206

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

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

229228
// Cleanup
230229
unset( $_SERVER['HTTPS'] );
231-
remove_filter( 'option_home', array( $this, 'return_https_site_com_blog' ) );
232-
remove_filter( 'option_siteurl', array( $this, 'return_https_site_com_blog' ) );
230+
231+
update_option( 'home', $original_home_option );
232+
update_option( 'siteurl', $original_siteurl_option );
233233
}
234234

235235
function test_home_site_urls_synced_while_migrate_for_idc_set() {
@@ -270,25 +270,6 @@ function test_home_site_urls_synced_while_migrate_for_idc_set() {
270270
Jetpack_Options::delete_option( 'migrate_for_idc' );
271271
}
272272

273-
function test_scheme_switching_does_not_cause_sync() {
274-
$this->setSyncClientDefaults();
275-
delete_transient( Jetpack_Sync_Module_Callables::CALLABLES_AWAIT_TRANSIENT_NAME );
276-
delete_option( Jetpack_Sync_Module_Callables::CALLABLES_CHECKSUM_OPTION_NAME );
277-
$_SERVER['HTTPS'] = 'off';
278-
$home_url = home_url();
279-
$this->sender->do_sync();
280-
281-
$this->assertEquals( $home_url, $this->server_replica_storage->get_callable( 'home_url' ) );
282-
283-
// this sets is_ssl() to return true.
284-
$_SERVER['HTTPS'] = 'on';
285-
delete_transient( Jetpack_Sync_Module_Callables::CALLABLES_AWAIT_TRANSIENT_NAME );
286-
$this->sender->do_sync();
287-
288-
unset( $_SERVER['HTTPS'] );
289-
$this->assertEquals( $home_url, $this->server_replica_storage->get_callable( 'home_url' ) );
290-
}
291-
292273
function return_example_com() {
293274
return 'http://example.com';
294275
}
@@ -553,17 +534,17 @@ function test_get_raw_url_returns_with_https_if_is_ssl() {
553534
unset( $_SERVER['HTTPS'] );
554535
}
555536

556-
function test_urls_are_raw_with_use_raw_url_constant() {
537+
function test_user_can_stop_raw_urls() {
557538
add_filter( 'option_home', array( $this, '__return_filtered_url' ) );
558539
add_filter( 'option_siteurl', array( $this, '__return_filtered_url' ) );
559540

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

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

568549
remove_filter( 'option_home', array( $this, '__return_filtered_url' ) );
569550
remove_filter( 'option_siteurl', array( $this, '__return_filtered_url' ) );

0 commit comments

Comments
 (0)