Make WordPress Core

Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#39079 closed enhancement (fixed)

REST API: Improve posts orderby tests

Reported by: jnylen0's profile jnylen0 Owned by: jnylen0's profile jnylen0
Milestone: 4.8 Priority: normal
Severity: normal Version:
Component: REST API Keywords: has-patch commit
Focuses: Cc:


The attached patch improves tests for the orderby parameter in WP_REST_Posts_Controller:

  1. Add tests for orderby=relevance combined with a search term
  2. 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).

Attachments (1)

39079.diff (6.6 KB) - added by jnylen0 8 years ago.

Download all attachments as: .zip

Change History (6)

8 years ago

#1 @jnylen0
8 years ago

  • Keywords dev-feedback added

#2 @jnylen0
7 years ago

  • Keywords commit added; dev-feedback removed

I'm going to commit this because it will help out in other places - most immediately, #39055.

#3 @jnylen0
7 years ago

  • Owner set to jnylen0
  • Resolution set to fixed
  • Status changed from new to closed

In 40037:

REST API: Improve posts orderby tests

This commit adds tests for orderby=relevance combined with a search term in the REST API.

It also improves tests for the orderby parameter in WP_REST_Posts_Controller by looking at the generated SQL query instead of creating a bunch of carefully arranged test objects. This should be much more robust, and we can use this approach in other places (such as #39055).

Fixes #39079.

#4 @swissspidy
7 years ago

  • Milestone changed from Future Release to 4.8

#5 @ocean90
7 years ago

In 40136:

REST API: Fix behavior of sticky posts filter when no posts are sticky.

Previously, when getting posts from the API with sticky=true, if there were no sticky posts set, the query would return all posts as if the sticky argument was not set. In this situation, the query should return an empty array instead.

A sticky=true query that should return an empty array (in the previous situation, or with include and no intersecting post IDs) was also broken in that it would query the post with ID 1.

Finally, this commit significantly improves test coverage for the sticky filter argument, including direct testing of the WHERE clauses generated by WP_Query.

Merge of [40037] and [40122] to the 4.7 branch.

Props ryelle, jnylen0.
See #39079.
Fixes #39947.

Note: See TracTickets for help on using tickets.