Skip to content

Fix: Improve wp_unique_id_from_values() unit tests#8590

Closed
Debarghya-Banerjee wants to merge 5 commits intoWordPress:trunkfrom
Debarghya-Banerjee:fix/63175-improve-wp_unique_id_from_values-unit-tests
Closed

Fix: Improve wp_unique_id_from_values() unit tests#8590
Debarghya-Banerjee wants to merge 5 commits intoWordPress:trunkfrom
Debarghya-Banerjee:fix/63175-improve-wp_unique_id_from_values-unit-tests

Conversation

@Debarghya-Banerjee
Copy link
Copy Markdown

@Debarghya-Banerjee Debarghya-Banerjee commented Mar 25, 2025

Trac Ticket: Core-63175

Problem Statement

The original unit tests for the wp_unique_id_from_values() function relied on specific hash outputs, which caused test failures in certain hosting environments due to differences in how data is serialized and hashed. These tests assumed consistent hash values across all environments for the same input, which was not guaranteed. Additionally, the tests did not properly validate the handling of the prefix parameter.

Solution

  • Ensured Consistent Output:

    • The tests were updated to ensure that the same input data consistently produces the same ID, regardless of the environment. This removes the reliance on specific hash values and focuses on validating consistent behavior.
  • Verified Uniqueness:

    • The tests now verify that different input values result in distinct, unique IDs. This ensures the function generates unique identifiers for different data sets.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 25, 2025

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 debarghyabanerjee, joemcgill.

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

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Copy Markdown
Member

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks @Debarghya-Banerjee!

This looks pretty close to what I had in mind. A couple quick observations:

  1. Given that all dataProvider responses return the same $prefix value, we can probably eliminate that and only return the data for each set.
  2. Rather than $output1, $output2, etc. Can the variable names be more descriptive? $unique_id_1, $unique_id_prefixed_1, etc.?

@Debarghya-Banerjee
Copy link
Copy Markdown
Author

Hi @joemcgill, I have pushed the updates, can you please have a look into it once. Thanks.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2025

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 60113
GitHub commit: c90b212

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions bot closed this Apr 1, 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.

2 participants