From 252e9ed04f2e522f6ad7d0cb103daa3e42e84404 Mon Sep 17 00:00:00 2001
From: Miguel Perez Pellicer <5908855+puntope@users.noreply.github.com>
Date: Tue, 30 Jan 2024 11:46:49 -0400
Subject: [PATCH 1/5] Fix PHPCS in GoogleListingsAndAdsPlugin
---
.../GoogleListingsAndAdsPlugin.php | 37 ++++++++++++-------
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/src/Infrastructure/GoogleListingsAndAdsPlugin.php b/src/Infrastructure/GoogleListingsAndAdsPlugin.php
index fa487fb7c1..426a0382d7 100644
--- a/src/Infrastructure/GoogleListingsAndAdsPlugin.php
+++ b/src/Infrastructure/GoogleListingsAndAdsPlugin.php
@@ -34,6 +34,7 @@ final class GoogleListingsAndAdsPlugin implements Plugin {
/**
* The client ID.
+ *
* @var string
*/
private $client_id;
@@ -116,12 +117,14 @@ function () {
}
);
- add_action( 'login_form_jetpack_json_api_authorization', array( $this, 'login_form_json_api_authorization' ) );
-
- add_filter('jetpack_xmlrpc_test_connection_response', function (){
- return '1.40';
- });
+ add_action( 'login_form_jetpack_json_api_authorization', [ $this, 'login_form_json_api_authorization' ] );
+ add_filter(
+ 'jetpack_xmlrpc_test_connection_response',
+ function () {
+ return '1.40';
+ }
+ );
}
/**
@@ -155,9 +158,9 @@ protected function maybe_register_services(): void {
* Handles the login action for Authorizing the JSON API
*/
public function login_form_json_api_authorization() {
- add_action( 'wp_login', array( $this, 'store_json_api_authorization_token' ), 10, 2 );
- add_action( 'login_form', array( $this, 'preserve_action_in_login_form_for_json_api_authorization' ) );
- add_filter( 'site_url', array( $this, 'post_login_form_to_signed_url' ), 10, 3 );
+ add_action( 'wp_login', [ $this, 'store_json_api_authorization_token' ], 10, 2 );
+ add_action( 'login_form', [ $this, 'preserve_action_in_login_form_for_json_api_authorization' ] );
+ add_filter( 'site_url', [ $this, 'post_login_form_to_signed_url' ], 10, 3 );
}
/**
@@ -167,10 +170,16 @@ public function login_form_json_api_authorization() {
* @param WP_User $user User logged in.
*/
public function store_json_api_authorization_token( $user_login, $user ) {
- $data = json_decode( base64_decode( stripslashes( $_REQUEST['data'] ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
- $this->client_id = $data->client_id;
- add_filter( 'login_redirect', array( $this, 'add_token_to_login_redirect_json_api_authorization' ), 10, 3 );
- add_filter( 'allowed_redirect_hosts', array( $this, 'allow_wpcom_public_api_domain' ) );
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+ $data = isset( $_REQUEST['data'] ) ? json_decode( base64_decode( wp_unslash( $_REQUEST['data'] ) ) ) : null;
+
+ if ( is_null( $data ) ) {
+ return;
+ }
+
+ $this->client_id = sanitize_text_field( $data->client_id );
+ add_filter( 'login_redirect', [ $this, 'add_token_to_login_redirect_json_api_authorization' ], 10, 3 );
+ add_filter( 'allowed_redirect_hosts', [ $this, 'allow_wpcom_public_api_domain' ] );
$token = wp_generate_password( 32, false );
update_user_meta( $user->ID, 'jetpack_json_api_' . $this->client_id, $token );
}
@@ -219,11 +228,11 @@ public function post_login_form_to_signed_url( $url, $path, $scheme ) {
public function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) {
return add_query_arg(
urlencode_deep(
- array(
+ [
'jetpack-code' => get_user_meta( $user->ID, 'jetpack_json_api_' . $this->client_id, true ),
'jetpack-user-id' => (int) $user->ID,
'jetpack-state' => '',
- )
+ ]
),
$redirect_to
);
From 75a61efe748187c8abc20caa652ec700d6b6081b Mon Sep 17 00:00:00 2001
From: Miguel Perez Pellicer <5908855+puntope@users.noreply.github.com>
Date: Tue, 30 Jan 2024 12:45:01 -0400
Subject: [PATCH 2/5] Solve PHPCS
---
src/Infrastructure/GoogleListingsAndAdsPlugin.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Infrastructure/GoogleListingsAndAdsPlugin.php b/src/Infrastructure/GoogleListingsAndAdsPlugin.php
index 426a0382d7..2739d78bed 100644
--- a/src/Infrastructure/GoogleListingsAndAdsPlugin.php
+++ b/src/Infrastructure/GoogleListingsAndAdsPlugin.php
@@ -170,7 +170,7 @@ public function login_form_json_api_authorization() {
* @param WP_User $user User logged in.
*/
public function store_json_api_authorization_token( $user_login, $user ) {
- // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized after via sanitize_text_field
$data = isset( $_REQUEST['data'] ) ? json_decode( base64_decode( wp_unslash( $_REQUEST['data'] ) ) ) : null;
if ( is_null( $data ) ) {
From c4fde99ac9c75f497d7e1550c928e3e07ddb6f05 Mon Sep 17 00:00:00 2001
From: Miguel Perez Pellicer <5908855+puntope@users.noreply.github.com>
Date: Tue, 30 Jan 2024 12:59:20 -0400
Subject: [PATCH 3/5] Remove old wrong code
---
.../GoogleListingsAndAdsPlugin.php | 112 ------------------
src/Product/ProductHelper.php | 2 +-
2 files changed, 1 insertion(+), 113 deletions(-)
diff --git a/src/Infrastructure/GoogleListingsAndAdsPlugin.php b/src/Infrastructure/GoogleListingsAndAdsPlugin.php
index 2739d78bed..8275f0d383 100644
--- a/src/Infrastructure/GoogleListingsAndAdsPlugin.php
+++ b/src/Infrastructure/GoogleListingsAndAdsPlugin.php
@@ -32,13 +32,6 @@ final class GoogleListingsAndAdsPlugin implements Plugin {
*/
private $registered_services;
- /**
- * The client ID.
- *
- * @var string
- */
- private $client_id;
-
/**
* GoogleListingsAndAdsPlugin constructor.
*
@@ -116,15 +109,6 @@ function () {
}
}
);
-
- add_action( 'login_form_jetpack_json_api_authorization', [ $this, 'login_form_json_api_authorization' ] );
-
- add_filter(
- 'jetpack_xmlrpc_test_connection_response',
- function () {
- return '1.40';
- }
- );
}
/**
@@ -153,100 +137,4 @@ protected function maybe_register_services(): void {
$registered = true;
}
-
- /**
- * Handles the login action for Authorizing the JSON API
- */
- public function login_form_json_api_authorization() {
- add_action( 'wp_login', [ $this, 'store_json_api_authorization_token' ], 10, 2 );
- add_action( 'login_form', [ $this, 'preserve_action_in_login_form_for_json_api_authorization' ] );
- add_filter( 'site_url', [ $this, 'post_login_form_to_signed_url' ], 10, 3 );
- }
-
- /**
- * If someone logs in to approve API access, store the Access Code in usermeta.
- *
- * @param string $user_login Unused.
- * @param WP_User $user User logged in.
- */
- public function store_json_api_authorization_token( $user_login, $user ) {
- // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized after via sanitize_text_field
- $data = isset( $_REQUEST['data'] ) ? json_decode( base64_decode( wp_unslash( $_REQUEST['data'] ) ) ) : null;
-
- if ( is_null( $data ) ) {
- return;
- }
-
- $this->client_id = sanitize_text_field( $data->client_id );
- add_filter( 'login_redirect', [ $this, 'add_token_to_login_redirect_json_api_authorization' ], 10, 3 );
- add_filter( 'allowed_redirect_hosts', [ $this, 'allow_wpcom_public_api_domain' ] );
- $token = wp_generate_password( 32, false );
- update_user_meta( $user->ID, 'jetpack_json_api_' . $this->client_id, $token );
- }
-
- /**
- * Make sure the POSTed request is handled by the same action.
- */
- public function preserve_action_in_login_form_for_json_api_authorization() {
- $http_host = isset( $_SERVER['HTTP_HOST'] ) ? wp_unslash( $_SERVER['HTTP_HOST'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- escaped with esc_url below.
- $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- escaped with esc_url below.
- echo "\n";
- echo "\n";
- }
-
- /**
- * Make sure the login form is POSTed to the signed URL so we can reverify the request.
- *
- * @param string $url Redirect URL.
- * @param string $path Path.
- * @param string $scheme URL Scheme.
- */
- public function post_login_form_to_signed_url( $url, $path, $scheme ) {
- if ( 'wp-login.php' !== $path || ( 'login_post' !== $scheme && 'login' !== $scheme ) ) {
- return $url;
- }
- $query_string = isset( $_SERVER['QUERY_STRING'] ) ? wp_unslash( $_SERVER['QUERY_STRING'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
- $parsed_url = wp_parse_url( $url );
- $url = strtok( $url, '?' );
- $url = "$url?{$query_string}";
- if ( ! empty( $parsed_url['query'] ) ) {
- $url .= "&{$parsed_url['query']}";
- }
-
- return $url;
- }
-
- /**
- * Add the Access Code details to the public-api.wordpress.com redirect.
- *
- * @param string $redirect_to URL.
- * @param string $original_redirect_to URL.
- * @param WP_User $user WP_User for the redirect.
- *
- * @return string
- */
- public function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) {
- return add_query_arg(
- urlencode_deep(
- [
- 'jetpack-code' => get_user_meta( $user->ID, 'jetpack_json_api_' . $this->client_id, true ),
- 'jetpack-user-id' => (int) $user->ID,
- 'jetpack-state' => '',
- ]
- ),
- $redirect_to
- );
- }
-
- /**
- * Add public-api.wordpress.com to the safe redirect allowed list - only added when someone allows API access.
- *
- * To be used with a filter of allowed domains for a redirect.
- *
- * @param array $domains Allowed WP.com Environments.
- */
- public function allow_wpcom_public_api_domain( $domains ) {
- $domains[] = 'public-api.wordpress.com';
- return $domains;
- }
}
diff --git a/src/Product/ProductHelper.php b/src/Product/ProductHelper.php
index 0121cfdce1..9956b360ad 100644
--- a/src/Product/ProductHelper.php
+++ b/src/Product/ProductHelper.php
@@ -406,7 +406,7 @@ public function has_notified_creation( WC_Product $product ): bool {
NotificationStatus::NOTIFICATION_PENDING_CREATE,
NotificationStatus::NOTIFICATION_CREATED,
NotificationStatus::NOTIFICATION_UPDATED,
- NotificationStatus::NOTIFICATION_PENDING_UPDATE
+ NotificationStatus::NOTIFICATION_PENDING_UPDATE,
];
return in_array( $this->meta_handler->get_notification_status( $product ), $valid_has_notified_creation_statuses, true ) || $this->is_product_synced( $product );
From 7fd17664f04a2aaff9dd19dcdb32bf021cc3ffb4 Mon Sep 17 00:00:00 2001
From: Miguel Perez Pellicer <5908855+puntope@users.noreply.github.com>
Date: Tue, 30 Jan 2024 13:08:21 -0400
Subject: [PATCH 4/5] Remove unsupported return type
---
src/Google/NotificationsService.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Google/NotificationsService.php b/src/Google/NotificationsService.php
index 92585904d1..d2a262636b 100644
--- a/src/Google/NotificationsService.php
+++ b/src/Google/NotificationsService.php
@@ -116,7 +116,7 @@ private function notification_error( int $item_id, string $topic, string $error
* @param array $args
* @return array|\WP_Error
*/
- protected function do_request( array $args ): \WP_Error|array {
+ protected function do_request( array $args ) {
return Client::remote_request( $args, wp_json_encode( $args['body'] ) );
}
From b4fa9c581db5ea2229b8d8ffbdfefcf352dce363 Mon Sep 17 00:00:00 2001
From: Miguel Perez Pellicer <5908855+puntope@users.noreply.github.com>
Date: Tue, 30 Jan 2024 13:13:58 -0400
Subject: [PATCH 5/5] PHPCS for tests
---
.../Unit/Google/NotificationsServiceTest.php | 169 +++++++++---------
.../Unit/Jobs/ProductNotificationJobTest.php | 41 ++---
tests/Unit/Product/ProductHelperTest.php | 4 +-
tests/Unit/Product/SyncerHooksTest.php | 27 ++-
4 files changed, 123 insertions(+), 118 deletions(-)
diff --git a/tests/Unit/Google/NotificationsServiceTest.php b/tests/Unit/Google/NotificationsServiceTest.php
index 5109cf5086..92db2e2b2a 100644
--- a/tests/Unit/Google/NotificationsServiceTest.php
+++ b/tests/Unit/Google/NotificationsServiceTest.php
@@ -10,107 +10,114 @@
/**
* Class NotificationsServiceTest
+ *
* @group Notifications
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tests\Unit\Google
*/
- class NotificationsServiceTest extends UnitTest {
+class NotificationsServiceTest extends UnitTest {
- /**
- * @var NotificationsService
- */
- public $service;
+ /**
+ * @var NotificationsService
+ */
+ public $service;
- const DUMMY_BLOG_ID = "123";
+ public const DUMMY_BLOG_ID = '123';
- /**
- * Runs before each test is executed.
- */
- public function setUp(): void {
- parent::setUp();
+ /**
+ * Runs before each test is executed.
+ */
+ public function setUp(): void {
+ parent::setUp();
- // Mock the Blog ID from Jetpack
- add_filter('jetpack_options', function ( $value, $name ) {
+ // Mock the Blog ID from Jetpack
+ add_filter(
+ 'jetpack_options',
+ function ( $value, $name ) {
if ( $name === 'id' ) {
return self::DUMMY_BLOG_ID;
}
return $value;
- }, 10, 2 );
-
- }
+ },
+ 10,
+ 2
+ );
+ }
- /**
- * Test if the route is correct
- */
- public function test_route() {
- $this->service = $this->get_mock( [] );
+ /**
+ * Test if the route is correct
+ */
+ public function test_route() {
+ $this->service = $this->get_mock( [] );
+ $blog_id = self::DUMMY_BLOG_ID;
+ $this->assertEquals( $this->service->get_notification_url(), "https://public-api.wordpress.com/wpcom/v2/sites/{$blog_id}/partners/google/notifications" );
+ }
- $blog_id = self::DUMMY_BLOG_ID;
- $this->assertEquals( $this->service->get_notification_url(), "https://public-api.wordpress.com/wpcom/v2/sites/{$blog_id}/partners/google/notifications" );
- }
+ /**
+ * Test notify() function with a call with success response.
+ */
+ public function test_notify() {
+ $this->service = $this->get_mock();
+
+ $topic = 'product.create';
+ $item_id = 1;
+
+ $args = [
+ 'method' => 'POST',
+ 'timeout' => 30,
+ 'headers' => [
+ 'x-woocommerce-topic' => $topic,
+ ],
+ 'body' => [
+ 'item_id' => $item_id,
+ ],
+ 'url' => $this->service->get_notification_url(),
+ ];
+
+ $this->service->expects( $this->once() )->method( 'do_request' )->with( $args )->willReturn( [ 'code' => 200 ] );
+ $this->assertTrue( $this->service->notify( $item_id, $topic ) );
+ }
- /**
- * Test notify() function with a call with success response.
- */
- public function test_notify() {
- $this->service = $this->get_mock();
+ /**
+ * Test notify() function with a call with wp_error response.
+ */
+ public function test_notify_wp_error() {
+ $this->service = $this->get_mock();
- $topic = 'product.create';
- $item_id = 1;
+ $this->service->expects( $this->once() )->method( 'do_request' )->willReturn( new \WP_Error( 'error', 'error message' ) );
+ $this->assertFalse( $this->service->notify( 1, 'topic' ) );
+ $this->assertEquals( did_action( 'woocommerce_gla_error' ), 1 );
+ }
- $args = [
- 'method' => 'POST',
- 'timeout' => 30,
- 'headers' => [
- 'x-woocommerce-topic' => $topic
- ],
- 'body' => [
- 'item_id' => $item_id,
+ /**
+ * Test notify() function with a call with an error response.
+ */
+ public function test_notify_response_error() {
+ $this->service = $this->get_mock();
+
+ $this->service->expects( $this->once() )->method( 'do_request' )->willReturn(
+ [
+ 'response' => [
+ 'code' => 400,
+ 'body' => 'Bad request',
],
- 'url' => $this->service->get_notification_url(),
- ];
-
- $this->service->expects( $this->once() )->method( 'do_request' )->with( $args )->willReturn( [ 'code' => 200 ] );
- $this->assertTrue( $this->service->notify( $item_id , $topic ) );
-
- }
-
-
- /**
- * Test notify() function with a call with wp_error response.
- */
- public function test_notify_wp_error() {
- $this->service = $this->get_mock();
-
-
- $this->service->expects( $this->once() )->method( 'do_request' )->willReturn( new \WP_Error( 'error', 'error message' ) );
- $this->assertFalse( $this->service->notify( 1 , 'topic') );
- $this->assertEquals( did_action( 'woocommerce_gla_error' ), 1 );
- }
-
- /**
- * Test notify() function with a call with an error response.
- */
- public function test_notify_response_error() {
-
- $this->service = $this->get_mock();
-
- $this->service->expects( $this->once() )->method( 'do_request' )->willReturn( [ 'response' => [ 'code' => 400, 'body' => 'Bad request' ] ] );
- $this->assertFalse( $this->service->notify( 1 , 'topic') );
- $this->assertEquals( did_action( 'woocommerce_gla_error' ), 1 );
- }
-
- /**
- * Mocks the service
- * @return NotificationsService
- */
- public function get_mock() {
- return $this->getMockBuilder( NotificationsService::class)
- ->onlyMethods( [ 'do_request' ] )
- ->getMock();
- }
+ ]
+ );
+ $this->assertFalse( $this->service->notify( 1, 'topic' ) );
+ $this->assertEquals( did_action( 'woocommerce_gla_error' ), 1 );
+ }
+ /**
+ * Mocks the service
+ *
+ * @return NotificationsService
+ */
+ public function get_mock() {
+ return $this->getMockBuilder( NotificationsService::class )
+ ->onlyMethods( [ 'do_request' ] )
+ ->getMock();
}
+}
diff --git a/tests/Unit/Jobs/ProductNotificationJobTest.php b/tests/Unit/Jobs/ProductNotificationJobTest.php
index 94b7b83f23..eadd9d89d1 100644
--- a/tests/Unit/Jobs/ProductNotificationJobTest.php
+++ b/tests/Unit/Jobs/ProductNotificationJobTest.php
@@ -15,6 +15,7 @@
/**
* Class ProductNotificationJobTest
+ *
* @group Notifications
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tests\Unit\Jobs
*/
@@ -65,7 +66,7 @@ public function test_job_name() {
public function test_schedule_schedules_immediate_job() {
$topic = 'product.create';
- $id = 1;
+ $id = 1;
$this->action_scheduler->expects( $this->once() )
->method( 'has_scheduled_action' )
@@ -83,7 +84,7 @@ public function test_schedule_schedules_immediate_job() {
}
public function test_schedule_doesnt_schedules_immediate_job_if_already_scheduled() {
- $id = 1;
+ $id = 1;
$topic = 'product.create';
$this->action_scheduler->expects( $this->once() )
@@ -94,11 +95,10 @@ public function test_schedule_doesnt_schedules_immediate_job_if_already_schedule
$this->action_scheduler->expects( $this->never() )->method( 'schedule_immediate' );
$this->job->schedule( [ $id, $topic ] );
-
}
public function test_schedule_doesnt_schedules_immediate_job_if_filtered() {
- $id = 1;
+ $id = 1;
$topic = 'product.create';
add_filter( 'woocommerce_gla_product_notification_job_can_schedule', '__return_false' );
@@ -111,14 +111,13 @@ public function test_schedule_doesnt_schedules_immediate_job_if_filtered() {
$this->action_scheduler->expects( $this->never() )->method( 'schedule_immediate' );
$this->job->schedule( [ $id, $topic ] );
-
}
public function test_process_items_calls_notify_and_set_status_on_success() {
/** @var \WC_Product $product */
$product = WC_Helper_Product::create_simple_product();
- $id = $product->get_id();
- $topic = 'product.create';
+ $id = $product->get_id();
+ $topic = 'product.create';
$this->notification_service->expects( $this->once() )
->method( 'notify' )
@@ -135,7 +134,6 @@ public function test_process_items_calls_notify_and_set_status_on_success() {
->with( $product, NotificationStatus::NOTIFICATION_CREATED );
$this->job->handle_process_items_action( [ $id, $topic ] );
-
}
public function test_process_items_doesnt_calls_notify_when_no_args() {
@@ -149,8 +147,8 @@ public function test_process_items_doesnt_calls_notify_when_no_args() {
public function test_process_items_doesnt_calls_set_status_on_failure() {
/** @var \WC_Product $product */
$product = WC_Helper_Product::create_simple_product();
- $id = $product->get_id();
- $topic = 'product.create';
+ $id = $product->get_id();
+ $topic = 'product.create';
$this->notification_service->expects( $this->once() )
->method( 'notify' )
@@ -164,13 +162,12 @@ public function test_process_items_doesnt_calls_set_status_on_failure() {
->method( 'set_notification_status' );
$this->job->handle_process_items_action( [ $id, $topic ] );
-
}
public function test_get_after_notification_status() {
/** @var \WC_Product $product */
$product = WC_Helper_Product::create_simple_product();
- $id = $product->get_id();
+ $id = $product->get_id();
$this->notification_service->expects( $this->exactly( 3 ) )
->method( 'notify' )
@@ -182,20 +179,20 @@ public function test_get_after_notification_status() {
$this->product_helper->expects( $this->exactly( 3 ) )
->method( 'set_notification_status' )
- ->willReturnCallback( function( $id, $topic ) {
- if ( $topic === 'product.create' ) {
- return NotificationStatus::NOTIFICATION_CREATED;
- } else if ( $topic === 'product.delete' ) {
- return NotificationStatus::NOTIFICATION_DELETED;
- } else {
- return NotificationStatus::NOTIFICATION_UPDATED;
+ ->willReturnCallback(
+ function ( $id, $topic ) {
+ if ( $topic === 'product.create' ) {
+ return NotificationStatus::NOTIFICATION_CREATED;
+ } elseif ( $topic === 'product.delete' ) {
+ return NotificationStatus::NOTIFICATION_DELETED;
+ } else {
+ return NotificationStatus::NOTIFICATION_UPDATED;
+ }
}
- });
-
+ );
$this->job->handle_process_items_action( [ $id, 'product.create' ] );
$this->job->handle_process_items_action( [ $id, 'product.delete' ] );
$this->job->handle_process_items_action( [ $id, 'product.update' ] );
}
-
}
diff --git a/tests/Unit/Product/ProductHelperTest.php b/tests/Unit/Product/ProductHelperTest.php
index 38737e8b7f..f8293611e3 100644
--- a/tests/Unit/Product/ProductHelperTest.php
+++ b/tests/Unit/Product/ProductHelperTest.php
@@ -24,6 +24,7 @@
/**
* Class ProductHelperTest
+ *
* @group Helpers
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tests\Unit\Product
*/
@@ -1130,12 +1131,13 @@ public function test_should_trigger_delete_notification() {
/**
* Set and save product to make it Notification Ready
+ *
* @param WC_Product $product
* @return WC_Product
*/
public function get_notification_ready_product( $product ) {
$product->set_status( 'publish' );
- $product->add_meta_data( '_wc_gla_visibility', ChannelVisibility::SYNC_AND_SHOW , true );
+ $product->add_meta_data( '_wc_gla_visibility', ChannelVisibility::SYNC_AND_SHOW, true );
$product->save();
return $product;
}
diff --git a/tests/Unit/Product/SyncerHooksTest.php b/tests/Unit/Product/SyncerHooksTest.php
index 7130c46a78..0d7b58ee3d 100644
--- a/tests/Unit/Product/SyncerHooksTest.php
+++ b/tests/Unit/Product/SyncerHooksTest.php
@@ -77,7 +77,6 @@ public function test_update_simple_product_schedules_update_job() {
->method( 'schedule' )
->with( $this->equalTo( [ [ $product->get_id() ] ] ) );
-
$product->set_status( 'publish' );
$product->save();
}
@@ -281,7 +280,7 @@ public function test_trashing_and_deleting_post_does_not_schedule_delete_job() {
public function test_create_product_triggers_notification_created() {
$product = WC_Helper_Product::create_simple_product( true, [ 'status' => 'draft' ] );
- $this->notification_service->expects( $this->once() )->method('is_enabled')->willReturn( true );
+ $this->notification_service->expects( $this->once() )->method( 'is_enabled' )->willReturn( true );
$this->product_notification_job->expects( $this->once() )
->method( 'schedule' )->with( $this->equalTo( [ $product->get_id(), NotificationsService::TOPIC_PRODUCT_CREATED ] ) );
$product->set_status( 'publish' );
@@ -290,7 +289,7 @@ public function test_create_product_triggers_notification_created() {
public function test_create_product_triggers_notification_updated() {
$product = WC_Helper_Product::create_simple_product( true, [ 'status' => 'draft' ] );
- $this->notification_service->expects( $this->once() )->method('is_enabled')->willReturn( true );
+ $this->notification_service->expects( $this->once() )->method( 'is_enabled' )->willReturn( true );
$this->product_notification_job->expects( $this->once() )
->method( 'schedule' )->with( $this->equalTo( [ $product->get_id(), NotificationsService::TOPIC_PRODUCT_UPDATED ] ) );
$product->set_status( 'publish' );
@@ -300,11 +299,11 @@ public function test_create_product_triggers_notification_updated() {
public function test_create_product_triggers_notification_delete() {
$product = WC_Helper_Product::create_simple_product( true, [ 'status' => 'draft' ] );
- $this->notification_service->expects( $this->once() )->method('is_enabled')->willReturn( true );
+ $this->notification_service->expects( $this->once() )->method( 'is_enabled' )->willReturn( true );
$this->product_notification_job->expects( $this->once() )
->method( 'schedule' )->with( $this->equalTo( [ $product->get_id(), NotificationsService::TOPIC_PRODUCT_DELETED ] ) );
$product->set_status( 'publish' );
- $product->add_meta_data( '_wc_gla_visibility', ChannelVisibility::DONT_SYNC_AND_SHOW , true );
+ $product->add_meta_data( '_wc_gla_visibility', ChannelVisibility::DONT_SYNC_AND_SHOW, true );
$this->product_helper->set_notification_status( $product, NotificationStatus::NOTIFICATION_CREATED );
$product->save();
}
@@ -323,11 +322,11 @@ public function setUp(): void {
->method( 'is_ready_for_syncing' )
->willReturn( true );
- $this->update_products_job = $this->createMock( UpdateProducts::class );
- $this->delete_products_job = $this->createMock( DeleteProducts::class );
- $this->product_notification_job = $this->createMock( ProductNotificationJob::class );
- $this->job_repository = $this->createMock( JobRepository::class );
- $this->notification_service = $this->createMock( NotificationsService::class );
+ $this->update_products_job = $this->createMock( UpdateProducts::class );
+ $this->delete_products_job = $this->createMock( DeleteProducts::class );
+ $this->product_notification_job = $this->createMock( ProductNotificationJob::class );
+ $this->job_repository = $this->createMock( JobRepository::class );
+ $this->notification_service = $this->createMock( NotificationsService::class );
$this->job_repository->expects( $this->any() )
->method( 'get' )
@@ -339,12 +338,12 @@ public function setUp(): void {
]
);
- $this->batch_helper = $this->container->get( BatchProductHelper::class );
- $this->product_helper = $this->container->get( ProductHelper::class );
- $this->wc = $this->container->get( WC::class );
+ $this->batch_helper = $this->container->get( BatchProductHelper::class );
+ $this->product_helper = $this->container->get( ProductHelper::class );
+ $this->wc = $this->container->get( WC::class );
$this->syncer_hooks = new SyncerHooks( $this->batch_helper, $this->product_helper, $this->job_repository, $this->merchant_center, $this->notification_service, $this->wc );
- add_filter( 'woocommerce_gla_notifications_enabled', '__return_false');
+ add_filter( 'woocommerce_gla_notifications_enabled', '__return_false' );
$this->syncer_hooks->register();
}
}