Repository navigation
Tests: Cover get_the_generator() type inference from the current filter - #16232
shail-mehta wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the test-only change adding regression coverage for filter-based generator type inference.
No open issues 🎉
What changed in this PR
Adds regression coverage for get_the_generator() inferring its output type from the current filter when no type is supplied, addressing Trac #66757. No production code changes.
Changes:
- Covers all eight recognized filter names through a data provider.
- Checks expected markup using the current WordPress version.
- Restores
$wp_current_filterafter each case, including assertion failures.
| File | Description |
|---|---|
tests/phpunit/tests/general/getTheGenerator.php |
Adds data-driven tests for filter-based generator type inference. |
Review effort: Balanced
|
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:
|
| global $wp_current_filter; | ||
|
|
||
| $original_filter = $wp_current_filter; | ||
| $wp_current_filter = array( $filter ); | ||
|
|
||
| try { | ||
| $version = ( 'atom' === $type || 'rss2' === $type || 'rdf' === $type ) | ||
| ? get_bloginfo_rss( 'version' ) | ||
| : get_bloginfo( 'version' ); | ||
|
|
||
| $this->assertSame( sprintf( $expected, $version ), get_the_generator() ); | ||
| } finally { | ||
| $wp_current_filter = $original_filter; | ||
| } |
There was a problem hiding this comment.
The base test case backs up and restores $wp_current_filter around each test (see backup_hooks() and restore_hooks() in abstract-testcase.php), so the manual restore and try/finally aren't needed:
| global $wp_current_filter; | |
| $original_filter = $wp_current_filter; | |
| $wp_current_filter = array( $filter ); | |
| try { | |
| $version = ( 'atom' === $type || 'rss2' === $type || 'rdf' === $type ) | |
| ? get_bloginfo_rss( 'version' ) | |
| : get_bloginfo( 'version' ); | |
| $this->assertSame( sprintf( $expected, $version ), get_the_generator() ); | |
| } finally { | |
| $wp_current_filter = $original_filter; | |
| } | |
| global $wp_current_filter; | |
| $wp_current_filter = array( $filter ); | |
| $version = ( 'atom' === $type || 'rss2' === $type || 'rdf' === $type ) | |
| ? get_bloginfo_rss( 'version' ) | |
| : get_bloginfo( 'version' ); | |
| $this->assertSame( sprintf( $expected, $version ), get_the_generator() ); |
lancewillett
left a comment
There was a problem hiding this comment.
Please keep the hook-to-type mapping and reuse the existing coverage for the markup. The provider can hold just the hook and expected type, then compare the inferred result with the explicit result for that type. The existing test independently checks the explicit markup. Removing just the commentsrss2_head mapping broke its new row locally. Mukesh is also right that the base test restores $wp_current_filter.
Before landing, please link a ticket in the component that owns the code under test, per the 7.3 ticket guidance. Related coverage can share a component ticket.
AI review · gpt-6.2-astra
|
Thanks for the reviews! I've simplified the data provider to hold just the hook and expected type, compared |
lancewillett
left a comment
There was a problem hiding this comment.
The provider now tests the mapping without rebuilding the markup. Removing the rss2_head mapping failed that row. The base test case restores the hook stack. The revised class passed on both single-site and multisite.
AI review · gpt-6.2-astra
Trac ticket: #66832
What
When
$typeis empty,get_the_generator()infers the generator type fromcurrent_filter()(rss2_head→rss2,atom_head→atom, and so on).Why
Existing tests cover an empty type with no active filter (returns
null) and explicit types. They do not cover filter-based inference. Removing theswitch ( $current_filter )mapping left those tests green.How
Adds
test_get_the_generator_infers_type_from_current_filter()with a data provider mapping all eight hooks to their expected type:rss2_headrss2commentsrss2_headrss2rss_headcommentopml_headcommentrdf_headerrdfatom_headatomcomments_atom_headatomapp_headatomEach case compares
get_the_generator()againstget_the_generator( $type ), reusing the existing explicit-type markup coverage.WP_UnitTestCaserestores$wp_current_filterautomatically between tests.Use of AI Tools