Repository navigation
Tests: Cover is_page_template() - #15222
devmuhib009 wants to merge 2 commits into
Conversation
Add unit tests for is_page_template(): - Verify is_page_template() returns false when not on a singular request. - Verify is_page_template() without arguments checks whether any custom page template is assigned. - Verify is_page_template() matches a specific template filename string. - Verify is_page_template() matches 'default' when no custom template is set. - Verify is_page_template() matches against an array of template filenames. See #65819. Props devmuhib009.
|
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:
|
huzaifaalmesbah
left a comment
There was a problem hiding this comment.
LGTM! Excellent test suite for is_page_template(). Tests non-singular requests, default template handling, custom template string matches, and array matches with clean wpSetUpBeforeClass fixture hygiene. All checks pass.
AI Review: Gemini 3.8 Flash
There was a problem hiding this comment.
🟡 Changes recommended
The tests miss an array containing 'default' checked against a custom-template page, leaving a potential matching regression undetected.
1 open issue
What changed in this PR
Adds dedicated PHPUnit coverage for is_page_template() under Trac #65819, without changing production behavior.
Changes:
- Creates fixtures for pages using custom and default templates.
- Adds five tests covering non-singular requests, calls without arguments, string matching, and array matching.
| File | Description |
|---|---|
tests/phpunit/tests/post/isPageTemplate.php |
Adds fixtures and dedicated tests for page-template detection. |
Review effort: Balanced
lancewillett
left a comment
There was a problem hiding this comment.
Please extend the existing page-template conditional tests instead of adding a second class. They already cover string/default/array matches, other post types, and a stronger non-singular regression involving colliding IDs. Retain only distinct missing coverage, such as the no-argument result. Copilot’s additional default-array case can be considered in that existing class; it does not justify repeating the surrounding matrix.
AI review · gpt-6
…19. Props devmuhib009.
| update_post_meta( $post_id, '_wp_page_template', 'example.php' ); | ||
| $this->go_to( "/?page_id=$post_id" ); | ||
| $this->assertTrue( is_page_template( 'example.php' ) ); | ||
| $this->assertTrue( is_page_template() ); |
lancewillett
left a comment
There was a problem hiding this comment.
The revised patch addresses the earlier review requests.
Validated with the related coverage patches on current trunk: 156 tests / 741 assertions in each of single-site and multisite, randomized seed 1101. No failures, errors, warnings, or skips.
Current-head CI and Copilot review checked.
AI review · gpt-6
Extend existing `is_page_template()` assertions for default and custom templates. Cover the global-post fallback and failure results in `has_term()`. Developed in: #15222, #15228 Props devmuhib, huzaifaalmesbah. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@65169 602fd350-edb4-49c9-b593-d223f7449a82
Extend existing `is_page_template()` assertions for default and custom templates. Cover the global-post fallback and failure results in `has_term()`. Developed in: WordPress/wordpress-develop#15222, WordPress/wordpress-develop#15228 Props devmuhib, huzaifaalmesbah. See #65819. Built from https://develop.svn.wordpress.org/trunk@65169 git-svn-id: http://core.svn.wordpress.org/trunk@64318 1a063a9b-81f0-0310-95a4-ce76da25c4cd
|
PR #15222 landed in https://core.trac.wordpress.org/changeset/65169 |

Description
Under Trac ticket #65819, this PR introduces dedicated unit test coverage for
is_page_template().Tests Added
test_is_page_template_returns_false_when_not_singular(): Verifiesis_page_template()returnsfalsewhen not on a singular request.test_is_page_template_without_arguments(): Verifiesis_page_template()without arguments checks whether any custom page template is assigned.test_is_page_template_with_matching_string(): Verifiesis_page_template()matches a specific template filename string.test_is_page_template_with_default(): Verifiesis_page_template()matches'default'when no custom template is set and returnsfalsewhen a custom template is assigned.test_is_page_template_with_array(): Verifiesis_page_template()matches against an array of template filenames.Testing Instructions
Run PHPUnit and PHPCS:
vendor/bin/phpunit --filter "Tests_Post_IsPageTemplate" vendor/bin/phpcs tests/phpunit/tests/post/isPageTemplate.phpVerification
Use of AI Tools