From 541a41c9a9a7b696ebd81f69a7d38b9dd9cbb296 Mon Sep 17 00:00:00 2001 From: Paul Kang Date: Thu, 10 Apr 2025 13:01:18 -0700 Subject: [PATCH 1/3] Unskipping two tests which now pass, deleting a test for a deprecated option. --- .../WCFacebookCommerceIntegrationTest.php | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/tests/Unit/WCFacebookCommerceIntegrationTest.php b/tests/Unit/WCFacebookCommerceIntegrationTest.php index a5c952b7c..3b6118104 100644 --- a/tests/Unit/WCFacebookCommerceIntegrationTest.php +++ b/tests/Unit/WCFacebookCommerceIntegrationTest.php @@ -416,29 +416,6 @@ function ( bool $status ) { $this->assertFalse( has_filter( 'facebook_for_woocommerce_allow_full_batch_api_sync' ) ); } - /** - * Tests default allow full batch api sync uses facebook_for_woocommerce_allow_full_batch_api_sync filter - * to overwrite allowance status. - * - * @return void - */ - public function test_allow_full_batch_api_sync_uses_allow_full_batch_api_sync_filter() { - $this->markTestSkipped( 'Some problems with phpunit polyfills notices handling.' ); - - $this->add_filter_with_safe_teardown( - 'facebook_for_woocommerce_allow_full_batch_api_sync', - function ( bool $status ) { - return false; - } - ); - - $status = $this->integration->allow_full_batch_api_sync(); - - $this->assertFalse( $status ); - $this->assertFalse( has_filter( 'facebook_for_woocommerce_block_full_batch_api_sync' ) ); - $this->assertTrue( has_filter( 'facebook_for_woocommerce_allow_full_batch_api_sync' ) ); - } - /** * Tests plugin enqueues scripts and styles for non admin user for non plugin settings screens. * @@ -2176,8 +2153,6 @@ function ( $pixel_install_time ) { * @return void */ public function test_get_js_sdk_version_returns_id_from_options_using_no_filter() { - $this->markTestSkipped( 'get_js_sdk_version method is called in constructor which makes it impossible to test it in isolation w/o refactoring the constructor.' ); - add_option( WC_Facebookcommerce_Integration::OPTION_JS_SDK_VERSION, 'v1.0.0' ); $this->teardown_callback_category_safely( 'wc_facebook_js_sdk_version' ); @@ -2192,8 +2167,6 @@ public function test_get_js_sdk_version_returns_id_from_options_using_no_filter( * @return void */ public function test_get_js_sdk_version_returns_id_with_filter() { - $this->markTestSkipped( 'get_js_sdk_version method is called in constructor which makes it impossible to test it in isolation w/o refactoring the constructor.' ); - $this->add_filter_with_safe_teardown( 'wc_facebook_js_sdk_version', function ( $js_sdk_version ) { From f73036909d858286e5e96d6d623a6f5393686e63 Mon Sep 17 00:00:00 2001 From: Paul Kang Date: Thu, 10 Apr 2025 13:33:44 -0700 Subject: [PATCH 2/3] final change to prevent bogus error logging messgaes --- tests/Unit/WCFacebookCommerceIntegrationTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Unit/WCFacebookCommerceIntegrationTest.php b/tests/Unit/WCFacebookCommerceIntegrationTest.php index 3b6118104..e2ee17ac7 100644 --- a/tests/Unit/WCFacebookCommerceIntegrationTest.php +++ b/tests/Unit/WCFacebookCommerceIntegrationTest.php @@ -69,6 +69,8 @@ public function setUp(): void { /* Making sure no options are set before the test. */ delete_option( WC_Facebookcommerce_Pixel::SETTINGS_KEY ); delete_option( WC_Facebookcommerce_Integration::SETTING_FACEBOOK_PIXEL_ID ); + // Needed to prevent error logs in tests. + WC_Facebookcommerce_Utils::$ems = 'dummy_ems_id'; } /** From bbd64eb27cfe5e0da63110fe457ebcbfb95031af Mon Sep 17 00:00:00 2001 From: Paul Kang Date: Thu, 17 Apr 2025 17:18:04 -0700 Subject: [PATCH 3/3] Fixing lint issues for adminMessageHandler.php --- includes/Framework/AdminMessageHandler.php | 57 +++++++++++++--------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/includes/Framework/AdminMessageHandler.php b/includes/Framework/AdminMessageHandler.php index 3cff57669..7df5b9c8c 100644 --- a/includes/Framework/AdminMessageHandler.php +++ b/includes/Framework/AdminMessageHandler.php @@ -1,17 +1,16 @@ get_message_id() == $message_id_get_name ) { $memo = get_transient( self::MESSAGE_TRANSIENT_PREFIX . $message_id_get_name ); - if ( isset( $memo['errors'] ) ) $this->errors = $memo['errors']; - if ( isset( $memo['warnings'] ) ) $this->warnings = $memo['warnings']; - if ( isset( $memo['infos'] ) ) $this->infos = $memo['infos']; - if ( isset( $memo['messages'] ) ) $this->messages = $memo['messages']; + if ( isset( $memo['errors'] ) ) { + $this->errors = $memo['errors']; + } + if ( isset( $memo['warnings'] ) ) { + $this->warnings = $memo['warnings']; + } + if ( isset( $memo['infos'] ) ) { + $this->infos = $memo['infos']; + } + if ( isset( $memo['messages'] ) ) { + $this->messages = $memo['messages']; + } $this->clear_messages( $message_id_get_name ); } } @@ -179,7 +186,7 @@ public function add_message( $message ) { * @return int error message count */ public function error_count() { - return sizeof( $this->errors ); + return count( $this->errors ); } @@ -191,7 +198,7 @@ public function error_count() { * @return int warning message count */ public function warning_count() { - return sizeof( $this->warnings ); + return count( $this->warnings ); } @@ -203,7 +210,7 @@ public function warning_count() { * @return int info message count */ public function info_count() { - return sizeof( $this->infos ); + return count( $this->infos ); } @@ -214,7 +221,7 @@ public function info_count() { * @return int message count */ public function message_count() { - return sizeof( $this->messages ); + return count( $this->messages ); } @@ -326,11 +333,14 @@ public function get_message( $index ) { * } */ public function show_messages( $params = [] ) { - $params = wp_parse_args( $params, array( - 'capabilities' => array( - 'manage_woocommerce', - ), - ) ); + $params = wp_parse_args( + $params, + array( + 'capabilities' => array( + 'manage_woocommerce', + ), + ) + ); $check_user_capabilities = []; // check if user has at least one capability that allows to see messages foreach ( $params['capabilities'] as $capability ) { @@ -361,11 +371,12 @@ public function show_messages( $params = [] ) { * Redirection hook which persists messages into session data. * * @since 1.0.0 - * @param string $location the URL to redirect to - * @param int $status the http status + * @param string $location the URL to redirect to + * @param int $_status the http status * @return string the URL to redirect to */ - public function redirect( $location, $status ) { + // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter + public function redirect( $location, $_status ) { // add the admin message id param to the if ( $this->set_messages() ) { $location = add_query_arg( self::MESSAGE_ID_GET_NAME, $this->get_message_id(), $location ); @@ -383,7 +394,9 @@ public function redirect( $location, $status ) { * @return string unique identifier */ protected function get_message_id() { - if ( ! isset( $this->message_id ) ) $this->message_id = __FILE__; + if ( ! isset( $this->message_id ) ) { + $this->message_id = __FILE__; + } return wp_create_nonce( $this->message_id ); } }