test: REST PHPUnit tests#212
Conversation
There was a problem hiding this comment.
Pull request overview
Adds initial PHPUnit coverage for the REST layer in OneSearch, focusing on controller route registration, permission-sensitive behavior, and governing/consumer data flows. This fits the codebase by expanding unit coverage around the plugin’s cross-site REST integration points.
Changes:
- Adds new unit test files for the abstract REST controller and the main REST controllers/handler.
- Covers route registration, option reads/writes, brand config retrieval, indexable entities, and reindex behavior.
- Adds permission and origin/header checks for same-origin and cross-origin REST requests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
tests/php/Unit/Modules/Rest/Abstract_REST_ControllerTest.php |
Adds tests for hook registration, API permission checks, and host/origin matching. |
tests/php/Unit/Modules/Rest/Basic_Options_ControllerTest.php |
Adds tests for basic settings REST endpoints such as site type, shared sites, health check, and governing site. |
tests/php/Unit/Modules/Rest/Governing_Data_ControllerTest.php |
Adds tests for brand-config and all-post-types controller behavior across site types. |
tests/php/Unit/Modules/Rest/Governing_Data_HandlerTest.php |
Adds tests for governing-data fetch/caching, child-site post type retrieval, and cache clearing. |
tests/php/Unit/Modules/Rest/Search_ControllerTest.php |
Adds tests for search controller routes, Algolia credentials, indexable entities, and reindex behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
We may need to mock some things to finish testing the important parts of this class. Will know more once everything's been converted to use $this->server->dispatch()
There was a problem hiding this comment.
Okay, looks like the only thing here still missing is a successful ::update_algolia_credentials(), but I think that's fine, considering the validation is done by the client we're about to replace.
There was a problem hiding this comment.
Same with Abstract_REST_Controller. We can come back for those later when we need them.
There was a problem hiding this comment.
These test cases look really good - great job @Kallyan01 !
As noted, we want these to be outcome-focused integration tests and get as close to making real REST requests as possible instead of calling the controller methods directly, and gotta ditch the // ai slop comments everywhere. Once that's done it'l be easier to spot if there's something missing or more likely if there's some that are too "implementation-detail" focused that we want to ditch.
Either way, shouldn't take much before we can merge 🙌
…t classes and removed test file for Abstract_REST_Controller
…mline route registration
…ller across different site types
|
@Kallyan01 in the future, please allow the creator of the comment or approver to resolve open comments. GitHub's UX makes it really hard to track otherwise. |
|
Great work @Kallyan01 🚀 As [noted], there's a few edge cases in the SearchController and our Abstract_REST_Controller that we still want to cover, but I'm fine doing that in a followup PR as those areas of the codebase become relevant. |
Sure, i'll keep the suggestions open in future. |
What
Added REST 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