#39079 closed enhancement (fixed)
REST API: Improve posts orderby tests
Reported by: | jnylen0 | Owned by: | jnylen0 |
---|---|---|---|
Milestone: | 4.8 | Priority: | normal |
Severity: | normal | Version: | |
Component: | REST API | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
The attached patch improves tests for the orderby
parameter in WP_REST_Posts_Controller
:
- Add tests for
orderby=relevance
combined with a search term - Instead of creating posts for a few tests, just look at the generated SQL query instead.
(2) is interesting because it is a start at testing all of our collection filtering parameters in a much more robust way: look at the SQL generated by WP_Query
and make sure it looks as expected.
This is much easier and more robust than the existing tests because we don't have to carefully arrange test objects so that they are returned in the expected order, and it also has the potential to be much faster, because if all of our filter parameters are covered by SQL checks, we don't even have to create any objects to test.
This will also provide a much easier way to test future filtering enhancements like multiple orderby
values together (see #39037).
I'm going to commit this because it will help out in other places - most immediately, #39055.