Skip to content

Tests: Add unit test coverage for Block Bindings core/term-data source - #13981

Closed
huzaifaalmesbah wants to merge 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:tests/block-bindings-term-data
Closed

huzaifaalmesbah wants to merge 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:tests/block-bindings-term-data

Conversation

@huzaifaalmesbah

@huzaifaalmesbah huzaifaalmesbah commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

This PR adds comprehensive unit test coverage for the Block Bindings core/term-data source (src/wp-includes/block-bindings/term-data.php) in tests/phpunit/tests/block-bindings/termDataSource.php.

The core/term-data source was introduced in r60946 (#64107) and updated in r60958 (#64112), but lacked a dedicated PHPUnit test file verifying its getter callback, boundary conditions, navigation block attribute fallbacks, permission checks, and source registration.

Trac ticket: https://core.trac.wordpress.org/ticket/65819

Changes & New Tests Added

  1. Input validation & boundary checks:

    • test_get_value_returns_null_when_field_empty: Verifies null is returned when the field argument is omitted or empty (tested via data provider).
    • test_get_value_returns_null_when_context_empty: Verifies null is returned when required block context (termId or taxonomy) is missing or invalid.
    • test_get_value_returns_null_when_term_not_found: Confirms null return for non-existent terms.
    • test_get_value_returns_null_when_taxonomy_invalid: Confirms null return for invalid taxonomy names.
    • test_get_value_returns_null_for_unsupported_field: Confirms null return for unrecognized field keys.
  2. Supported field value computation:

    • test_get_value_returns_supported_fields: Data provider testing name, slug, description, and count.
    • test_get_value_link_field: Tests term permalink generation via get_term_link().
    • test_get_value_id_and_parent_fields: Tests string casting and escaping for term ID and parent ID.
  3. Navigation block compatibility:

    • test_get_value_navigation_link_attributes: Verifies reading id and type attributes for core/navigation-link.
    • test_get_value_navigation_submenu_attributes: Verifies reading attributes for core/navigation-submenu.
    • test_get_value_navigation_link_maps_tag_type_to_post_tag: Verifies UI shorthand tag mapping to post_tag taxonomy slug.
    • test_get_value_navigation_link_missing_attributes: Verifies null return when navigation attributes are missing.
  4. Permissions & visibility:

    • test_get_value_non_publicly_queryable_taxonomy_unauthenticated: Verifies unauthenticated users cannot read private taxonomies.
    • test_get_value_non_publicly_queryable_taxonomy_with_read_capability: Verifies users with read capability can access private taxonomies.
  5. Source registration & integration:

    • test_register_block_bindings_term_data_source: Verifies source registration metadata (label, uses_context).
    • test_register_block_bindings_term_data_source_idempotent: Verifies registration idempotence.
    • test_source_get_value_integration: Verifies end-to-end lookup through WP_Block_Bindings_Source::get_value().

Testing Instructions

Run the unit test suite:

npm run test:php -- --filter Tests_Block_Bindings_Term_Data_Source

Run multisite:

npm run test:php -- --filter Tests_Block_Bindings_Term_Data_Source -c tests/phpunit/multisite.xml

Run the entire block-bindings test group:

npm run test:php -- --group block-bindings

Use of AI Tools

AI assistance: Yes
Model(s): Gemini 3.8 Flash
Used for: Analyzing execution branches and edge cases in src/wp-includes/block-bindings/term-data.php, structuring test cases with data providers, and drafting this PR summary. All generated tests (28 tests, 34 assertions across single-site and multisite) and coding standards compliance were reviewed, executed, and verified locally in a Docker environment.

@github-actions

github-actions Bot commented Oct 4, 2026 •

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 huzaifaalmesbah, lancewillett.

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

@lancewillett
lancewillett self-requested a review October 4, 2026 19:32
@lancewillett

Copy link
Copy Markdown
Member

Optional follow-up for this PR: add markup/entity fixtures with literal expected output to protect name escaping and description sanitization. The current plain-text fixtures do not detect removal of those transformations.

wporg-sync pushed a commit that referenced this pull request Oct 4, 2026
Add tests for `core/term-data` field values, missing or invalid inputs, navigation block attributes, and access to non-publicly queryable taxonomies. Verify source registration metadata, repeated registration, and value retrieval through the registered source.

Developed in: #13981

Props huzaifaalmesbah.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@64086 602fd350-edb4-49c9-b593-d223f7449a82
@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 4, 2026
Add tests for `core/term-data` field values, missing or invalid inputs, navigation block attributes, and access to non-publicly queryable taxonomies. Verify source registration metadata, repeated registration, and value retrieval through the registered source.

Developed in: WordPress/wordpress-develop#13981

Props huzaifaalmesbah.
See #65819.

Built from https://develop.svn.wordpress.org/trunk@64086


git-svn-id: http://core.svn.wordpress.org/trunk@63245 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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