Skip to content

Tests: Cover is_page_template() - #15222

Closed
devmuhib009 wants to merge 2 commits into
WordPress:trunkfrom
devmuhib009:tests/65819-cover-is-page-template
Closed

devmuhib009 wants to merge 2 commits into
WordPress:trunkfrom
devmuhib009:tests/65819-cover-is-page-template

Conversation

@devmuhib009

Copy link
Copy Markdown
Member

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(): Verifies is_page_template() returns false when not on a singular request.
  • test_is_page_template_without_arguments(): Verifies is_page_template() without arguments checks whether any custom page template is assigned.
  • test_is_page_template_with_matching_string(): Verifies is_page_template() matches a specific template filename string.
  • test_is_page_template_with_default(): Verifies is_page_template() matches 'default' when no custom template is set and returns false when a custom template is assigned.
  • test_is_page_template_with_array(): Verifies is_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.php

Verification

  • PHPUnit: OK (5 tests, 14 assertions)
  • PHPCS: OK (1 file checked, 0 errors, 0 warnings)

Use of AI Tools

  • Tool: Google Antigravity
  • Model: Gemini 2.5 Pro
  • Assistance: Test scaffolding, assertion formulation, and verification execution.

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.
@github-actions

github-actions Bot commented Oct 30, 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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props devmuhib, huzaifaalmesbah, lancewillett.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@huzaifaalmesbah huzaifaalmesbah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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 lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The custom-template test lacks negative scalar assertions for 'default' and a different filename, leaving fallback regressions untested.

1 open issue
1 resolved since last review

Review effort: Balanced

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 lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

wporg-sync pushed a commit that referenced this pull request Nov 1, 2026
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
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 1, 2026
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
@lancewillett

Copy link
Copy Markdown
Member

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.

4 participants