Skip to content

Conversation

@priethor
Copy link
Contributor

What

Part of #315.

Adds PHPUnit test coverage for SCF helper and utility functions in acf-helper-functions.php and acf-utility-functions.php.

Why

Helper functions provide foundational utilities used throughout SCF (empty checks, sanitization, filters, string formatting). Utility functions manage core patterns like singletons, stores, and path resolution. Tests ensure these building blocks work correctly.

How

Adding 159 tests covering:

  • Empty checks with numeric edge cases (acf_is_empty, acf_not_empty)
  • Unique ID generation and counter management
  • Attribute merging with class/style concatenation
  • Filter enable/disable/get/set state management
  • ID extraction from arrays, objects, and scalars
  • Numeric type conversion and formatting
  • String utilities (idify, slugify, punctify, strlen)
  • Request sanitization with XSS prevention
  • File upload array sanitization
  • Secure unserialization blocking class instantiation
  • Singleton pattern implementation
  • Data store registration and retrieval
  • Path and URL resolution

Testing Instructions

Run the test suite: ./vendor/bin/phpunit --filter "Test_ACF_Helper_Functions|Test_ACF_Utility_Functions"

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

@priethor priethor changed the title Tests: Add comprehensive tests for helper and utility functions Tests: Add PHPUnit tests for helper and utility functions Dec 30, 2025
Add 159 tests covering acf-helper-functions.php (136 tests) and
acf-utility-functions.php (23 tests) with 222 assertions total.

Helper function tests cover:
- acf_is_empty/acf_not_empty with numeric edge cases
- acf_uniqid counter and prefix behavior
- acf_merge_attributes class/style concatenation
- Filter enable/disable/get/set operations
- acf_idval/acf_maybe_idval ID extraction
- acf_format_numerics/acf_numval type conversion
- acf_idify/acf_slugify/acf_punctify string formatting
- acf_strlen with line breaks and multibyte chars
- acf_sanitize_request_args type handling and XSS prevention
- acf_sanitize_files_array single and multiple file handling
- acf_maybe_unserialize with class blocking security

Utility function tests cover:
- acf_new_instance/acf_get_instance singleton pattern
- acf_register_store/acf_get_store data management
- acf_get_path/acf_get_url path resolution
- acf_include path handling behavior

All tests use data providers for comprehensive edge case coverage
and include documentation for non-obvious behavior.
@priethor priethor force-pushed the add/helper-utility-function-tests branch from 1ca2bb9 to c2fb444 Compare December 30, 2025 12:26
@priethor priethor mentioned this pull request Dec 30, 2025
22 tasks
@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 17.22%. Comparing base (f0036e7) to head (c2fb444).
⚠️ Report is 5 commits behind head on trunk.

Additional details and impacted files
@@             Coverage Diff              @@
##              trunk     #328      +/-   ##
============================================
+ Coverage     16.68%   17.22%   +0.53%     
  Complexity     4410     4410              
============================================
  Files           291      291              
  Lines         36995    36995              
============================================
+ Hits           6173     6372     +199     
+ Misses        30822    30623     -199     
Flag Coverage Δ
e2e 28.87% <ø> (ø)
javascript 2.50% <ø> (ø)
phpunit 15.62% <ø> (+0.73%) ⬆️

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 merged commit 646f3de into trunk Dec 30, 2025
9 checks passed
@priethor priethor deleted the add/helper-utility-function-tests branch December 30, 2025 12:37
@priethor priethor self-assigned this Dec 30, 2025
@priethor priethor added this to the 6.8.0 milestone Dec 30, 2025
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