test: Search PHPUnit tests#213
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds PHPUnit unit tests for the Search module’s WordPress integration points and for the Algolia Index wrapper, helping validate hook registration and several “remote post” mapping behaviors.
Changes:
- Add
SearchTestcovering hook registration and selected behaviors for permalinks, author fields, term links, and rendered block rewriting. - Add
IndexTestcovering error returns when prerequisites are missing and verifyingIndex::get_index()caching behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| tests/php/Unit/Modules/Search/SearchTest.php | Introduces unit tests for OneSearch\Modules\Search\Search behaviors (hooks, mapping, block output). |
| tests/php/Unit/Modules/Search/IndexTest.php | Introduces unit tests for OneSearch\Modules\Search\Index error handling and caching. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sabbir1991
left a comment
There was a problem hiding this comment.
Please review the coverage HTML again and check the functions are fully covered which test you have written
… Index and Search modules
…s during delete, save, and search operations
…t, and WatcherTest
justlevine
left a comment
There was a problem hiding this comment.
Great first pass! 🙌 Especially a fan of daab8dc before I even asked ;-)
Just some minor cleanup and trying to cover the few areas the coverage report missed. We'll be refactoring soon though, so if something I asked for isn't easily testable, lmk and maybe we'll skip it.
…ling and remove unused code
…ges in SettingsTest and WatcherTest
… resets and updating settings test logic
| /** | ||
| * Returns true when index_all_posts is called with no post types and valid credentials. | ||
| */ | ||
| public function test_index_all_posts_returns_true_with_valid_credentials_and_no_post_types(): void { |
There was a problem hiding this comment.
I think we need one more successful index_all_posts with 101 posts, so it triggers ::generate_post_batches(), but I'm on the fence.
@Kallyan01 thoughts?
There was a problem hiding this comment.
Added the case, I think it's a good testcase to add.
justlevine
left a comment
There was a problem hiding this comment.
These look good!
I'm wondering if it's worth it for you to do one more pass through the coverage report, and see if there's some more low-hanging you can catch here, e.g. from a brand site, w. author info, composite scores, > 100 posts, etc. Still outcome based, nothing that requires elaborate stubbing.
Alternatively, we can skip them now add the coverage to the areas that we refactor, the missing areas aren't particularly important for back-compat, just catching unintentional breaks...
@Kallyan01 can you take a look at the report and let me know which - if any - you think are worth doing now vs later?
Sure, I've started looking into it, I'll let you know if I find something. |

What
Added Search Module PHPUnit test cases.
Why
Improves development workflow by enabling faster and more reliable validation of REST functionality, reducing repetitive manual testing efforts.
Related Issue(s):
How
AI Disclosure
Hybrid approach = Written by Me + Copilot (Claude Opus 4.6, GPT 5.3) + Audited by me
Testing Instructions
Screenshots
Additional Info
Checklist