Skip to content

Conversation

@priethor
Copy link
Contributor

@priethor priethor commented Dec 30, 2025

What

Part of #315.

Adds PHPUnit test coverage for the REST API integration classes and helper functions.

Why

The REST API integration is critical for exposing SCF field data through WordPress REST endpoints. It handles:

  • Field value formatting for REST responses
  • Schema generation for field types
  • Request parsing and object type detection
  • Embed link preparation for related resources
  • Permission and visibility filtering via show_in_rest

How

Adding 134 tests across 4 test files:

  • test-acf-rest-api.php - Tests for ACF_Rest_Api class: initialization, hooks, schema generation, field loading, filtering by show_in_rest, location matching, admin mode detection, REST format settings
  • test-acf-rest-request.php - Tests for ACF_Rest_Request class: request parsing, URL parameter handling (_fields, _embed), object type detection, route matching, HTTP method detection
  • test-acf-rest-embed-links.php - Tests for ACF_Rest_Embed_Links class: link preparation, response integration, field link building, hook registration
  • test-acf-rest-api-functions.php - Tests for helper functions: acf_get_field_rest_schema() schema generation with filter hooks, acf_format_value_for_rest() value formatting, acf_get_field_rest_links() link generation, filter variations by type/name/key

Testing Instructions

./vendor/bin/phpunit --filter "Test_ACF_Rest"

@github-actions
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.

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

Props priethor.

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

@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 23.67%. Comparing base (1e33a3a) to head (707c905).
⚠️ Report is 1 commits behind head on trunk.

Additional details and impacted files
@@             Coverage Diff              @@
##              trunk     #332      +/-   ##
============================================
+ Coverage     22.86%   23.67%   +0.80%     
  Complexity     4410     4410              
============================================
  Files           291      291              
  Lines         36940    36940              
============================================
+ Hits           8448     8745     +297     
+ Misses        28492    28195     -297     
Flag Coverage Δ
e2e 28.87% <ø> (ø)
javascript 6.53% <ø> (ø)
phpunit 22.98% <ø> (+1.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@priethor priethor force-pushed the de68-phase-2-pr-10-re branch 2 times, most recently from 9dd3270 to 8d7fe26 Compare December 30, 2025 15:29
@priethor priethor mentioned this pull request Dec 30, 2025
22 tasks
@priethor priethor added this to the 6.9.0 milestone Dec 30, 2025
@priethor priethor self-assigned this Dec 31, 2025
@priethor priethor force-pushed the de68-phase-2-pr-10-re branch 3 times, most recently from cf04582 to 43e3104 Compare December 31, 2025 03:03
Add comprehensive tests for the REST API integration:

- test-acf-rest-api.php: Tests for ACF_Rest_Api class including
  initialization, schema generation, field loading, and filtering
- test-acf-rest-api-functions.php: Tests for helper functions like
  acf_get_field_rest_schema() and acf_format_value_for_rest()
- test-acf-rest-embed-links.php: Tests for ACF_Rest_Embed_Links class
  covering link preparation and response integration
- test-acf-rest-request.php: Tests for ACF_Rest_Request class
  including request parsing and URL parameter handling

Test coverage includes:
- REST API initialization and configuration
- Schema generation and structure validation
- Field loading with show_in_rest filtering
- Request parsing and object type detection
- Embed link preparation and loading
- Filter hook integration (acf/rest/* hooks)
- Admin mode detection
- REST API format settings (light/standard)
- Error handling and edge cases

143 tests with 200 assertions. Some tests are skipped in WorDBless
environment due to field type and location type registration limitations.
@priethor priethor force-pushed the de68-phase-2-pr-10-re branch from 43e3104 to 707c905 Compare December 31, 2025 03:06
@priethor priethor merged commit 42c4ac8 into trunk Dec 31, 2025
9 checks passed
@priethor priethor deleted the de68-phase-2-pr-10-re branch December 31, 2025 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants