-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Use 'action_scheduler_ensure_recurring_actions' for scheduling PTK Pattern fetches. #61749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Use 'action_scheduler_ensure_recurring_actions' for scheduling PTK Pattern fetches. #61749
Conversation
Testing GuidelinesHi @joshuatf , Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
📝 WalkthroughWalkthroughMoves PTK Patterns fetching from a timestamp/option-based mechanism to Action Scheduler recurring actions, adds a DB updater to remove the legacy Changes
Sequence DiagramsequenceDiagram
participant WP as WordPress
participant AS as Action Scheduler
participant Store as PTKPatternsStore
participant Cache as Patterns Cache
rect rgba(220,240,255,0.6)
Note over WP,Cache: Legacy flow (timestamp/option based — cleaned up)
WP->>Store: get_patterns()
alt cache present & timestamp fresh (legacy)
Store->>Cache: return cached
else
Store->>Store: fetch_patterns() (legacy would set option)
Store->>Cache: update cache
end
end
rect rgba(240,255,240,0.6)
Note over WP,AS: New flow (recurring Action Scheduler)
WP->>AS: action_scheduler_ensure_recurring_actions
AS->>Store: ensure_recurring_fetch_patterns_if_enabled()
alt tracking enabled & no recurring scheduled
Store->>AS: as_schedule_recurring_action(fetch_patterns, interval=DAY_IN_SECONDS)
end
AS->>Store: fetch_patterns() [on schedule]
Store->>Cache: update cache
alt flush_cached_patterns() called
Store->>AS: as_unschedule_all_actions(fetch_patterns, ... , 'woocommerce')
Store->>Cache: clear cache
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Areas requiring extra attention:
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (3)
plugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php (1)
96-102: Minor: early-return is fine; consider immediate fetch on enableCurrent path only ensures the recurring job exists. If product wants an immediate refresh when tracking flips to “yes”, enqueue a single action too:
public function ensure_recurring_fetch_patterns_if_enabled() { if ( ! $this->allowed_tracking_is_enabled() ) { return; } $this->schedule_action_if_not_pending( 'fetch_patterns' ); + // Optionally kick an immediate run the first time. + if ( ! as_has_scheduled_action( 'fetch_patterns', array(), self::AS_GROUP ) ) { + as_schedule_single_action( time(), 'fetch_patterns', array(), self::AS_GROUP, true ); + } }plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php (2)
460-473: Strengthen “no duplicates” assertionComparing timestamps via
as_next_scheduled_action()can miss duplicates scheduled at the same time. Assert count=1 instead:- $first_action_id = as_next_scheduled_action( 'fetch_patterns' ); - $this->assertNotFalse( $first_action_id, 'First action should be scheduled' ); - // Call again - should not create duplicate. - $this->pattern_store->ensure_recurring_fetch_patterns_if_enabled(); - $second_action_id = as_next_scheduled_action( 'fetch_patterns' ); - $this->assertEquals( $first_action_id, $second_action_id, 'Should not create duplicate action' ); + $scheduled = as_get_scheduled_actions( + array( 'hook' => 'fetch_patterns', 'status' => \ActionScheduler_Store::STATUS_PENDING, 'per_page' => -1 ) + ); + $this->assertCount( 1, $scheduled, 'Exactly one action should be scheduled' ); + // Call again - should not create duplicate. + $this->pattern_store->ensure_recurring_fetch_patterns_if_enabled(); + $scheduled_after = as_get_scheduled_actions( + array( 'hook' => 'fetch_patterns', 'status' => \ActionScheduler_Store::STATUS_PENDING, 'per_page' => -1 ) + ); + $this->assertCount( 1, $scheduled_after, 'No duplicate should be created' );
478-490: Optional: verify flush uses group if one is addedIf you adopt a group (e.g.,
woocommerce-ptk-patterns), update test assertions to pass the group toas_has_scheduled_actionandas_unschedule_all_actionsfor precision.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
plugins/woocommerce/changelog/WOOPLUG-5765-use-as-ensure-action-for-ptkpattern-fetching(1 hunks)plugins/woocommerce/includes/class-wc-install.php(1 hunks)plugins/woocommerce/includes/wc-update-functions.php(1 hunks)plugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php(6 hunks)plugins/woocommerce/tests/php/includes/wc-update-functions-test.php(1 hunks)plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php(3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{php,js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/code-quality.mdc)
**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable
Files:
plugins/woocommerce/includes/wc-update-functions.phpplugins/woocommerce/includes/class-wc-install.phpplugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.phpplugins/woocommerce/tests/php/includes/wc-update-functions-test.phpplugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
**/*.{php,js,jsx,tsx,ts}
📄 CodeRabbit inference engine (.cursor/rules/avoid-regex.mdc)
**/*.{php,js,jsx,tsx,ts}: Avoid using regular expressions unless absolutely necessary to favor readability and maintainability
Only consider regex when no built-in language alternative (string/array APIs) fits the need
Only use regex when performance is critical and faster than alternatives, with measurements to justify
Use regex for complex pattern matching only if the pattern is well-documented and thoroughly tested
Allow regex when maintaining legacy code where an existing, correct pattern is being modified
If regex is necessary, document the pattern extensively to explain what it matches
If regex is necessary, add comprehensive tests covering edge cases and potential security issues
Use named capture groups in regex to improve readability when supported
Validate input before applying regex to ensure it is safe
Assess and mitigate security risks when using regex, including ReDoS and injection vulnerabilities
Avoid regex patterns that can cause catastrophic backtracking (ReDoS)
Do not construct regex from untrusted input to prevent injection attacks
Ensure regex patterns do not overmatch and unintentionally capture unexpected inputs
Files:
plugins/woocommerce/includes/wc-update-functions.phpplugins/woocommerce/includes/class-wc-install.phpplugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.phpplugins/woocommerce/tests/php/includes/wc-update-functions-test.phpplugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
**/*.{php,js,ts,jsx,tsx}
⚙️ CodeRabbit configuration file
**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:
- Guards against unexpected inputs.
- Sanitizes and validates any potentially dangerous inputs.
- Is backwards compatible.
- Is readable and intuitive.
- Has unit or E2E tests where applicable.
When making any changes to code that deletes or modifies orders/products/customer data, make sure that there are
sufficient checks in place to prevent accidental data loss. As an example, if deleting a draft order, check that
the order status is indeeddraftorcheckout-draft. Also think about whether race conditions could occur and
delete orders that don't belong to the current customer. When in doubt, ask for clarification in the PR comments.
Files:
plugins/woocommerce/includes/wc-update-functions.phpplugins/woocommerce/includes/class-wc-install.phpplugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.phpplugins/woocommerce/tests/php/includes/wc-update-functions-test.phpplugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
plugins/woocommerce/tests/**/*.php
📄 CodeRabbit inference engine (.cursor/rules/woo-phpunit.mdc)
plugins/woocommerce/tests/**/*.php: Ensure test classes define public setUp() and tearDown() methods (not protected)
All PHPUnit test methods must be public, not protected
Add declare(strict_types=1); at the top of each test file
Test classes should extend WC_Unit_Test_Case
Files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.phpplugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
🧠 Learnings (13)
📓 Common learnings
Learnt from: opr
Repo: woocommerce/woocommerce PR: 60360
File: plugins/woocommerce/includes/class-woocommerce.php:1553-1563
Timestamp: 2025-08-15T13:00:31.543Z
Learning: The learning from PR #60360 about not needing to clean up legacy scheduled actions when hook names change is specific to that PR's context: PR #59325 was released in WC 10.1 with an incorrect hook name (action_scheduler_schedule_recurring_actions instead of action_scheduler_ensure_recurring_actions), so no actions were actually queued under the old hook name. This is not a general rule for all hook name changes.
Learnt from: opr
Repo: woocommerce/woocommerce PR: 60360
File: plugins/woocommerce/includes/class-woocommerce.php:1533-1544
Timestamp: 2025-08-14T07:34:00.169Z
Learning: When a WordPress action hook name is changed in a PR (like from action_scheduler_schedule_recurring_actions to action_scheduler_ensure_recurring_actions), any code that was previously hooked to the old hook name would not have been executed, so there's no need to clean up or unschedule any legacy scheduled actions that were supposedly created by the old hook.
Learnt from: senadir
Repo: woocommerce/woocommerce PR: 59325
File: plugins/woocommerce/includes/wc-formatting-functions.php:1211-1226
Timestamp: 2025-07-01T16:24:23.871Z
Learning: Action Scheduler is bundled into WooCommerce and always available, so there's no need to add fallback logic to WordPress cron functions when using Action Scheduler functions like as_schedule_single_action() and as_unschedule_all_actions() in WooCommerce code.
📚 Learning: 2025-08-14T07:34:00.169Z
Learnt from: opr
Repo: woocommerce/woocommerce PR: 60360
File: plugins/woocommerce/includes/class-woocommerce.php:1533-1544
Timestamp: 2025-08-14T07:34:00.169Z
Learning: When a WordPress action hook name is changed in a PR (like from action_scheduler_schedule_recurring_actions to action_scheduler_ensure_recurring_actions), any code that was previously hooked to the old hook name would not have been executed, so there's no need to clean up or unschedule any legacy scheduled actions that were supposedly created by the old hook.
Applied to files:
plugins/woocommerce/changelog/WOOPLUG-5765-use-as-ensure-action-for-ptkpattern-fetchingplugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php
📚 Learning: 2025-08-15T13:00:31.543Z
Learnt from: opr
Repo: woocommerce/woocommerce PR: 60360
File: plugins/woocommerce/includes/class-woocommerce.php:1553-1563
Timestamp: 2025-08-15T13:00:31.543Z
Learning: The learning from PR #60360 about not needing to clean up legacy scheduled actions when hook names change is specific to that PR's context: PR #59325 was released in WC 10.1 with an incorrect hook name (action_scheduler_schedule_recurring_actions instead of action_scheduler_ensure_recurring_actions), so no actions were actually queued under the old hook name. This is not a general rule for all hook name changes.
Applied to files:
plugins/woocommerce/changelog/WOOPLUG-5765-use-as-ensure-action-for-ptkpattern-fetchingplugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php
📚 Learning: 2025-06-17T07:07:53.443Z
Learnt from: samueljseay
Repo: woocommerce/woocommerce PR: 58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:83-101
Timestamp: 2025-06-17T07:07:53.443Z
Learning: In WooCommerce blocks, when porting existing code patterns that have known issues (like parseInt truncating decimal money values), maintain consistency with existing implementation rather than making isolated fixes. The preference is for systematic refactoring approaches (like broader Dinero adoption) over piecemeal changes.
Applied to files:
plugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php
📚 Learning: 2025-07-01T16:24:23.871Z
Learnt from: senadir
Repo: woocommerce/woocommerce PR: 59325
File: plugins/woocommerce/includes/wc-formatting-functions.php:1211-1226
Timestamp: 2025-07-01T16:24:23.871Z
Learning: Action Scheduler is bundled into WooCommerce and always available, so there's no need to add fallback logic to WordPress cron functions when using Action Scheduler functions like as_schedule_single_action() and as_unschedule_all_actions() in WooCommerce code.
Applied to files:
plugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php
📚 Learning: 2025-08-18T06:11:48.768Z
Learnt from: CR
Repo: woocommerce/woocommerce PR: 0
File: .cursor/rules/woo-phpunit.mdc:0-0
Timestamp: 2025-08-18T06:11:48.768Z
Learning: Applies to plugins/woocommerce/tests/**/*.php : Add declare(strict_types=1); at the top of each test file
Applied to files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.phpplugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-18T06:11:48.768Z
Learnt from: CR
Repo: woocommerce/woocommerce PR: 0
File: .cursor/rules/woo-phpunit.mdc:0-0
Timestamp: 2025-08-18T06:11:48.768Z
Learning: Applies to plugins/woocommerce/tests/**/*.php : All PHPUnit test methods must be public, not protected
Applied to files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.phpplugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-10-24T13:25:49.900Z
Learnt from: hannahtinkler
Repo: woocommerce/woocommerce PR: 61384
File: plugins/woocommerce/tests/php/src/Internal/PushNotifications/Entities/PushTokenTest.php:208-216
Timestamp: 2025-10-24T13:25:49.900Z
Learning: In plugins/woocommerce/tests/**/*.php files, omit setUp() and tearDown() methods when they are not needed, as the project's linting configuration makes it easier to omit these methods than to add them with phpcs:ignore comments.
Applied to files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.phpplugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-18T06:11:48.768Z
Learnt from: CR
Repo: woocommerce/woocommerce PR: 0
File: .cursor/rules/woo-phpunit.mdc:0-0
Timestamp: 2025-08-18T06:11:48.768Z
Learning: Applies to plugins/woocommerce/tests/**/*.php : Test classes should extend WC_Unit_Test_Case
Applied to files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.php
📚 Learning: 2025-09-03T11:50:02.208Z
Learnt from: tpaksu
Repo: woocommerce/woocommerce PR: 60735
File: plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Fulfillments/class-wc-rest-fulfillments-v4-controller-tests.php:10-10
Timestamp: 2025-09-03T11:50:02.208Z
Learning: For REST API controller tests in plugins/woocommerce/tests/**/*.php, test classes should extend WC_REST_Unit_Test_Case instead of WC_Unit_Test_Case because REST routes need to be registered before tests run.
Applied to files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.php
📚 Learning: 2025-08-14T08:20:36.357Z
Learnt from: Aljullu
Repo: woocommerce/woocommerce PR: 60191
File: plugins/woocommerce/client/blocks/tests/e2e/tests/single-product-template/single-product-template-compatibility-layer.spec.ts:4-4
Timestamp: 2025-08-14T08:20:36.357Z
Learning: In WooCommerce e2e tests, some test files intentionally use hard-coded "woocommerce/woocommerce//" template IDs instead of BLOCK_THEME_SLUG to test backwards compatibility with the legacy plugin-scoped template ID format. These should not be updated to use the dynamic slug constant as they serve a specific testing purpose.
Applied to files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.phpplugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-14T08:22:34.886Z
Learnt from: Aljullu
Repo: woocommerce/woocommerce PR: 60191
File: plugins/woocommerce/client/blocks/tests/e2e/tests/product-filters/rating-filter-editor.block_theme.spec.ts:36-36
Timestamp: 2025-08-14T08:22:34.886Z
Learning: In WooCommerce e2e tests, some test files intentionally use hard-coded "woocommerce/woocommerce//" template slugs (not just template IDs) instead of BLOCK_THEME_SLUG to test backwards compatibility with the legacy plugin-scoped template slug format. These should not be updated to use the dynamic slug constant as they serve a specific backwards compatibility testing purpose.
Applied to files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.php
📚 Learning: 2025-06-25T15:39:25.166Z
Learnt from: vladolaru
Repo: woocommerce/woocommerce PR: 59160
File: plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPayments/WooPaymentsServiceTest.php:360-373
Timestamp: 2025-06-25T15:39:25.166Z
Learning: Test mocks should accurately simulate the behavior of the functions they replace, including return value semantics. For WordPress functions like `update_option`, the mock should properly return `false` when the value hasn't changed and `true` when it has, to avoid masking logic errors in tests.
Applied to files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.phpplugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
🧬 Code graph analysis (2)
plugins/woocommerce/tests/php/includes/wc-update-functions-test.php (1)
plugins/woocommerce/includes/wc-update-functions.php (1)
wc_update_1040_remove_last_fetch_patterns_request_option(3136-3138)
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php (1)
plugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php (3)
PTKPatternsStore(13-295)flush_cached_patterns(187-192)ensure_recurring_fetch_patterns_if_enabled(96-102)
🔇 Additional comments (7)
plugins/woocommerce/changelog/WOOPLUG-5765-use-as-ensure-action-for-ptkpattern-fetching (1)
1-4: Changelog entry looks goodAccurately reflects the scheduling change. No action needed.
plugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php (3)
49-49: Good move toaction_scheduler_ensure_recurring_actionsHook selection is correct for “ensure” semantics with Action Scheduler. LGTM.
126-129: Comment aligns with behaviorScheduling on missing/invalid cache is fine; no fetch-in-constructor surprises. LGTM.
190-192: The suggested fix references a non-existent constant and misidentifies a non-issueThe
as_unschedule_all_actions()call andas_schedule_recurring_action()call are already internally consistent—both omit the group parameter and default to an empty group. The referencedself::AS_GROUPconstant does not exist in this class.While using explicit group scoping is a defensive practice, the current code is not broken. If group scoping is desired, first define an
AS_GROUPclass constant, then use it in both the scheduling (line 111 inschedule_action_if_not_pending()) and unscheduling (line 191) calls. Search results show the'fetch_patterns'hook is used only within this class, further reducing collision risk.Likely an incorrect or invalid review comment.
plugins/woocommerce/includes/class-wc-install.php (1)
310-312: Updater wiring looks correct
wc_update_1040_remove_last_fetch_patterns_request_optionis added to 10.4.0 callbacks. LGTM.plugins/woocommerce/includes/wc-update-functions.php (1)
3129-3137: Updater implementation is minimal and correct
delete_option( 'last_fetch_patterns_request' );is sufficient. No further changes needed.plugins/woocommerce/tests/php/includes/wc-update-functions-test.php (1)
251-267: Test covers the updater wellAsserts option removal after running the updater. LGTM.
Please add strict types per repo test guidelines. Minimal patch:
<?php +declare(strict_types=1);If this file already declares strict types elsewhere, ignore.
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
Outdated
Show resolved
Hide resolved
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
Show resolved
Hide resolved
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
plugins/woocommerce/tests/php/includes/wc-update-functions-test.php (1)
1-8: Add strict types declarationPer the coding guidelines for test files, a
declare(strict_types=1);statement should be added at the top of the file.Apply this diff:
<?php +declare(strict_types=1); + /** * Update functions tests * * @package WooCommerce\Tests\Functions. */
🧹 Nitpick comments (1)
plugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php (1)
110-116: Use a class constant for the Action Scheduler group and add uniqueness constraintThe hardcoded
'woocommerce'group string is repeated in three locations (lines 111, 115, and 191), which makes the code harder to maintain and prone to typos. Additionally, passingunique=truetoas_schedule_recurring_actionprevents race-condition duplicates when multiple processes might attempt to schedule the same action.Apply this diff:
+ private const AS_GROUP = 'woocommerce-ptk-patterns'; + private function schedule_action_if_not_pending( $action ) { - if ( as_has_scheduled_action( $action, array(), 'woocommerce' ) ) { + if ( as_has_scheduled_action( $action, array(), self::AS_GROUP ) ) { return; } - as_schedule_recurring_action( time(), DAY_IN_SECONDS, $action, array(), 'woocommerce' ); + as_schedule_recurring_action( time(), DAY_IN_SECONDS, $action, array(), self::AS_GROUP, true ); }Also update line 191 to use the same constant:
- as_unschedule_all_actions( 'fetch_patterns', array(), 'woocommerce' ); + as_unschedule_all_actions( 'fetch_patterns', array(), self::AS_GROUP );
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
plugins/woocommerce/includes/class-wc-install.php(1 hunks)plugins/woocommerce/includes/wc-update-functions.php(1 hunks)plugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php(6 hunks)plugins/woocommerce/tests/php/includes/wc-update-functions-test.php(1 hunks)plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
- plugins/woocommerce/includes/class-wc-install.php
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{php,js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/code-quality.mdc)
**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable
Files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.phpplugins/woocommerce/includes/wc-update-functions.phpplugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php
plugins/woocommerce/tests/**/*.php
📄 CodeRabbit inference engine (.cursor/rules/woo-phpunit.mdc)
plugins/woocommerce/tests/**/*.php: Ensure test classes define public setUp() and tearDown() methods (not protected)
All PHPUnit test methods must be public, not protected
Add declare(strict_types=1); at the top of each test file
Test classes should extend WC_Unit_Test_Case
Files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.php
**/*.{php,js,jsx,tsx,ts}
📄 CodeRabbit inference engine (.cursor/rules/avoid-regex.mdc)
**/*.{php,js,jsx,tsx,ts}: Avoid using regular expressions unless absolutely necessary to favor readability and maintainability
Only consider regex when no built-in language alternative (string/array APIs) fits the need
Only use regex when performance is critical and faster than alternatives, with measurements to justify
Use regex for complex pattern matching only if the pattern is well-documented and thoroughly tested
Allow regex when maintaining legacy code where an existing, correct pattern is being modified
If regex is necessary, document the pattern extensively to explain what it matches
If regex is necessary, add comprehensive tests covering edge cases and potential security issues
Use named capture groups in regex to improve readability when supported
Validate input before applying regex to ensure it is safe
Assess and mitigate security risks when using regex, including ReDoS and injection vulnerabilities
Avoid regex patterns that can cause catastrophic backtracking (ReDoS)
Do not construct regex from untrusted input to prevent injection attacks
Ensure regex patterns do not overmatch and unintentionally capture unexpected inputs
Files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.phpplugins/woocommerce/includes/wc-update-functions.phpplugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php
**/*.{php,js,ts,jsx,tsx}
⚙️ CodeRabbit configuration file
**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:
- Guards against unexpected inputs.
- Sanitizes and validates any potentially dangerous inputs.
- Is backwards compatible.
- Is readable and intuitive.
- Has unit or E2E tests where applicable.
When making any changes to code that deletes or modifies orders/products/customer data, make sure that there are
sufficient checks in place to prevent accidental data loss. As an example, if deleting a draft order, check that
the order status is indeeddraftorcheckout-draft. Also think about whether race conditions could occur and
delete orders that don't belong to the current customer. When in doubt, ask for clarification in the PR comments.
Files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.phpplugins/woocommerce/includes/wc-update-functions.phpplugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php
🧠 Learnings (11)
📓 Common learnings
Learnt from: opr
Repo: woocommerce/woocommerce PR: 60360
File: plugins/woocommerce/includes/class-woocommerce.php:1553-1563
Timestamp: 2025-08-15T13:00:31.543Z
Learning: The learning from PR #60360 about not needing to clean up legacy scheduled actions when hook names change is specific to that PR's context: PR #59325 was released in WC 10.1 with an incorrect hook name (action_scheduler_schedule_recurring_actions instead of action_scheduler_ensure_recurring_actions), so no actions were actually queued under the old hook name. This is not a general rule for all hook name changes.
Learnt from: opr
Repo: woocommerce/woocommerce PR: 60360
File: plugins/woocommerce/includes/class-woocommerce.php:1533-1544
Timestamp: 2025-08-14T07:34:00.169Z
Learning: When a WordPress action hook name is changed in a PR (like from action_scheduler_schedule_recurring_actions to action_scheduler_ensure_recurring_actions), any code that was previously hooked to the old hook name would not have been executed, so there's no need to clean up or unschedule any legacy scheduled actions that were supposedly created by the old hook.
Learnt from: senadir
Repo: woocommerce/woocommerce PR: 59325
File: plugins/woocommerce/includes/wc-formatting-functions.php:1211-1226
Timestamp: 2025-07-01T16:24:23.871Z
Learning: Action Scheduler is bundled into WooCommerce and always available, so there's no need to add fallback logic to WordPress cron functions when using Action Scheduler functions like as_schedule_single_action() and as_unschedule_all_actions() in WooCommerce code.
Learnt from: prettyboymp
Repo: woocommerce/woocommerce PR: 60272
File: .github/workflows/release-open-issue-warning.yml:15-23
Timestamp: 2025-08-08T13:52:26.423Z
Learning: Repository: woocommerce/woocommerce
Context: .github/workflows/release-open-issue-warning.yml and similar workflows
Learning: Maintainers (per prettyboymp) are fine requiring third-party modules inside actions/github-script without adding setup-node/createRequire. Prefer to keep this pattern and defer structural changes unless it demonstrably causes issues; minor safeguards like version pinning are acceptable if needed.
📚 Learning: 2025-10-24T13:25:49.900Z
Learnt from: hannahtinkler
Repo: woocommerce/woocommerce PR: 61384
File: plugins/woocommerce/tests/php/src/Internal/PushNotifications/Entities/PushTokenTest.php:208-216
Timestamp: 2025-10-24T13:25:49.900Z
Learning: In plugins/woocommerce/tests/**/*.php files, omit setUp() and tearDown() methods when they are not needed, as the project's linting configuration makes it easier to omit these methods than to add them with phpcs:ignore comments.
Applied to files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.php
📚 Learning: 2025-08-18T06:11:48.768Z
Learnt from: CR
Repo: woocommerce/woocommerce PR: 0
File: .cursor/rules/woo-phpunit.mdc:0-0
Timestamp: 2025-08-18T06:11:48.768Z
Learning: Applies to plugins/woocommerce/tests/**/*.php : All PHPUnit test methods must be public, not protected
Applied to files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.php
📚 Learning: 2025-08-18T06:11:48.768Z
Learnt from: CR
Repo: woocommerce/woocommerce PR: 0
File: .cursor/rules/woo-phpunit.mdc:0-0
Timestamp: 2025-08-18T06:11:48.768Z
Learning: Applies to plugins/woocommerce/tests/**/*.php : Add declare(strict_types=1); at the top of each test file
Applied to files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.php
📚 Learning: 2025-08-14T08:20:36.357Z
Learnt from: Aljullu
Repo: woocommerce/woocommerce PR: 60191
File: plugins/woocommerce/client/blocks/tests/e2e/tests/single-product-template/single-product-template-compatibility-layer.spec.ts:4-4
Timestamp: 2025-08-14T08:20:36.357Z
Learning: In WooCommerce e2e tests, some test files intentionally use hard-coded "woocommerce/woocommerce//" template IDs instead of BLOCK_THEME_SLUG to test backwards compatibility with the legacy plugin-scoped template ID format. These should not be updated to use the dynamic slug constant as they serve a specific testing purpose.
Applied to files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.php
📚 Learning: 2025-08-18T06:11:48.768Z
Learnt from: CR
Repo: woocommerce/woocommerce PR: 0
File: .cursor/rules/woo-phpunit.mdc:0-0
Timestamp: 2025-08-18T06:11:48.768Z
Learning: Applies to plugins/woocommerce/tests/**/*.php : Test classes should extend WC_Unit_Test_Case
Applied to files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.php
📚 Learning: 2025-06-25T15:39:25.166Z
Learnt from: vladolaru
Repo: woocommerce/woocommerce PR: 59160
File: plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPayments/WooPaymentsServiceTest.php:360-373
Timestamp: 2025-06-25T15:39:25.166Z
Learning: Test mocks should accurately simulate the behavior of the functions they replace, including return value semantics. For WordPress functions like `update_option`, the mock should properly return `false` when the value hasn't changed and `true` when it has, to avoid masking logic errors in tests.
Applied to files:
plugins/woocommerce/tests/php/includes/wc-update-functions-test.php
📚 Learning: 2025-08-15T13:00:31.543Z
Learnt from: opr
Repo: woocommerce/woocommerce PR: 60360
File: plugins/woocommerce/includes/class-woocommerce.php:1553-1563
Timestamp: 2025-08-15T13:00:31.543Z
Learning: The learning from PR #60360 about not needing to clean up legacy scheduled actions when hook names change is specific to that PR's context: PR #59325 was released in WC 10.1 with an incorrect hook name (action_scheduler_schedule_recurring_actions instead of action_scheduler_ensure_recurring_actions), so no actions were actually queued under the old hook name. This is not a general rule for all hook name changes.
Applied to files:
plugins/woocommerce/includes/wc-update-functions.phpplugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php
📚 Learning: 2025-08-14T07:34:00.169Z
Learnt from: opr
Repo: woocommerce/woocommerce PR: 60360
File: plugins/woocommerce/includes/class-woocommerce.php:1533-1544
Timestamp: 2025-08-14T07:34:00.169Z
Learning: When a WordPress action hook name is changed in a PR (like from action_scheduler_schedule_recurring_actions to action_scheduler_ensure_recurring_actions), any code that was previously hooked to the old hook name would not have been executed, so there's no need to clean up or unschedule any legacy scheduled actions that were supposedly created by the old hook.
Applied to files:
plugins/woocommerce/includes/wc-update-functions.phpplugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php
📚 Learning: 2025-07-01T16:24:23.871Z
Learnt from: senadir
Repo: woocommerce/woocommerce PR: 59325
File: plugins/woocommerce/includes/wc-formatting-functions.php:1211-1226
Timestamp: 2025-07-01T16:24:23.871Z
Learning: Action Scheduler is bundled into WooCommerce and always available, so there's no need to add fallback logic to WordPress cron functions when using Action Scheduler functions like as_schedule_single_action() and as_unschedule_all_actions() in WooCommerce code.
Applied to files:
plugins/woocommerce/includes/wc-update-functions.phpplugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php
📚 Learning: 2025-06-17T07:07:53.443Z
Learnt from: samueljseay
Repo: woocommerce/woocommerce PR: 58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:83-101
Timestamp: 2025-06-17T07:07:53.443Z
Learning: In WooCommerce blocks, when porting existing code patterns that have known issues (like parseInt truncating decimal money values), maintain consistency with existing implementation rather than making isolated fixes. The preference is for systematic refactoring approaches (like broader Dinero adoption) over piecemeal changes.
Applied to files:
plugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php
🧬 Code graph analysis (1)
plugins/woocommerce/tests/php/includes/wc-update-functions-test.php (1)
plugins/woocommerce/includes/wc-update-functions.php (1)
wc_update_1040_cleanup_legacy_ptk_patterns_fetching(3136-3139)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (32)
- GitHub Check: Blocks e2e tests 9/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests - Legacy MiniCart 1/3 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 8/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 10/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 7/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 6/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests - Legacy MiniCart - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 5/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 1/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 2/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Metrics - @woocommerce/plugin-woocommerce [performance]
- GitHub Check: Core e2e tests 6/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 3/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 4/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 8.4 WP: latest (HPOS:off) [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Blocks e2e tests 3/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 5/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 8.4 WP: latest (HPOS:off) [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Core API tests - @woocommerce/plugin-woocommerce [api]
- GitHub Check: PHP: 8.4 WP: latest [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.4] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Core e2e tests 2/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 1/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 8.4 WP: latest - Legacy MiniCart [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: PHP: 7.4 WP: pre-release [WP 6.9-beta2] 2/2 - @woocommerce/plugin-woocommerce [unit:php] (optional)
- GitHub Check: PHP: 7.4 WP: pre-release [WP 6.9-beta2] 1/2 - @woocommerce/plugin-woocommerce [unit:php] (optional)
- GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.4] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Core e2e tests 4/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 8.4 WP: latest [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: PHP: 8.4 WP: latest - Legacy MiniCart [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Lint - @woocommerce/plugin-woocommerce
- GitHub Check: build
🔇 Additional comments (4)
plugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php (2)
49-49: LGTM: Hook integration for recurring action schedulerThe integration with
action_scheduler_ensure_recurring_actionscorrectly follows the new WooCommerce pattern for managing recurring scheduled actions.
96-102: LGTM: Guard condition properly prevents schedulingThe method correctly checks tracking status before scheduling and properly delegates to the existing scheduling logic.
plugins/woocommerce/includes/wc-update-functions.php (1)
3136-3139: LGTM: Cleanup correctly removes all legacy actionsThe updater function properly:
- Removes the obsolete
last_fetch_patterns_requestoption- Unschedules all
fetch_patternsactions (correctly omitting the group parameter to clean up both legacy ungrouped actions and any grouped actions)This ensures a clean migration to the new recurring Action Scheduler approach implemented in PTKPatternsStore.
plugins/woocommerce/tests/php/includes/wc-update-functions-test.php (1)
256-274: LGTM: Test properly verifies cleanup behaviorThe test correctly:
- Sets up legacy state (option and ungrouped scheduled action)
- Verifies the cleanup function removes both
- Uses clear assertions with helpful failure messages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php(5 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{php,js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/code-quality.mdc)
**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable
Files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
plugins/woocommerce/tests/**/*.php
📄 CodeRabbit inference engine (.cursor/rules/woo-phpunit.mdc)
plugins/woocommerce/tests/**/*.php: Ensure test classes define public setUp() and tearDown() methods (not protected)
All PHPUnit test methods must be public, not protected
Add declare(strict_types=1); at the top of each test file
Test classes should extend WC_Unit_Test_Case
Files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
**/*.{php,js,jsx,tsx,ts}
📄 CodeRabbit inference engine (.cursor/rules/avoid-regex.mdc)
**/*.{php,js,jsx,tsx,ts}: Avoid using regular expressions unless absolutely necessary to favor readability and maintainability
Only consider regex when no built-in language alternative (string/array APIs) fits the need
Only use regex when performance is critical and faster than alternatives, with measurements to justify
Use regex for complex pattern matching only if the pattern is well-documented and thoroughly tested
Allow regex when maintaining legacy code where an existing, correct pattern is being modified
If regex is necessary, document the pattern extensively to explain what it matches
If regex is necessary, add comprehensive tests covering edge cases and potential security issues
Use named capture groups in regex to improve readability when supported
Validate input before applying regex to ensure it is safe
Assess and mitigate security risks when using regex, including ReDoS and injection vulnerabilities
Avoid regex patterns that can cause catastrophic backtracking (ReDoS)
Do not construct regex from untrusted input to prevent injection attacks
Ensure regex patterns do not overmatch and unintentionally capture unexpected inputs
Files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
**/*.{php,js,ts,jsx,tsx}
⚙️ CodeRabbit configuration file
**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:
- Guards against unexpected inputs.
- Sanitizes and validates any potentially dangerous inputs.
- Is backwards compatible.
- Is readable and intuitive.
- Has unit or E2E tests where applicable.
When making any changes to code that deletes or modifies orders/products/customer data, make sure that there are
sufficient checks in place to prevent accidental data loss. As an example, if deleting a draft order, check that
the order status is indeeddraftorcheckout-draft. Also think about whether race conditions could occur and
delete orders that don't belong to the current customer. When in doubt, ask for clarification in the PR comments.
Files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
🧠 Learnings (20)
📓 Common learnings
Learnt from: opr
Repo: woocommerce/woocommerce PR: 60360
File: plugins/woocommerce/includes/class-woocommerce.php:1553-1563
Timestamp: 2025-08-15T13:00:31.543Z
Learning: The learning from PR #60360 about not needing to clean up legacy scheduled actions when hook names change is specific to that PR's context: PR #59325 was released in WC 10.1 with an incorrect hook name (action_scheduler_schedule_recurring_actions instead of action_scheduler_ensure_recurring_actions), so no actions were actually queued under the old hook name. This is not a general rule for all hook name changes.
Learnt from: opr
Repo: woocommerce/woocommerce PR: 60360
File: plugins/woocommerce/includes/class-woocommerce.php:1533-1544
Timestamp: 2025-08-14T07:34:00.169Z
Learning: When a WordPress action hook name is changed in a PR (like from action_scheduler_schedule_recurring_actions to action_scheduler_ensure_recurring_actions), any code that was previously hooked to the old hook name would not have been executed, so there's no need to clean up or unschedule any legacy scheduled actions that were supposedly created by the old hook.
Learnt from: senadir
Repo: woocommerce/woocommerce PR: 59325
File: plugins/woocommerce/includes/wc-formatting-functions.php:1211-1226
Timestamp: 2025-07-01T16:24:23.871Z
Learning: Action Scheduler is bundled into WooCommerce and always available, so there's no need to add fallback logic to WordPress cron functions when using Action Scheduler functions like as_schedule_single_action() and as_unschedule_all_actions() in WooCommerce code.
Learnt from: prettyboymp
Repo: woocommerce/woocommerce PR: 60272
File: .github/workflows/release-open-issue-warning.yml:15-23
Timestamp: 2025-08-08T13:52:26.423Z
Learning: Repository: woocommerce/woocommerce
Context: .github/workflows/release-open-issue-warning.yml and similar workflows
Learning: Maintainers (per prettyboymp) are fine requiring third-party modules inside actions/github-script without adding setup-node/createRequire. Prefer to keep this pattern and defer structural changes unless it demonstrably causes issues; minor safeguards like version pinning are acceptable if needed.
📚 Learning: 2025-08-18T06:11:48.768Z
Learnt from: CR
Repo: woocommerce/woocommerce PR: 0
File: .cursor/rules/woo-phpunit.mdc:0-0
Timestamp: 2025-08-18T06:11:48.768Z
Learning: Applies to plugins/woocommerce/tests/**/*.php : Add declare(strict_types=1); at the top of each test file
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-18T06:11:48.768Z
Learnt from: CR
Repo: woocommerce/woocommerce PR: 0
File: .cursor/rules/woo-phpunit.mdc:0-0
Timestamp: 2025-08-18T06:11:48.768Z
Learning: Applies to plugins/woocommerce/tests/**/*.php : All PHPUnit test methods must be public, not protected
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-10-24T13:25:49.900Z
Learnt from: hannahtinkler
Repo: woocommerce/woocommerce PR: 61384
File: plugins/woocommerce/tests/php/src/Internal/PushNotifications/Entities/PushTokenTest.php:208-216
Timestamp: 2025-10-24T13:25:49.900Z
Learning: In plugins/woocommerce/tests/**/*.php files, omit setUp() and tearDown() methods when they are not needed, as the project's linting configuration makes it easier to omit these methods than to add them with phpcs:ignore comments.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-18T06:11:48.768Z
Learnt from: CR
Repo: woocommerce/woocommerce PR: 0
File: .cursor/rules/woo-phpunit.mdc:0-0
Timestamp: 2025-08-18T06:11:48.768Z
Learning: Applies to plugins/woocommerce/tests/**/*.php : Test classes should extend WC_Unit_Test_Case
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-14T08:20:36.357Z
Learnt from: Aljullu
Repo: woocommerce/woocommerce PR: 60191
File: plugins/woocommerce/client/blocks/tests/e2e/tests/single-product-template/single-product-template-compatibility-layer.spec.ts:4-4
Timestamp: 2025-08-14T08:20:36.357Z
Learning: In WooCommerce e2e tests, some test files intentionally use hard-coded "woocommerce/woocommerce//" template IDs instead of BLOCK_THEME_SLUG to test backwards compatibility with the legacy plugin-scoped template ID format. These should not be updated to use the dynamic slug constant as they serve a specific testing purpose.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-09-03T11:50:02.208Z
Learnt from: tpaksu
Repo: woocommerce/woocommerce PR: 60735
File: plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Fulfillments/class-wc-rest-fulfillments-v4-controller-tests.php:10-10
Timestamp: 2025-09-03T11:50:02.208Z
Learning: For REST API controller tests in plugins/woocommerce/tests/**/*.php, test classes should extend WC_REST_Unit_Test_Case instead of WC_Unit_Test_Case because REST routes need to be registered before tests run.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-09-09T01:49:42.513Z
Learnt from: peterwilsoncc
Repo: woocommerce/woocommerce PR: 0
File: :0-0
Timestamp: 2025-09-09T01:49:42.513Z
Learning: The WooCommerce Blocks repository uses Playwright for e2e tests, not Jest unit tests (which were deprecated). Express Payment Methods accessibility tests should verify DOM structure changes (div vs ul/li) and screen reader compliance using Playwright's DOM querying capabilities.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-11T18:01:34.499Z
Learnt from: nerrad
Repo: woocommerce/woocommerce PR: 60158
File: plugins/woocommerce/tests/php/includes/class-wc-brands-test.php:207-223
Timestamp: 2025-08-11T18:01:34.499Z
Learning: In the WooCommerce test suite, the team prefers test helper methods to fail immediately with errors (like undefined index) rather than adding defensive checks, as this makes test failures more visible and helps identify setup issues quickly. This applies to helper methods like `get_first_brand_term()` in test files.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-06-25T06:51:41.381Z
Learnt from: samueljseay
Repo: woocommerce/woocommerce PR: 59142
File: plugins/woocommerce/src/Blocks/BlockTypes/MiniCart.php:594-602
Timestamp: 2025-06-25T06:51:41.381Z
Learning: WooCommerce block templates have a predictable structure where each block has one top-level div with wp-block-woocommerce- class containing arbitrary nested content that should be preserved.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-14T08:22:34.886Z
Learnt from: Aljullu
Repo: woocommerce/woocommerce PR: 60191
File: plugins/woocommerce/client/blocks/tests/e2e/tests/product-filters/rating-filter-editor.block_theme.spec.ts:36-36
Timestamp: 2025-08-14T08:22:34.886Z
Learning: In WooCommerce e2e tests, some test files intentionally use hard-coded "woocommerce/woocommerce//" template slugs (not just template IDs) instead of BLOCK_THEME_SLUG to test backwards compatibility with the legacy plugin-scoped template slug format. These should not be updated to use the dynamic slug constant as they serve a specific backwards compatibility testing purpose.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-06-17T07:07:53.443Z
Learnt from: samueljseay
Repo: woocommerce/woocommerce PR: 58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:83-101
Timestamp: 2025-06-17T07:07:53.443Z
Learning: In WooCommerce blocks, when porting existing code patterns that have known issues (like parseInt truncating decimal money values), maintain consistency with existing implementation rather than making isolated fixes. The preference is for systematic refactoring approaches (like broader Dinero adoption) over piecemeal changes.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-22T10:24:05.067Z
Learnt from: yuliyan
Repo: woocommerce/woocommerce PR: 60554
File: plugins/woocommerce/client/blocks/bin/webpack-entries.js:62-62
Timestamp: 2025-08-22T10:24:05.067Z
Learning: WooCommerce blocks use their own block asset API system rather than standard WordPress block.json asset referencing. WC blocks extend AbstractBlock and use methods like get_block_type_editor_script() that leverage $this->asset_api->get_block_asset_build_path() to handle asset registration, instead of defining editorScript, viewScript, or style fields directly in block.json.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-12T14:22:05.865Z
Learnt from: NeosinneR
Repo: woocommerce/woocommerce PR: 60325
File: plugins/woocommerce/tests/php/includes/settings/class-wc-settings-accounts-test.php:0-0
Timestamp: 2025-08-12T14:22:05.865Z
Learning: In WooCommerce settings tests, the woocommerce_enable_delayed_account_creation setting is conditionally present based on wp_is_block_theme() being true OR (wp_is_block_theme() being false AND CartCheckoutUtils::is_checkout_block_default() being true). In test environments with block themes, checking only wp_is_block_theme() is sufficient to determine if the setting should be expected in the settings array.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-06-23T05:47:52.696Z
Learnt from: samueljseay
Repo: woocommerce/woocommerce PR: 59051
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-footer-block/index.tsx:66-70
Timestamp: 2025-06-23T05:47:52.696Z
Learning: For WooCommerce mini-cart blocks in plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/, the standardized conditional pattern for experimental features should be `if ( isExperimentalMiniCartEnabled() ) { blockSettings.save = () => <InnerBlocks.Content />; }` - defaulting to the traditional Save component and only overriding when the experimental feature is enabled.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-06-16T09:20:22.981Z
Learnt from: gigitux
Repo: woocommerce/woocommerce PR: 58846
File: plugins/woocommerce/client/blocks/tests/e2e/tests/all-products/all-products.block_theme.spec.ts:41-52
Timestamp: 2025-06-16T09:20:22.981Z
Learning: In WooCommerce E2E tests, the database is reset to the initial state for each test, so there's no need to manually restore global template changes (like clearing the header template) as the test infrastructure handles cleanup automatically.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-18T06:11:48.768Z
Learnt from: CR
Repo: woocommerce/woocommerce PR: 0
File: .cursor/rules/woo-phpunit.mdc:0-0
Timestamp: 2025-08-18T06:11:48.768Z
Learning: Ensure all dependencies are initialized in setUp() before tests run
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-09T17:57:10.170Z
Learnt from: nerrad
Repo: woocommerce/woocommerce PR: 60158
File: plugins/woocommerce/tests/php/includes/class-wc-brands-test.php:15-23
Timestamp: 2025-08-09T17:57:10.170Z
Learning: WP_UnitTestCase_Base::tearDown() automatically resets the current screen context via set_current_screen(null), so tests extending WP_UnitTestCase (or WC_Unit_Test_Case which extends from it) don't need to manually reset the admin screen context if they call parent::tearDown().
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-06-25T15:39:25.166Z
Learnt from: vladolaru
Repo: woocommerce/woocommerce PR: 59160
File: plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPayments/WooPaymentsServiceTest.php:360-373
Timestamp: 2025-06-25T15:39:25.166Z
Learning: Test mocks should accurately simulate the behavior of the functions they replace, including return value semantics. For WordPress functions like `update_option`, the mock should properly return `false` when the value hasn't changed and `true` when it has, to avoid masking logic errors in tests.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-07-01T16:24:23.871Z
Learnt from: senadir
Repo: woocommerce/woocommerce PR: 59325
File: plugins/woocommerce/includes/wc-formatting-functions.php:1211-1226
Timestamp: 2025-07-01T16:24:23.871Z
Learning: Action Scheduler is bundled into WooCommerce and always available, so there's no need to add fallback logic to WordPress cron functions when using Action Scheduler functions like as_schedule_single_action() and as_unschedule_all_actions() in WooCommerce code.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
🧬 Code graph analysis (1)
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php (1)
plugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php (3)
PTKPatternsStore(13-295)flush_cached_patterns(187-192)ensure_recurring_fetch_patterns_if_enabled(96-102)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (32)
- GitHub Check: Blocks e2e tests - Legacy MiniCart 1/3 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 8.4 WP: latest (HPOS:off) [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Blocks e2e tests 4/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 2/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 8/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core API tests - @woocommerce/plugin-woocommerce [api]
- GitHub Check: Core e2e tests - Legacy MiniCart - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 5/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 10/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 6/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 7/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 9/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 6/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 1/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 8.4 WP: latest (HPOS:off) [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Blocks e2e tests 3/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Metrics - @woocommerce/plugin-woocommerce [performance]
- GitHub Check: Core e2e tests 5/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 8.4 WP: latest [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Core e2e tests 3/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 4/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 2/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 7.4 WP: pre-release [WP 6.9-beta2] 2/2 - @woocommerce/plugin-woocommerce [unit:php] (optional)
- GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.4] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Core e2e tests 1/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 8.4 WP: latest - Legacy MiniCart [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.4] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: PHP: 8.4 WP: latest - Legacy MiniCart [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: PHP: 7.4 WP: pre-release [WP 6.9-beta2] 1/2 - @woocommerce/plugin-woocommerce [unit:php] (optional)
- GitHub Check: PHP: 8.4 WP: latest [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Lint - @woocommerce/plugin-woocommerce
- GitHub Check: build
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php (1)
13-13: Consider extending WC_Unit_Test_Case for WooCommerce-specific tests.The test class extends
\WP_UnitTestCase, but since it tests WooCommerce functionality and uses Action Scheduler (bundled with WooCommerce), extendingWC_Unit_Test_Casewould provide better initialization and cleanup for WooCommerce-specific test scenarios. This is a pre-existing pattern in this file, but worth considering for future refactoring.Based on learnings.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php(5 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{php,js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/code-quality.mdc)
**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable
Files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
plugins/woocommerce/tests/**/*.php
📄 CodeRabbit inference engine (.cursor/rules/woo-phpunit.mdc)
plugins/woocommerce/tests/**/*.php: Ensure test classes define public setUp() and tearDown() methods (not protected)
All PHPUnit test methods must be public, not protected
Add declare(strict_types=1); at the top of each test file
Test classes should extend WC_Unit_Test_Case
Files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
**/*.{php,js,jsx,tsx,ts}
📄 CodeRabbit inference engine (.cursor/rules/avoid-regex.mdc)
**/*.{php,js,jsx,tsx,ts}: Avoid using regular expressions unless absolutely necessary to favor readability and maintainability
Only consider regex when no built-in language alternative (string/array APIs) fits the need
Only use regex when performance is critical and faster than alternatives, with measurements to justify
Use regex for complex pattern matching only if the pattern is well-documented and thoroughly tested
Allow regex when maintaining legacy code where an existing, correct pattern is being modified
If regex is necessary, document the pattern extensively to explain what it matches
If regex is necessary, add comprehensive tests covering edge cases and potential security issues
Use named capture groups in regex to improve readability when supported
Validate input before applying regex to ensure it is safe
Assess and mitigate security risks when using regex, including ReDoS and injection vulnerabilities
Avoid regex patterns that can cause catastrophic backtracking (ReDoS)
Do not construct regex from untrusted input to prevent injection attacks
Ensure regex patterns do not overmatch and unintentionally capture unexpected inputs
Files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
**/*.{php,js,ts,jsx,tsx}
⚙️ CodeRabbit configuration file
**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:
- Guards against unexpected inputs.
- Sanitizes and validates any potentially dangerous inputs.
- Is backwards compatible.
- Is readable and intuitive.
- Has unit or E2E tests where applicable.
When making any changes to code that deletes or modifies orders/products/customer data, make sure that there are
sufficient checks in place to prevent accidental data loss. As an example, if deleting a draft order, check that
the order status is indeeddraftorcheckout-draft. Also think about whether race conditions could occur and
delete orders that don't belong to the current customer. When in doubt, ask for clarification in the PR comments.
Files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
🧠 Learnings (20)
📓 Common learnings
Learnt from: opr
Repo: woocommerce/woocommerce PR: 60360
File: plugins/woocommerce/includes/class-woocommerce.php:1553-1563
Timestamp: 2025-08-15T13:00:31.543Z
Learning: The learning from PR #60360 about not needing to clean up legacy scheduled actions when hook names change is specific to that PR's context: PR #59325 was released in WC 10.1 with an incorrect hook name (action_scheduler_schedule_recurring_actions instead of action_scheduler_ensure_recurring_actions), so no actions were actually queued under the old hook name. This is not a general rule for all hook name changes.
Learnt from: opr
Repo: woocommerce/woocommerce PR: 60360
File: plugins/woocommerce/includes/class-woocommerce.php:1533-1544
Timestamp: 2025-08-14T07:34:00.169Z
Learning: When a WordPress action hook name is changed in a PR (like from action_scheduler_schedule_recurring_actions to action_scheduler_ensure_recurring_actions), any code that was previously hooked to the old hook name would not have been executed, so there's no need to clean up or unschedule any legacy scheduled actions that were supposedly created by the old hook.
Learnt from: senadir
Repo: woocommerce/woocommerce PR: 59325
File: plugins/woocommerce/includes/wc-formatting-functions.php:1211-1226
Timestamp: 2025-07-01T16:24:23.871Z
Learning: Action Scheduler is bundled into WooCommerce and always available, so there's no need to add fallback logic to WordPress cron functions when using Action Scheduler functions like as_schedule_single_action() and as_unschedule_all_actions() in WooCommerce code.
📚 Learning: 2025-08-18T06:11:48.768Z
Learnt from: CR
Repo: woocommerce/woocommerce PR: 0
File: .cursor/rules/woo-phpunit.mdc:0-0
Timestamp: 2025-08-18T06:11:48.768Z
Learning: Applies to plugins/woocommerce/tests/**/*.php : Add declare(strict_types=1); at the top of each test file
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-18T06:11:48.768Z
Learnt from: CR
Repo: woocommerce/woocommerce PR: 0
File: .cursor/rules/woo-phpunit.mdc:0-0
Timestamp: 2025-08-18T06:11:48.768Z
Learning: Applies to plugins/woocommerce/tests/**/*.php : All PHPUnit test methods must be public, not protected
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-10-24T13:25:49.900Z
Learnt from: hannahtinkler
Repo: woocommerce/woocommerce PR: 61384
File: plugins/woocommerce/tests/php/src/Internal/PushNotifications/Entities/PushTokenTest.php:208-216
Timestamp: 2025-10-24T13:25:49.900Z
Learning: In plugins/woocommerce/tests/**/*.php files, omit setUp() and tearDown() methods when they are not needed, as the project's linting configuration makes it easier to omit these methods than to add them with phpcs:ignore comments.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-18T06:11:48.768Z
Learnt from: CR
Repo: woocommerce/woocommerce PR: 0
File: .cursor/rules/woo-phpunit.mdc:0-0
Timestamp: 2025-08-18T06:11:48.768Z
Learning: Applies to plugins/woocommerce/tests/**/*.php : Test classes should extend WC_Unit_Test_Case
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-14T08:20:36.357Z
Learnt from: Aljullu
Repo: woocommerce/woocommerce PR: 60191
File: plugins/woocommerce/client/blocks/tests/e2e/tests/single-product-template/single-product-template-compatibility-layer.spec.ts:4-4
Timestamp: 2025-08-14T08:20:36.357Z
Learning: In WooCommerce e2e tests, some test files intentionally use hard-coded "woocommerce/woocommerce//" template IDs instead of BLOCK_THEME_SLUG to test backwards compatibility with the legacy plugin-scoped template ID format. These should not be updated to use the dynamic slug constant as they serve a specific testing purpose.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-09-03T11:50:02.208Z
Learnt from: tpaksu
Repo: woocommerce/woocommerce PR: 60735
File: plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Fulfillments/class-wc-rest-fulfillments-v4-controller-tests.php:10-10
Timestamp: 2025-09-03T11:50:02.208Z
Learning: For REST API controller tests in plugins/woocommerce/tests/**/*.php, test classes should extend WC_REST_Unit_Test_Case instead of WC_Unit_Test_Case because REST routes need to be registered before tests run.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-09-09T01:49:42.513Z
Learnt from: peterwilsoncc
Repo: woocommerce/woocommerce PR: 0
File: :0-0
Timestamp: 2025-09-09T01:49:42.513Z
Learning: The WooCommerce Blocks repository uses Playwright for e2e tests, not Jest unit tests (which were deprecated). Express Payment Methods accessibility tests should verify DOM structure changes (div vs ul/li) and screen reader compliance using Playwright's DOM querying capabilities.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-12T14:22:05.865Z
Learnt from: NeosinneR
Repo: woocommerce/woocommerce PR: 60325
File: plugins/woocommerce/tests/php/includes/settings/class-wc-settings-accounts-test.php:0-0
Timestamp: 2025-08-12T14:22:05.865Z
Learning: In WooCommerce settings tests, the woocommerce_enable_delayed_account_creation setting is conditionally present based on wp_is_block_theme() being true OR (wp_is_block_theme() being false AND CartCheckoutUtils::is_checkout_block_default() being true). In test environments with block themes, checking only wp_is_block_theme() is sufficient to determine if the setting should be expected in the settings array.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-14T08:22:34.886Z
Learnt from: Aljullu
Repo: woocommerce/woocommerce PR: 60191
File: plugins/woocommerce/client/blocks/tests/e2e/tests/product-filters/rating-filter-editor.block_theme.spec.ts:36-36
Timestamp: 2025-08-14T08:22:34.886Z
Learning: In WooCommerce e2e tests, some test files intentionally use hard-coded "woocommerce/woocommerce//" template slugs (not just template IDs) instead of BLOCK_THEME_SLUG to test backwards compatibility with the legacy plugin-scoped template slug format. These should not be updated to use the dynamic slug constant as they serve a specific backwards compatibility testing purpose.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-11T18:01:34.499Z
Learnt from: nerrad
Repo: woocommerce/woocommerce PR: 60158
File: plugins/woocommerce/tests/php/includes/class-wc-brands-test.php:207-223
Timestamp: 2025-08-11T18:01:34.499Z
Learning: In the WooCommerce test suite, the team prefers test helper methods to fail immediately with errors (like undefined index) rather than adding defensive checks, as this makes test failures more visible and helps identify setup issues quickly. This applies to helper methods like `get_first_brand_term()` in test files.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-06-25T06:51:41.381Z
Learnt from: samueljseay
Repo: woocommerce/woocommerce PR: 59142
File: plugins/woocommerce/src/Blocks/BlockTypes/MiniCart.php:594-602
Timestamp: 2025-06-25T06:51:41.381Z
Learning: WooCommerce block templates have a predictable structure where each block has one top-level div with wp-block-woocommerce- class containing arbitrary nested content that should be preserved.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-06-17T07:07:53.443Z
Learnt from: samueljseay
Repo: woocommerce/woocommerce PR: 58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:83-101
Timestamp: 2025-06-17T07:07:53.443Z
Learning: In WooCommerce blocks, when porting existing code patterns that have known issues (like parseInt truncating decimal money values), maintain consistency with existing implementation rather than making isolated fixes. The preference is for systematic refactoring approaches (like broader Dinero adoption) over piecemeal changes.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-22T10:24:05.067Z
Learnt from: yuliyan
Repo: woocommerce/woocommerce PR: 60554
File: plugins/woocommerce/client/blocks/bin/webpack-entries.js:62-62
Timestamp: 2025-08-22T10:24:05.067Z
Learning: WooCommerce blocks use their own block asset API system rather than standard WordPress block.json asset referencing. WC blocks extend AbstractBlock and use methods like get_block_type_editor_script() that leverage $this->asset_api->get_block_asset_build_path() to handle asset registration, instead of defining editorScript, viewScript, or style fields directly in block.json.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-06-23T05:47:52.696Z
Learnt from: samueljseay
Repo: woocommerce/woocommerce PR: 59051
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-footer-block/index.tsx:66-70
Timestamp: 2025-06-23T05:47:52.696Z
Learning: For WooCommerce mini-cart blocks in plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/, the standardized conditional pattern for experimental features should be `if ( isExperimentalMiniCartEnabled() ) { blockSettings.save = () => <InnerBlocks.Content />; }` - defaulting to the traditional Save component and only overriding when the experimental feature is enabled.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-06-16T09:20:22.981Z
Learnt from: gigitux
Repo: woocommerce/woocommerce PR: 58846
File: plugins/woocommerce/client/blocks/tests/e2e/tests/all-products/all-products.block_theme.spec.ts:41-52
Timestamp: 2025-06-16T09:20:22.981Z
Learning: In WooCommerce E2E tests, the database is reset to the initial state for each test, so there's no need to manually restore global template changes (like clearing the header template) as the test infrastructure handles cleanup automatically.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-18T06:11:48.768Z
Learnt from: CR
Repo: woocommerce/woocommerce PR: 0
File: .cursor/rules/woo-phpunit.mdc:0-0
Timestamp: 2025-08-18T06:11:48.768Z
Learning: Ensure all dependencies are initialized in setUp() before tests run
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-08-09T17:57:10.170Z
Learnt from: nerrad
Repo: woocommerce/woocommerce PR: 60158
File: plugins/woocommerce/tests/php/includes/class-wc-brands-test.php:15-23
Timestamp: 2025-08-09T17:57:10.170Z
Learning: WP_UnitTestCase_Base::tearDown() automatically resets the current screen context via set_current_screen(null), so tests extending WP_UnitTestCase (or WC_Unit_Test_Case which extends from it) don't need to manually reset the admin screen context if they call parent::tearDown().
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-06-25T15:39:25.166Z
Learnt from: vladolaru
Repo: woocommerce/woocommerce PR: 59160
File: plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPayments/WooPaymentsServiceTest.php:360-373
Timestamp: 2025-06-25T15:39:25.166Z
Learning: Test mocks should accurately simulate the behavior of the functions they replace, including return value semantics. For WordPress functions like `update_option`, the mock should properly return `false` when the value hasn't changed and `true` when it has, to avoid masking logic errors in tests.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
📚 Learning: 2025-07-01T16:24:23.871Z
Learnt from: senadir
Repo: woocommerce/woocommerce PR: 59325
File: plugins/woocommerce/includes/wc-formatting-functions.php:1211-1226
Timestamp: 2025-07-01T16:24:23.871Z
Learning: Action Scheduler is bundled into WooCommerce and always available, so there's no need to add fallback logic to WordPress cron functions when using Action Scheduler functions like as_schedule_single_action() and as_unschedule_all_actions() in WooCommerce code.
Applied to files:
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php
🧬 Code graph analysis (1)
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php (1)
plugins/woocommerce/src/Blocks/Patterns/PTKPatternsStore.php (3)
PTKPatternsStore(13-295)flush_cached_patterns(187-192)ensure_recurring_fetch_patterns_if_enabled(96-102)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (32)
- GitHub Check: Blocks e2e tests 1/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 10/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests - Legacy MiniCart 1/3 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 7/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 2/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 3/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 9/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 5/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core API tests - @woocommerce/plugin-woocommerce [api]
- GitHub Check: PHP: 7.4 WP: pre-release [WP 6.9-beta2] 1/2 - @woocommerce/plugin-woocommerce [unit:php] (optional)
- GitHub Check: Blocks e2e tests 6/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.4] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: PHP: 8.4 WP: latest - Legacy MiniCart [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: PHP: 8.4 WP: latest (HPOS:off) [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Blocks e2e tests 8/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 4/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 4/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests - Legacy MiniCart - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Metrics - @woocommerce/plugin-woocommerce [performance]
- GitHub Check: PHP: 7.4 WP: pre-release [WP 6.9-beta2] 2/2 - @woocommerce/plugin-woocommerce [unit:php] (optional)
- GitHub Check: PHP: 8.4 WP: latest (HPOS:off) [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Core e2e tests 6/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 3/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 8.4 WP: latest [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Core e2e tests 5/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 8.4 WP: latest - Legacy MiniCart [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Core e2e tests 2/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 1/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.4] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: PHP: 8.4 WP: latest [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Lint - @woocommerce/plugin-woocommerce
- GitHub Check: build
🔇 Additional comments (2)
plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKPatternsStoreTest.php (2)
33-57: Excellent test setup and cleanup.The public visibility for
setUp()andtearDown()is correct, and the cleanup logic (unscheduling actions, deleting options) ensures proper test isolation. This prevents test pollution and follows PHPUnit best practices.
135-143: LGTM! Comprehensive test coverage for the new recurring action functionality.The new tests thoroughly cover the
ensure_recurring_fetch_patterns_if_enabled()functionality:
- Verifies actions are scheduled when tracking is enabled
- Verifies actions are NOT scheduled when tracking is disabled
- Confirms
flush_cached_patterns()properly unschedules both single and recurring actionsThe updated assertions now correctly include the
'woocommerce'group parameter, matching how actions are scheduled in the implementation. All tests follow best practices with clear names, descriptive assertion messages, and proper arrange-act-assert structure.Also applies to: 200-200, 436-473
Changes proposed in this Pull Request:
Updates the PTKPatternsStore so that it uses the newer
action_scheduler_ensure_recurring_actionsaction to keep the schedule of fetching updated PTK Patterns instead of running a query to see if the action already exists.Closes WOOPLUG-5765 / #61722 .
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
fetch_patterns.fetch_patternsactions.