diff --git a/3rd-party/domain-mapping.php b/3rd-party/domain-mapping.php index 6079ac325908..f780033b98dd 100644 --- a/3rd-party/domain-mapping.php +++ b/3rd-party/domain-mapping.php @@ -1,5 +1,7 @@ function_exists( 'domain_mapping_siteurl' ) ) { + if ( ! Constants_Manager::is_defined( 'SUNRISE_LOADED' ) || ! $this->function_exists( 'domain_mapping_siteurl' ) ) { return false; } diff --git a/_inc/lib/core-api/wpcom-endpoints/subscribers.php b/_inc/lib/core-api/wpcom-endpoints/subscribers.php index c1a712bdb84d..9f8d99994572 100644 --- a/_inc/lib/core-api/wpcom-endpoints/subscribers.php +++ b/_inc/lib/core-api/wpcom-endpoints/subscribers.php @@ -1,5 +1,7 @@ Jetpack_Sync_Functions::home_url(), 'siteurl' => Jetpack_Sync_Functions::site_url(), - 'WP_HOME' => Jetpack_Constants::is_defined( 'WP_HOME' ) ? Jetpack_Constants::get_constant( 'WP_HOME' ) : '', - 'WP_SITEURL' => Jetpack_Constants::is_defined( 'WP_SITEURL' ) ? Jetpack_Constants::get_constant( 'WP_SITEURL' ) : '', + 'WP_HOME' => Constants_Manager::is_defined( 'WP_HOME' ) ? Constants_Manager::get_constant( 'WP_HOME' ) : '', + 'WP_SITEURL' => Constants_Manager::is_defined( 'WP_SITEURL' ) ? Constants_Manager::get_constant( 'WP_SITEURL' ) : '', ); $debug_info['idc_urls'] = array( diff --git a/class.jetpack-data.php b/class.jetpack-data.php index 2d762866fc51..53c48681a9a2 100644 --- a/class.jetpack-data.php +++ b/class.jetpack-data.php @@ -1,5 +1,7 @@ production ) ? (array) $preset_extensions_manifest->production : array(); - if ( Jetpack_Constants::is_true( 'JETPACK_BETA_BLOCKS' ) ) { + if ( Constants_Manager::is_true( 'JETPACK_BETA_BLOCKS' ) ) { $beta_extensions = isset( $preset_extensions_manifest->beta ) ? (array) $preset_extensions_manifest->beta : array(); return array_unique( array_merge( $preset_extensions, $beta_extensions ) ); } @@ -548,7 +550,7 @@ public static function enqueue_block_editor_assets() { } $rtl = is_rtl() ? '.rtl' : ''; - $beta = Jetpack_Constants::is_true( 'JETPACK_BETA_BLOCKS' ) ? '-beta' : ''; + $beta = Constants_Manager::is_true( 'JETPACK_BETA_BLOCKS' ) ? '-beta' : ''; $blocks_dir = self::get_blocks_directory(); $editor_script = plugins_url( "{$blocks_dir}editor{$beta}.js", JETPACK__PLUGIN_FILE ); diff --git a/class.jetpack-options.php b/class.jetpack-options.php index fcb7fbc0ab38..4cf6bf28b7b3 100644 --- a/class.jetpack-options.php +++ b/class.jetpack-options.php @@ -1,5 +1,6 @@ 'Activate/Deactivate a Plugin on your Jetpack Site, or set automatic updates', @@ -291,7 +294,7 @@ protected function deactivate() { protected function update() { $query_args = $this->query_args(); if ( isset( $query_args['autoupdate'] ) && $query_args['autoupdate'] ) { - Jetpack_Constants::set_constant( 'JETPACK_PLUGIN_AUTOUPDATE', true ); + Constants_Manager::set_constant( 'JETPACK_PLUGIN_AUTOUPDATE', true ); } wp_clean_plugins_cache(); ob_start(); diff --git a/json-endpoints/jetpack/class.jetpack-json-api-user-create-endpoint.php b/json-endpoints/jetpack/class.jetpack-json-api-user-create-endpoint.php index bd71249b2254..dfb1f7b4974c 100644 --- a/json-endpoints/jetpack/class.jetpack-json-api-user-create-endpoint.php +++ b/json-endpoints/jetpack/class.jetpack-json-api-user-create-endpoint.php @@ -1,5 +1,7 @@ query_args(); if ( isset( $query_args['invite_accepted'] ) && $query_args['invite_accepted'] ) { - Jetpack_Constants::set_constant( 'JETPACK_INVITE_ACCEPTED', true ); + Constants_Manager::set_constant( 'JETPACK_INVITE_ACCEPTED', true ); } if ( ! $user ) { diff --git a/modules/protect.php b/modules/protect.php index 334439fc29fe..b3cdbb14ca39 100644 --- a/modules/protect.php +++ b/modules/protect.php @@ -12,6 +12,8 @@ * Additional Search Queries: security, jetpack protect, secure, protection, botnet, brute force, protect, login, bot, password, passwords, strong passwords, strong password, wp-login.php, protect admin */ +use Automattic\Jetpack\Constants\Manager as Constants_Manager; + include_once JETPACK__PLUGIN_DIR . 'modules/protect/shared-functions.php'; class Jetpack_Protect_Module { @@ -438,7 +440,7 @@ function check_login_ability( $preauth = false ) { /** * JETPACK_ALWAYS_PROTECT_LOGIN will always disable the login page, and use a page provided by Jetpack. */ - if ( Jetpack_Constants::is_true( 'JETPACK_ALWAYS_PROTECT_LOGIN' ) ) { + if ( Constants_Manager::is_true( 'JETPACK_ALWAYS_PROTECT_LOGIN' ) ) { $this->kill_login(); } diff --git a/modules/search/class.jetpack-search-helpers.php b/modules/search/class.jetpack-search-helpers.php index 27526b4c36d2..462f71dc2bfe 100644 --- a/modules/search/class.jetpack-search-helpers.php +++ b/modules/search/class.jetpack-search-helpers.php @@ -7,6 +7,8 @@ * @since 5.8.0 */ +use Automattic\Jetpack\Constants\Manager as Constants_Manager; + /** * Various helper functions for reuse throughout the Jetpack Search code. * @@ -659,8 +661,8 @@ public static function are_filters_by_widget_disabled() { */ public static function site_has_vip_index() { $has_vip_index = ( - Jetpack_Constants::is_defined( 'JETPACK_SEARCH_VIP_INDEX' ) && - Jetpack_Constants::get_constant( 'JETPACK_SEARCH_VIP_INDEX' ) + Constants_Manager::is_defined( 'JETPACK_SEARCH_VIP_INDEX' ) && + Constants_Manager::get_constant( 'JETPACK_SEARCH_VIP_INDEX' ) ); /** diff --git a/modules/shortcodes/crowdsignal.php b/modules/shortcodes/crowdsignal.php index f043d001c456..14f84fde8ae0 100644 --- a/modules/shortcodes/crowdsignal.php +++ b/modules/shortcodes/crowdsignal.php @@ -18,6 +18,8 @@ * @package Jetpack */ +use Automattic\Jetpack\Constants\Manager as Constants_Manager; + // Keep compatibility with the PollDaddy plugin. if ( ! class_exists( 'CrowdsignalShortcode' ) @@ -213,7 +215,7 @@ public function crowdsignal_shortcode( $atts ) { ); $inline = ! in_the_loop() - && ! Jetpack_Constants::is_defined( 'TESTING_IN_JETPACK' ); + && ! Constants_Manager::is_defined( 'TESTING_IN_JETPACK' ); $no_script = false; $infinite_scroll = false; diff --git a/modules/theme-tools/featured-content.php b/modules/theme-tools/featured-content.php index 1df0f069c67a..7a33ddbff82c 100644 --- a/modules/theme-tools/featured-content.php +++ b/modules/theme-tools/featured-content.php @@ -1,5 +1,7 @@ + + + tests/php + + + diff --git a/packages/constants/src/Manager.php b/packages/constants/src/Manager.php new file mode 100644 index 000000000000..ff3b03dfb90d --- /dev/null +++ b/packages/constants/src/Manager.php @@ -0,0 +1,109 @@ +assertTrue( Constants_Manager::is_defined( 'TEST' ) ); + } + + function test_jetpack_constants_is_defined_false_when_constant_not_set() { + $this->assertFalse( Constants_Manager::is_defined( 'UNDEFINED' ) ); + } + + function test_jetpack_constants_is_defined_true_when_set_with_define() { + $this->assertTrue( Constants_Manager::is_defined( 'JETPACK__VERSION' ) ); + } + + function test_jetpack_constants_is_defined_when_constant_set_to_null() { + Constants_Manager::set_constant( 'TEST', null ); + $this->assertTrue( Constants_Manager::is_defined( 'TEST' ) ); + } + + // Constants_Manager::get_constant() + + function test_jetpack_constants_default_to_constant() { + $this->assertEquals( Constants_Manager::get_constant( 'JETPACK__VERSION' ), JETPACK__VERSION ); + } + + function test_jetpack_constants_get_constant_null_when_not_set() { + $this->assertNull( Constants_Manager::get_constant( 'UNDEFINED' ) ); + } + + function test_jetpack_constants_can_override_previously_defined_constant() { + $test_version = '1.0.0'; + Constants_Manager::set_constant( 'JETPACK__VERSION', $test_version ); + $this->assertEquals( Constants_Manager::get_constant( 'JETPACK__VERSION' ), $test_version ); + } + + function test_jetpack_constants_override_to_null_gets_null() { + Constants_Manager::set_constant( 'JETPACK__VERSION', null ); + $this->assertNull( Constants_Manager::get_constant( 'JETPACK__VERSION' ) ); + } + + // Constants_Manager::set_constant() + + function test_jetpack_constants_set_constants_adds_to_set_constants_array() { + $key = 'TEST'; + Constants_Manager::set_constant( $key, '1' ); + $this->assertArrayHasKey( $key, Constants_Manager::$set_constants ); + $this->assertEquals( '1', Constants_Manager::$set_constants[ $key ] ); + } + + // Constants_Manager::clear_constants() + + function test_jetpack_constants_can_clear_all_constants() { + Constants_Manager::set_constant( 'JETPACK__VERSION', '1.0.0' ); + Constants_Manager::clear_constants(); + $this->assertEmpty( Constants_Manager::$set_constants ); + } + + // Constants_Manager::clear_single_constant() + + function test_jetpack_constants_can_clear_single_constant() { + Constants_Manager::set_constant( 'FIRST', '1' ); + Constants_Manager::set_constant( 'SECOND', '2' ); + + $this->assertCount( 2, Constants_Manager::$set_constants ); + + Constants_Manager::clear_single_constant( 'FIRST' ); + + $this->assertCount( 1, Constants_Manager::$set_constants ); + $this->assertContains( 'SECOND', array_keys( Constants_Manager::$set_constants ) ); + } + + function test_jetpack_constants_can_clear_single_constant_when_null() { + Constants_Manager::set_constant( 'TEST', null ); + $this->assertCount( 1, Constants_Manager::$set_constants ); + + Constants_Manager::clear_single_constant( 'TEST' ); + + $this->assertEmpty( Constants_Manager::$set_constants ); + } + + // Jetpack_Constant::is_true + function test_jetpack_constants_is_true_method() { + $this->assertFalse( Constants_Manager::is_true( 'FOO' ), 'unset constant returns true' ); + Constants_Manager::set_constant( 'FOO', false ); + + $this->assertFalse( Constants_Manager::is_true( 'FOO' ), 'false constant returns true' ); + Constants_Manager::set_constant( 'FOO', true ); + + $this->assertTrue( Constants_Manager::is_true( 'FOO' ), 'true constant returns false'); + } +} diff --git a/packages/options/src/Manager.php b/packages/options/src/Manager.php index 8f031fe83c5f..2723b1bd69b6 100644 --- a/packages/options/src/Manager.php +++ b/packages/options/src/Manager.php @@ -7,6 +7,8 @@ namespace Automattic\Jetpack\Options; +use Automattic\Jetpack\Constants\Manager as Constants_Manager; + /** * The Jetpack Options Manager class that is used as a single gateway between WordPress options API * and Jetpack. @@ -277,7 +279,7 @@ function get_raw_option( $name, $default = null ) { * @return bool */ function bypass_raw_option( $name ) { - if ( \Jetpack_Constants::get_constant( 'JETPACK_DISABLE_RAW_OPTIONS' ) ) { + if ( Constants_Manager::get_constant( 'JETPACK_DISABLE_RAW_OPTIONS' ) ) { return true; } /** diff --git a/sync/class.jetpack-sync-actions.php b/sync/class.jetpack-sync-actions.php index 3f137d840e8d..3ed60732b0a3 100644 --- a/sync/class.jetpack-sync-actions.php +++ b/sync/class.jetpack-sync-actions.php @@ -1,5 +1,7 @@ Jetpack_Constants::is_true( 'JETPACK_PLUGIN_AUTOUPDATE' ), + 'is_autoupdate' => Constants_Manager::is_true( 'JETPACK_PLUGIN_AUTOUPDATE' ), ); $errors = $this->get_errors( $upgrader->skin ); if ( $errors ) { diff --git a/sync/class.jetpack-sync-module-posts.php b/sync/class.jetpack-sync-module-posts.php index 0384b64ffe1d..6874ff47ae80 100644 --- a/sync/class.jetpack-sync-module-posts.php +++ b/sync/class.jetpack-sync-module-posts.php @@ -1,5 +1,7 @@ (bool) Jetpack_Constants::get_constant( 'DOING_AUTOSAVE' ), + 'is_auto_save' => (bool) Constants_Manager::get_constant( 'DOING_AUTOSAVE' ), 'previous_status' => $previous_status, 'just_published' => $just_published, 'is_gutenberg_meta_box_update' => $this->is_gutenberg_meta_box_update(), diff --git a/sync/class.jetpack-sync-module-protect.php b/sync/class.jetpack-sync-module-protect.php index a8dcd43e83ed..98e572ef37bd 100644 --- a/sync/class.jetpack-sync-module-protect.php +++ b/sync/class.jetpack-sync-module-protect.php @@ -1,5 +1,7 @@ has_login_ability() && ! Jetpack_Constants::is_true( 'XMLRPC_REQUEST' ) ) { + if ( $protect->has_login_ability() && ! Constants_Manager::is_true( 'XMLRPC_REQUEST' ) ) { do_action( 'jetpack_valid_failed_login_attempt', $failed_attempt ); } } diff --git a/sync/class.jetpack-sync-module-updates.php b/sync/class.jetpack-sync-module-updates.php index 4da4414fc073..133007260ec3 100644 --- a/sync/class.jetpack-sync-module-updates.php +++ b/sync/class.jetpack-sync-module-updates.php @@ -1,5 +1,7 @@ add_flags( $user_id, array( 'invitation_accepted' => true ) ); } /** @@ -267,7 +269,7 @@ function add_user_to_blog_handler( $user_id, $old_user_data = null ) { return; } - if ( Jetpack_Constants::is_true( 'JETPACK_INVITE_ACCEPTED' ) ) { + if ( Constants_Manager::is_true( 'JETPACK_INVITE_ACCEPTED' ) ) { $this->add_flags( $user_id, array( 'invitation_accepted' => true ) ); } /** diff --git a/sync/class.jetpack-sync-sender.php b/sync/class.jetpack-sync-sender.php index 21f914819310..76748bfc85e4 100644 --- a/sync/class.jetpack-sync-sender.php +++ b/sync/class.jetpack-sync-sender.php @@ -1,5 +1,7 @@ verify_xml_rpc_signature(); - if ( Jetpack_Constants::is_true( 'XMLRPC_REQUEST' ) && + if ( Constants_Manager::is_true( 'XMLRPC_REQUEST' ) && ! is_wp_error( $verified_user ) && $verified_user ) { @@ -207,7 +209,7 @@ public function do_sync_for_queue( $queue ) { } /* Don't make the request block till we finish, if possible. */ - if ( Jetpack_Constants::is_true( 'REST_REQUEST' ) || Jetpack_Constants::is_true('XMLRPC_REQUEST' ) ) { + if ( Constants_Manager::is_true( 'REST_REQUEST' ) || Constants_Manager::is_true('XMLRPC_REQUEST' ) ) { $this->fastcgi_finish_request(); } diff --git a/tests/php/3rd-party/test_class.jetpack-domain-mapping.php b/tests/php/3rd-party/test_class.jetpack-domain-mapping.php index 3e53b86331ba..70aa5efe0ee1 100644 --- a/tests/php/3rd-party/test_class.jetpack-domain-mapping.php +++ b/tests/php/3rd-party/test_class.jetpack-domain-mapping.php @@ -1,5 +1,7 @@ get_jetpack_sync_filters() as $filter ) { remove_all_filters( $filter ); } @@ -35,7 +37,7 @@ function test_domain_mapping_should_not_try_to_hook_when_sunrise_disable() { } function test_domain_mapping_should_stop_search_after_hooking_once() { - Jetpack_Constants::set_constant( 'SUNRISE', true ); + Constants_Manager::set_constant( 'SUNRISE', true ); $stub = $this->getMockBuilder( 'MockDomainMapping' ) ->setMethods( array( 'hook_wordpress_mu_domain_mapping', 'hook_wpmu_dev_domain_mapping' ) ) @@ -55,7 +57,7 @@ function test_domain_mapping_should_stop_search_after_hooking_once() { } function test_domain_mapping_mu_domain_mapping_not_hooked_when_function_not_exists() { - Jetpack_Constants::set_constant( 'SUNRISE_LOADED', true ); + Constants_Manager::set_constant( 'SUNRISE_LOADED', true ); $stub = $this->getMockBuilder( 'MockDomainMapping' ) ->setMethods( array( 'function_exists' ) ) @@ -74,7 +76,7 @@ function test_domain_mapping_mu_domain_mapping_not_hooked_when_function_not_exis } function test_domain_mapping_mu_domain_mapping_hooked_when_function_exists() { - Jetpack_Constants::set_constant( 'SUNRISE_LOADED', true ); + Constants_Manager::set_constant( 'SUNRISE_LOADED', true ); $stub = $this->getMockBuilder( 'MockDomainMapping' ) ->setMethods( array( 'function_exists' ) ) diff --git a/tests/php/general/test-class.jetpack-constants.php b/tests/php/general/test-class.jetpack-constants.php deleted file mode 100644 index ed626a7c8d8b..000000000000 --- a/tests/php/general/test-class.jetpack-constants.php +++ /dev/null @@ -1,100 +0,0 @@ -assertTrue( Jetpack_Constants::is_defined( 'TEST' ) ); - } - - function test_jetpack_constants_is_defined_false_when_constant_not_set() { - $this->assertFalse( Jetpack_Constants::is_defined( 'UNDEFINED' ) ); - } - - function test_jetpack_constants_is_defined_true_when_set_with_define() { - $this->assertTrue( Jetpack_Constants::is_defined( 'JETPACK__VERSION' ) ); - } - - function test_jetpack_constants_is_defined_when_constant_set_to_null() { - Jetpack_Constants::set_constant( 'TEST', null ); - $this->assertTrue( Jetpack_Constants::is_defined( 'TEST' ) ); - } - - // Jetpack_Constants::get_constant() - - function test_jetpack_constants_default_to_constant() { - $this->assertEquals( Jetpack_Constants::get_constant( 'JETPACK__VERSION' ), JETPACK__VERSION ); - } - - function test_jetpack_constants_get_constant_null_when_not_set() { - $this->assertNull( Jetpack_Constants::get_constant( 'UNDEFINED' ) ); - } - - function test_jetpack_constants_can_override_previously_defined_constant() { - $test_version = '1.0.0'; - Jetpack_Constants::set_constant( 'JETPACK__VERSION', $test_version ); - $this->assertEquals( Jetpack_Constants::get_constant( 'JETPACK__VERSION' ), $test_version ); - } - - function test_jetpack_constants_override_to_null_gets_null() { - Jetpack_Constants::set_constant( 'JETPACK__VERSION', null ); - $this->assertNull( Jetpack_Constants::get_constant( 'JETPACK__VERSION' ) ); - } - - // Jetpack_Constants::set_constant() - - function test_jetpack_constants_set_constants_adds_to_set_constants_array() { - $key = 'TEST'; - Jetpack_Constants::set_constant( $key, '1' ); - $this->assertArrayHasKey( $key, Jetpack_Constants::$set_constants ); - $this->assertEquals( '1', Jetpack_Constants::$set_constants[ $key ] ); - } - - // Jetpack_Constants::clear_constants() - - function test_jetpack_constants_can_clear_all_constants() { - Jetpack_Constants::set_constant( 'JETPACK__VERSION', '1.0.0' ); - Jetpack_Constants::clear_constants(); - $this->assertEmpty( Jetpack_Constants::$set_constants ); - } - - // Jetpack_Constants::clear_single_constant() - - function test_jetpack_constants_can_clear_single_constant() { - Jetpack_Constants::set_constant( 'FIRST', '1' ); - Jetpack_Constants::set_constant( 'SECOND', '2' ); - - $this->assertCount( 2, Jetpack_Constants::$set_constants ); - - Jetpack_Constants::clear_single_constant( 'FIRST' ); - - $this->assertCount( 1, Jetpack_Constants::$set_constants ); - $this->assertContains( 'SECOND', array_keys( Jetpack_Constants::$set_constants ) ); - } - - function test_jetpack_constants_can_clear_single_constant_when_null() { - Jetpack_Constants::set_constant( 'TEST', null ); - $this->assertCount( 1, Jetpack_Constants::$set_constants ); - - Jetpack_Constants::clear_single_constant( 'TEST' ); - - $this->assertEmpty( Jetpack_Constants::$set_constants ); - } - - // Jetpack_Constant::is_true - function test_jetpack_constants_is_true_method() { - $this->assertFalse( Jetpack_Constants::is_true( 'FOO' ), 'unset constant returns true' ); - Jetpack_Constants::set_constant( 'FOO', false ); - - $this->assertFalse( Jetpack_Constants::is_true( 'FOO' ), 'false constant returns true' ); - Jetpack_Constants::set_constant( 'FOO', true ); - - $this->assertTrue( Jetpack_Constants::is_true( 'FOO' ), 'true constant returns false'); - } -} diff --git a/tests/php/general/test-class.jetpack-options.php b/tests/php/general/test-class.jetpack-options.php index 0241c7091574..83e360a44f60 100644 --- a/tests/php/general/test-class.jetpack-options.php +++ b/tests/php/general/test-class.jetpack-options.php @@ -1,5 +1,7 @@ assertTrue( Jetpack::sync_idc_optin() ); } function test_idc_optin_false_when_constant_false() { - Jetpack_Constants::set_constant( 'JETPACK_SYNC_IDC_OPTIN', false ); + Constants_Manager::set_constant( 'JETPACK_SYNC_IDC_OPTIN', false ); $this->assertFalse( Jetpack::sync_idc_optin() ); } function test_idc_optin_filter_overrides_constant() { - Jetpack_Constants::set_constant( 'JETPACK_SYNC_IDC_OPTIN', true ); + Constants_Manager::set_constant( 'JETPACK_SYNC_IDC_OPTIN', true ); add_filter( 'jetpack_sync_idc_optin', '__return_false' ); $this->assertFalse( Jetpack::sync_idc_optin() ); remove_filter( 'jetpack_sync_idc_optin', '__return_false' ); @@ -429,7 +431,7 @@ function test_sync_error_idc_validation_cleans_up_when_part_of_validation_fails( function test_sync_error_idc_validation_returns_false_and_cleans_up_when_opted_out() { Jetpack_Options::update_option( 'sync_error_idc', Jetpack::get_sync_error_idc_option() ); - Jetpack_Constants::set_constant( 'JETPACK_SYNC_IDC_OPTIN', false ); + Constants_Manager::set_constant( 'JETPACK_SYNC_IDC_OPTIN', false ); $this->assertFalse( Jetpack::validate_sync_error_idc_option() ); $this->assertFalse( Jetpack_Options::get_option( 'sync_error_idc' ) ); @@ -507,27 +509,27 @@ function test_is_staging_site_true_when_sync_error_idc_is_valid() { } function test_is_dev_version_true_with_alpha() { - Jetpack_Constants::set_constant( 'JETPACK__VERSION', '4.3.1-alpha' ); + Constants_Manager::set_constant( 'JETPACK__VERSION', '4.3.1-alpha' ); $this->assertTrue( Jetpack::is_development_version() ); } function test_is_dev_version_true_with_beta() { - Jetpack_Constants::set_constant( 'JETPACK__VERSION', '4.3-beta2' ); + Constants_Manager::set_constant( 'JETPACK__VERSION', '4.3-beta2' ); $this->assertTrue( Jetpack::is_development_version() ); } function test_is_dev_version_true_with_rc() { - Jetpack_Constants::set_constant( 'JETPACK__VERSION', '4.3-rc2' ); + Constants_Manager::set_constant( 'JETPACK__VERSION', '4.3-rc2' ); $this->assertTrue( Jetpack::is_development_version() ); } function test_is_dev_version_false_with_number_dot_number() { - Jetpack_Constants::set_constant( 'JETPACK__VERSION', '4.3' ); + Constants_Manager::set_constant( 'JETPACK__VERSION', '4.3' ); $this->assertFalse( Jetpack::is_development_version() ); } function test_is_dev_version_false_with_number_dot_number_dot_number() { - Jetpack_Constants::set_constant( 'JETPACK__VERSION', '4.3.1' ); + Constants_Manager::set_constant( 'JETPACK__VERSION', '4.3.1' ); $this->assertFalse( Jetpack::is_development_version() ); } @@ -798,7 +800,7 @@ function test_get_assumed_site_creation_date_only_admins() { * @dataProvider get_file_url_for_environment_data_provider */ function test_get_file_url_for_environment( $min_path, $non_min_path, $is_script_debug, $expected, $not_expected ) { - Jetpack_Constants::set_constant( 'SCRIPT_DEBUG', $is_script_debug ); + Constants_Manager::set_constant( 'SCRIPT_DEBUG', $is_script_debug ); $file_url = Jetpack::get_file_url_for_environment( $min_path, $non_min_path ); $this->assertContains( $$expected, $file_url ); diff --git a/tests/php/modules/search/test-class.jetpack-search-helpers.php b/tests/php/modules/search/test-class.jetpack-search-helpers.php index a4d91f0d425f..cc928fd9dff4 100644 --- a/tests/php/modules/search/test-class.jetpack-search-helpers.php +++ b/tests/php/modules/search/test-class.jetpack-search-helpers.php @@ -1,5 +1,7 @@ assertSame( $expected, Jetpack_Search_Helpers::get_max_posts_per_page() ); } @@ -429,7 +431,7 @@ public function test_get_max_posts_per_page( $expected, $has_vip_index ) { * @dataProvider get_max_offset_data */ public function test_get_max_offset( $expected, $has_vip_index ) { - Jetpack_Constants::set_constant( 'JETPACK_SEARCH_VIP_INDEX', $has_vip_index ); + Constants_Manager::set_constant( 'JETPACK_SEARCH_VIP_INDEX', $has_vip_index ); $this->assertSame( $expected, Jetpack_Search_Helpers::get_max_offset() ); } diff --git a/tests/php/sync/test_class.jetpack-sync-callables.php b/tests/php/sync/test_class.jetpack-sync-callables.php index 9d4b6aaaeffb..18ac8d4962e7 100644 --- a/tests/php/sync/test_class.jetpack-sync-callables.php +++ b/tests/php/sync/test_class.jetpack-sync-callables.php @@ -1,5 +1,7 @@ assertTrue( 'http://filteredurl.com' !== Jetpack_Sync_Functions::home_url() ); // Now, without, which should return the filtered URL - Jetpack_Constants::set_constant( 'JETPACK_SYNC_USE_RAW_URL', false ); + Constants_Manager::set_constant( 'JETPACK_SYNC_USE_RAW_URL', false ); $this->assertEquals( $this->__return_filtered_url(), Jetpack_Sync_Functions::home_url() ); - Jetpack_Constants::clear_constants(); + Constants_Manager::clear_constants(); remove_filter( 'option_home', array( $this, '__return_filtered_url' ) ); remove_filter( 'option_siteurl', array( $this, '__return_filtered_url' ) ); @@ -940,7 +942,7 @@ function mock_authenticated_xml_rpc() { $_GET['signature'] = base64_encode( hash_hmac( 'sha1', $normalize , 'secret', true ) ); // call one of the authenticated endpoints - Jetpack_Constants::set_constant( 'XMLRPC_REQUEST', true ); + Constants_Manager::set_constant( 'XMLRPC_REQUEST', true ); $jetpack = Jetpack::init(); $jetpack->xmlrpc_methods( array() ); $jetpack->require_jetpack_authentication(); @@ -948,7 +950,7 @@ function mock_authenticated_xml_rpc() { } function mock_authenticated_xml_rpc_cleanup( $user_id ) { - Jetpack_Constants::clear_constants(); + Constants_Manager::clear_constants(); remove_filter( 'pre_option_jetpack_private_options', array( $this, 'mock_jetpack_private_options' ), 10 ); unset( $_GET['token'] ); diff --git a/tests/php/sync/test_class.jetpack-sync-integration.php b/tests/php/sync/test_class.jetpack-sync-integration.php index 935f99714f89..5a44b6c563e2 100644 --- a/tests/php/sync/test_class.jetpack-sync-integration.php +++ b/tests/php/sync/test_class.jetpack-sync-integration.php @@ -1,5 +1,7 @@ factory->post->create(); @@ -103,7 +105,7 @@ function test_loads_sender_if_listener_queues_actions() { } function test_do_not_load_sender_if_is_cron_and_cron_sync_disabled() { - Jetpack_Constants::set_constant( 'DOING_CRON', true ); + Constants_Manager::set_constant( 'DOING_CRON', true ); $settings = Jetpack_Sync_Settings::get_settings(); $settings['sync_via_cron'] = 0; Jetpack_Sync_Settings::update_settings( $settings ); @@ -113,7 +115,7 @@ function test_do_not_load_sender_if_is_cron_and_cron_sync_disabled() { $this->assertNull( Jetpack_Sync_Actions::$sender ); - Jetpack_Constants::clear_constants(); + Constants_Manager::clear_constants(); Jetpack_Sync_Settings::reset_data(); } diff --git a/tests/php/sync/test_class.jetpack-sync-module-protect.php b/tests/php/sync/test_class.jetpack-sync-module-protect.php index 0b697bba0c5e..341bc6a1762d 100644 --- a/tests/php/sync/test_class.jetpack-sync-module-protect.php +++ b/tests/php/sync/test_class.jetpack-sync-module-protect.php @@ -1,5 +1,7 @@ factory->user->create(); $user = get_userdata( $user_id ); - Jetpack_Constants::set_constant( 'XMLRPC_REQUEST', true ); // fake xmlrpc request + Constants_Manager::set_constant( 'XMLRPC_REQUEST', true ); // fake xmlrpc request Jetpack_Protect_Module::instance()->log_failed_attempt( $user->user_email ); - Jetpack_Constants::clear_single_constant( 'XMLRPC_REQUEST' ); + Constants_Manager::clear_single_constant( 'XMLRPC_REQUEST' ); $this->sender->do_sync(); $action = $this->server_event_storage->get_most_recent_event( 'jetpack_valid_failed_login_attempt' ); diff --git a/tests/php/sync/test_class.jetpack-sync-plugins-updates.php b/tests/php/sync/test_class.jetpack-sync-plugins-updates.php index 5c9d62376a17..b13fafe05915 100644 --- a/tests/php/sync/test_class.jetpack-sync-plugins-updates.php +++ b/tests/php/sync/test_class.jetpack-sync-plugins-updates.php @@ -1,5 +1,7 @@ '', ); - Jetpack_Constants::set_constant( 'JETPACK_PLUGIN_AUTOUPDATE', true ); + Constants_Manager::set_constant( 'JETPACK_PLUGIN_AUTOUPDATE', true ); $this->set_error(); $this->update_bulk_plugins( new WP_Ajax_Upgrader_Skin( $plugin_defaults ) ); @@ -179,7 +181,7 @@ function test_updating_with_autoupdate_constant_results_in_proper_state() { 'api' => '', ); - Jetpack_Constants::set_constant( 'JETPACK_PLUGIN_AUTOUPDATE', true ); + Constants_Manager::set_constant( 'JETPACK_PLUGIN_AUTOUPDATE', true ); $this->update_bulk_plugins( new WP_Ajax_Upgrader_Skin( $plugin_defaults ) ); $this->sender->do_sync(); $updated_plugin = $this->server_event_storage->get_most_recent_event( 'jetpack_plugins_updated' ); diff --git a/tests/php/sync/test_class.jetpack-sync-posts.php b/tests/php/sync/test_class.jetpack-sync-posts.php index 898cd2087ce4..6f1aa1c4b86c 100644 --- a/tests/php/sync/test_class.jetpack-sync-posts.php +++ b/tests/php/sync/test_class.jetpack-sync-posts.php @@ -1,5 +1,7 @@ server_event_storage->get_most_recent_event( 'jetpack_sync_save_post' ); $this->assertFalse( $event->args[3]['is_auto_save'] ); - Jetpack_Constants::set_constant( 'DOING_AUTOSAVE', true ); + Constants_Manager::set_constant( 'DOING_AUTOSAVE', true ); //Performing sync here (even though setup() does it) to sync REQUEST_URI $user_id = $this->factory->user->create(); diff --git a/tests/php/sync/test_class.jetpack-sync-updates.php b/tests/php/sync/test_class.jetpack-sync-updates.php index d61fb0c3e0de..257d50c4455e 100644 --- a/tests/php/sync/test_class.jetpack-sync-updates.php +++ b/tests/php/sync/test_class.jetpack-sync-updates.php @@ -1,5 +1,7 @@ assertFalse( $pagenow === 'update-core.php' ); - Jetpack_Constants::set_constant( 'REST_API_REQUEST', true ); + Constants_Manager::set_constant( 'REST_API_REQUEST', true ); Jetpack_Sync_Modules::get_module( "updates" )->update_core( 'new_version' ); $this->sender->do_sync(); - Jetpack_Constants::clear_single_constant( 'REST_API_REQUEST' ); + Constants_Manager::clear_single_constant( 'REST_API_REQUEST' ); $autoupdate_event = $this->server_event_storage->get_most_recent_event( 'jetpack_sync_core_autoupdated_successfully' ); $event = $this->server_event_storage->get_most_recent_event( 'jetpack_sync_core_updated_successfully' ); diff --git a/tests/php/sync/test_class.jetpack-sync-users.php b/tests/php/sync/test_class.jetpack-sync-users.php index 8b8357e95885..d0d82007a4c8 100644 --- a/tests/php/sync/test_class.jetpack-sync-users.php +++ b/tests/php/sync/test_class.jetpack-sync-users.php @@ -1,5 +1,6 @@ server_event_storage->reset(); // Fake it till you make it - Jetpack_Constants::set_constant( 'JETPACK_INVITE_ACCEPTED', true ); + Constants_Manager::set_constant( 'JETPACK_INVITE_ACCEPTED', true ); // We modify the input here to mimick the same call structure of the update user endpoint. Jetpack_SSO_Helpers::generate_user( $this->get_invite_user_data() ); $this->sender->do_sync(); - Jetpack_Constants::clear_constants(); + Constants_Manager::clear_constants(); $event = $this->server_event_storage->get_most_recent_event( 'jetpack_sync_save_user' ); $this->assertFalse( $event ); @@ -729,12 +730,12 @@ public function test_invite_user_sync_invite_event() { public function test_invite_user_sync_invite_event_false() { $this->server_event_storage->reset(); // Fake it till we make it - Jetpack_Constants::set_constant( 'JETPACK_INVITE_ACCEPTED', false ); + Constants_Manager::set_constant( 'JETPACK_INVITE_ACCEPTED', false ); // We modify the input here to mimick the same call structure of the update user endpoint. Jetpack_SSO_Helpers::generate_user( $this->get_invite_user_data() ); $this->sender->do_sync(); - Jetpack_Constants::clear_constants(); + Constants_Manager::clear_constants(); $event = $this->server_event_storage->get_most_recent_event( 'jetpack_sync_save_user' ); $this->assertFalse( $event );