Skip to content

Add unit tests for RegisteredDataHandler - #1402

Open
noruzzamans wants to merge 1 commit into
10up:developfrom
noruzzamans:test/registered-data-handler-unit-tests
Open

noruzzamans wants to merge 1 commit into
10up:developfrom
noruzzamans:test/registered-data-handler-unit-tests

Conversation

@noruzzamans

Copy link
Copy Markdown

Description of the Change

Adds a comprehensive unit test suite for the Distributor\RegisteredDataHandler class introduced in Distributor 2.2.0, which handles registered data processing across post content, Gutenberg blocks, shortcodes, post meta, and taxonomy terms.

Prior to this PR, Distributor\RegisteredDataHandler had 0% unit test coverage. This PR provides 100% test-only coverage (29 unit tests, 49 assertions) covering:

  1. Instantiation & Connection State: Verifies default empty state and custom connection array assignment.
  2. Block Inner Content Replacements (search_replace_block_inner_content): Tests empty replacement handling and multi-string replacements across both innerHTML and innerContent.
  3. Term Extra Data Preparation (prepare_registered_data_term): Tests invalid/null/WP_Error term handling, flat taxonomy terms, and hierarchical terms with recursive parent data.
  4. Term Data Processing (process_registered_data_term): Tests empty term data, existing terms, hierarchy updates when parents differ, new term insertion via wp_insert_term(), and error handling when term creation fails.
  5. Post Meta Data Processing (process_registered_post_meta_data): Tests missing callbacks/keys, single string meta keys, single-element array wrapped keys, and multi-key batch updates.
  6. Block Content Processing (process_blocks_data_recursive & process_registered_block_data): Tests uncallable callbacks, matching block attribute updates, media block replacement (URL, wp-image-* class, and GUID updates), nested innerBlocks recursion, and fallback when has_block() returns false.
  7. Shortcode Processing (process_registered_shortcode_data): Tests fallback when has_shortcode() returns false, single attribute replacements, and multiple attribute replacements.
  8. Pipeline Orchestration (process_registered_data & pre_process_registered_data_post): Tests filter bypass (dt_process_extra_data), empty registry, meta pipeline dispatching, and external connection pre-processing guards.

How to test the Change

Run the PHPUnit test suite locally:

composer test

Or run the dedicated test class directly:

vendor/bin/phpunit --filter RegisteredDataHandlerTest

All 29 tests should execute and pass without errors or regressions.

Changelog Entry

Added - Unit tests for RegisteredDataHandler.

Credits

Props @noruzzamans

Checklist:

@noruzzamans
noruzzamans marked this pull request as ready for review September 20, 2026 09:03
@noruzzamans
noruzzamans requested a review from a team as a code owner September 20, 2026 09:03
@noruzzamans
noruzzamans requested review from peterwilsoncc and removed request for a team September 20, 2026 09:03
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