Skip to content
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

62292 warning in wp rest posts controllerget items #8021

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

pbearne
Copy link

@pbearne pbearne commented Dec 18, 2024

Paul Bearne and others added 2 commits December 18, 2024 12:19
…`WP-REST-Global-Styles-Revisions-Controller-Test.php` file (previously named `rest-global-styles-revisions-controller.php`). This test verifies the pagination functionality of the REST API endpoint for global styles revisions.

Here's a breakdown:

1. **Revision Creation:** The test begins by creating 15 revisions for a global style (using `self::$global_styles_id`). This sets up the scenario for testing pagination.

2. **Offset Test:** It then makes a request to the `/wp/v2/global-styles/{global_style_id}/revisions` endpoint with `offset=5` and `per_page=5`. This should return revisions 6-10.  The test asserts:
    - A 200 OK status code.
    - 5 items in the response data.
    - `X-WP-Total` header equals 15 (total revisions).
    - `X-WP-TotalPages` header equals 3 (given 5 per page).

3. **Paged Test:** Next, it tests "paged" requests, setting `page=2` and `per_page=6`.  This should return revisions 7-12. The assertions are similar to the offset test, checking for 6 items and the same total/total pages headers.

4. **Out of Bounds Test:**  Finally, the test attempts to fetch an out-of-bounds page (`page=4`, `per_page=6`). It expects a `rest_revision_invalid_page_number` error with a 400 Bad Request status code, confirming proper handling of invalid pagination parameters.

In summary, this new test ensures that the global styles revisions endpoint correctly handles `offset`, `page`, and `per_page` parameters, returns the expected number of results, and provides accurate pagination headers (`X-WP-Total` and `X-WP-TotalPages`).  It also tests error handling for invalid page numbers.
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @[email protected].

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

Core Committers: Use this line as a base for the props when committing in SVN:

Props pbearne.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Paul Bearne added 2 commits December 19, 2024 18:00
Unified and improved pagination handling in REST API controllers by ensuring 'paged' parameter is checked for existence before casting. Updated tests for global styles, posts, and templates to validate pagination behavior, including edge cases like offsets and out-of-bounds pages. Renamed and reorganized test files for clarity.
…ontrollerget_items' into 62292-Warning-in-WP_REST_Posts_Controllerget_items
Copy link

@apermo apermo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, besides the question regarding the new lines.

Comment on lines +5705 to +5706


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add these two new lines?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants