diff --git a/plugins/woocommerce/changelog/fix-rin-alert-notes b/plugins/woocommerce/changelog/fix-rin-alert-notes new file mode 100644 index 00000000000..f82680e6f35 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-rin-alert-notes @@ -0,0 +1,4 @@ +Significance: minor +Type: fix + +Fix RIN Display Logic for Banner Alert Notifications diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/SpecRunner.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/SpecRunner.php index ab38100f3e9..dee3a29dfae 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/SpecRunner.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/SpecRunner.php @@ -114,7 +114,7 @@ class SpecRunner { $matching_wp_locales = array_values( array_filter( $locales, - function( $l ) use ( $wp_locale ) { + function ( $l ) use ( $wp_locale ) { return $wp_locale === $l->locale; } ) @@ -128,7 +128,7 @@ class SpecRunner { $en_us_locales = array_values( array_filter( $locales, - function( $l ) { + function ( $l ) { return $l->locale === 'en_US'; } ) @@ -168,7 +168,7 @@ class SpecRunner { $en_us_locales = array_values( array_filter( $action_locales, - function( $l ) { + function ( $l ) { return $l->locale === 'en_US'; } ) diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/EvaluateAndGetStatus.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/EvaluateAndGetStatus.php index 9d7920d63f1..7a568c33f09 100644 --- a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/EvaluateAndGetStatus.php +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/EvaluateAndGetStatus.php @@ -46,6 +46,13 @@ class EvaluateAndGetStatus { : Note::E_WC_ADMIN_NOTE_PENDING; } + // If the spec is an alert type and the note is unactioned, set to pending if the spec no longer applies. + if ( isset( $spec->type ) && in_array( $spec->type, array( 'error', 'update' ), true ) + && Note::E_WC_ADMIN_NOTE_UNACTIONED === $current_status + && ! $evaluated_result ) { + return Note::E_WC_ADMIN_NOTE_PENDING; + } + // When allow_redisplay isn't set, just leave the note alone. if ( ! isset( $spec->allow_redisplay ) || ! $spec->allow_redisplay ) { return $current_status; diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/evaluate-and-get-status.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/evaluate-and-get-status.php index 2d8c0295985..7de3b0c6251 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/evaluate-and-get-status.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/evaluate-and-get-status.php @@ -212,4 +212,55 @@ class WC_Admin_Tests_RemoteInboxNotifications_EvaluateAndGetStatus extends WC_Un $this->assertEquals( 'unactioned', $result ); } + + /** + * Tests that for an alert note that is unactioned and eval to true, + * The pending status is returned. + * + * @group fast + */ + public function test_unactioned_alert_note_return_pending_when_eval_to_false() { + $spec = json_decode( + '{ + "slug": "test", + "type": "error", + "rules": [] + }' + ); + + $result = EvaluateAndGetStatus::evaluate( + $spec, + 'unactioned', + new stdClass(), + new FailingRuleEvaluator() + ); + + $this->assertEquals( 'pending', $result ); + } + + /** + * Tests that for an alert note that is unactioned and eval to true, + * The current status is returned. + * + * @group fast + */ + public function test_unactioned_info_note_return_current_status_when_eval_to_false() { + $spec = json_decode( + '{ + "slug": "test", + "type": "info", + "rules": [] + }' + ); + + $current_status = 'unactioned'; + $result = EvaluateAndGetStatus::evaluate( + $spec, + $current_status, + new stdClass(), + new FailingRuleEvaluator() + ); + + $this->assertEquals( $current_status, $result ); + } }