Repository navigation
Tests: Add unit tests for wp_theme_get_element_class_name(). - #16192
rejaulalomkhan wants to merge 2 commits into
Conversation
Cover known elements ('button', 'caption'), non-registered elements, empty string, and unknown elements.
See #56467.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
mukeshpanchal27
left a comment
There was a problem hiding this comment.
Thanks for adding coverage for this function. The tests pass and the history in the description is right: r54174 added wp_theme_get_element_class_name(). I left two small inline comments.
One more, non-blocking: the function only calls WP_Theme_JSON::get_element_class_name(), and tests/phpunit/tests/theme/wpThemeJson.php already tests that method for 'button' and an unknown element (test_get_element_class_name_button() and test_get_element_class_name_invalid()). The new cases here are 'caption', 'heading', and the empty string. A committer may prefer either one test that checks the wrapper returns the same value as the method, or adding the new cases to the existing tests.
| /** | ||
| * Test wp_theme_get_element_class_name(). | ||
| * | ||
| * @group theme |
There was a problem hiding this comment.
The test files in tests/phpunit/tests/theme/ use @group themes. With theme, running --group themes skips this file.
| * @group theme | |
| * @group themes |
| /** | ||
| * Tests that wp_theme_get_element_class_name() returns correct class name for known and unknown elements. | ||
| * | ||
| * @ticket 56467 |
There was a problem hiding this comment.
#56467 is the WordPress 6.1 backport ticket from 2022. New test coverage usually goes on an open ticket. Recent coverage commits, such as the wp_default_editor() tests in r65747, use #65819. Could this tag and the PR's Trac ticket line point to #65819 instead?
There was a problem hiding this comment.
🟡 Changes recommended
The tests use the singular theme group instead of the established themes group, causing all five cases to be omitted when running --group themes.
1 open issue
What changed in this PR
Adds direct unit coverage for wp_theme_get_element_class_name(), the public alias for WP_Theme_JSON::get_element_class_name(), without changing production code.
Changes:
- Adds a data-driven test with five cases.
- Verifies class names for button and caption elements, and empty-string results for unsupported or empty element names.
| File | Description |
|---|---|
tests/phpunit/tests/theme/wpThemeGetElementClassName.php |
Adds dedicated tests for the public theme element class-name helper. |
Review effort: Balanced
| /** | ||
| * Test wp_theme_get_element_class_name(). | ||
| * | ||
| * @group theme |
lancewillett
left a comment
There was a problem hiding this comment.
What regression would these five rows catch that the existing tests miss? The helper forwards directly to WP_Theme_JSON::get_element_class_name(). Its button and unknown-element cases already run in tests/phpunit/tests/theme/wpThemeJson.php, and test_block_theme_button() checks the public output. Also, heading is registered but has no class mapping. I’d close this unless there’s a distinct caller or mapping that needs protection.
AI review · gpt-6
|
Thanks for the review, @mukeshpanchal27! Updated per your feedback:
Both single-site and multisite PHPUnit test suites pass cleanly with 0 PHPCS errors. AI assistance: Yes | Tool: Google Antigravity | Model: Gemini 3.8 Flash | Used for: Local test verification and annotation updates per review feedback. |
|
Correction to my earlier comment, sorry @rejaulalomkhan. Test-only changes now need their own Trac ticket per component, not #65819 (comment 1521). If this continues, please open a Themes ticket and point the I agree with @lancewillett, though. The function only forwards to |
|
Thanks for the follow-up and clarification, @mukeshpanchal27 and @lancewillett. That makes complete sense — since Closing this PR in favor of keeping the test suite lean. Thank you both for the review and guidance on ticket scopes! AI assistance: Yes | Tool: Google Antigravity | Model: Gemini 3.8 Flash | Used for: Drafting review response. |

Description
Adds dedicated unit tests for wp_theme_get_element_class_name() in src/wp-includes/theme.php. Introduced in [54174] (#56467) as a public alias for WP_Theme_JSON::get_element_class_name(), this standalone function currently lacks direct unit tests in Core.
Tests added in ests/phpunit/tests/theme/wpThemeGetElementClassName.php:
Testing Instructions
Run single-site and multisite test suites and coding standards:
�ash node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit tests/phpunit/tests/theme/wpThemeGetElementClassName.php node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit -c tests/phpunit/multisite.xml tests/phpunit/tests/theme/wpThemeGetElementClassName.php node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpcs tests/phpunit/tests/theme/wpThemeGetElementClassName.phpAll 5 tests and 5 assertions pass cleanly with 0 PHPCS errors.
Trac ticket: https://core.trac.wordpress.org/ticket/65819
This Pull Request is for code review only. Please keep all other discussion to the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
Use of AI Tools
AI assistance: Yes
Tool(s): Google Antigravity
Model(s): Gemini 3.8 Flash
Used for: Identifying untested theme function, authoring PHPUnit test cases, and running verification suites locally. I reviewed every line, ran the tests, and take responsibility for the change.