Skip to content

Tests: Add PHPUnit tests for helper and utility functions#327

Closed
priethor wants to merge 1 commit intotrunkfrom
tests/helper-utility-functions
Closed

Tests: Add PHPUnit tests for helper and utility functions#327
priethor wants to merge 1 commit intotrunkfrom
tests/helper-utility-functions

Conversation

@priethor
Copy link
Copy Markdown
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"

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

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
Copy Markdown

codecov bot commented Dec 30, 2025

Codecov Report

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

Additional details and impacted files
@@             Coverage Diff              @@
##              trunk     #327      +/-   ##
============================================
+ Coverage     13.55%   17.22%   +3.66%     
- Complexity     4404     4410       +6     
============================================
  Files           291      291              
  Lines         36984    36995      +11     
============================================
+ Hits           5014     6372    +1358     
+ Misses        31970    30623    -1347     
Flag Coverage Δ
e2e 28.87% <ø> (ø)
javascript 2.50% <ø> (ø)
phpunit 15.62% <ø> (+5.02%) ⬆️

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 closed this Dec 30, 2025
@priethor priethor deleted the tests/helper-utility-functions branch December 30, 2025 12:21
@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
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.

1 participant