mirror of
https://gh.wpcy.net/https://github.com/wp-cli/profile-command.git
synced 2026-04-17 14:32:21 +08:00
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com>
202 lines
6.3 KiB
Gherkin
202 lines
6.3 KiB
Gherkin
Feature: Profile the template render stage
|
|
|
|
@require-wp-4.0
|
|
Scenario: Profiler loads a summary table
|
|
Given a WP install
|
|
|
|
When I run `wp profile stage --fields=stage`
|
|
Then STDOUT should be a table containing rows:
|
|
| stage |
|
|
| bootstrap |
|
|
| main_query |
|
|
| template |
|
|
|
|
@require-wp-4.0
|
|
Scenario: Profiler loads a table with the correct hooks
|
|
Given a WP install
|
|
|
|
When I run `wp profile stage bootstrap --fields=hook`
|
|
Then STDOUT should be a table containing rows:
|
|
| hook |
|
|
| muplugins_loaded:before |
|
|
| muplugins_loaded |
|
|
| plugins_loaded:before |
|
|
| plugins_loaded |
|
|
| setup_theme:before |
|
|
| setup_theme |
|
|
| after_setup_theme:before |
|
|
| after_setup_theme |
|
|
| init:before |
|
|
| init |
|
|
| wp_loaded:before |
|
|
| wp_loaded |
|
|
| wp_loaded:after |
|
|
|
|
When I run `wp profile stage main_query --fields=hook`
|
|
Then STDOUT should be a table containing rows:
|
|
| hook |
|
|
| parse_request:before |
|
|
| parse_request |
|
|
| send_headers:before |
|
|
| send_headers |
|
|
| pre_get_posts:before |
|
|
| pre_get_posts |
|
|
| the_posts:before |
|
|
| the_posts |
|
|
| wp:before |
|
|
| wp |
|
|
| wp:after |
|
|
|
|
When I run `wp profile stage template --fields=hook`
|
|
Then STDOUT should be a table containing rows:
|
|
| hook |
|
|
| template_redirect:before |
|
|
| template_redirect |
|
|
| template_include:before |
|
|
| template_include |
|
|
| wp_head:before |
|
|
| wp_head |
|
|
| loop_start:before |
|
|
| loop_start |
|
|
| loop_end:before |
|
|
| loop_end |
|
|
| wp_footer:before |
|
|
| wp_footer |
|
|
| wp_footer:after |
|
|
|
|
When I run `wp profile stage template --fields=hook --orderby=hook --order=DESC`
|
|
Then STDOUT should be a table containing rows:
|
|
| hook |
|
|
| wp_head:before |
|
|
| wp_head |
|
|
| wp_footer:before |
|
|
| wp_footer:after |
|
|
| wp_footer |
|
|
| template_redirect:before |
|
|
| template_redirect |
|
|
| template_include:before |
|
|
| template_include |
|
|
| loop_start:before |
|
|
| loop_start |
|
|
| loop_end:before |
|
|
| loop_end |
|
|
|
|
@require-wp-4.0
|
|
Scenario: Use --all flag to profile all stages
|
|
Given a WP install
|
|
|
|
When I run `wp profile stage --all --fields=hook`
|
|
Then STDOUT should be a table containing rows:
|
|
| hook |
|
|
| muplugins_loaded:before |
|
|
| muplugins_loaded |
|
|
| plugins_loaded:before |
|
|
| plugins_loaded |
|
|
| setup_theme:before |
|
|
| setup_theme |
|
|
| after_setup_theme:before |
|
|
| after_setup_theme |
|
|
| init:before |
|
|
| init |
|
|
| wp_loaded:before |
|
|
| wp_loaded |
|
|
| parse_request:before |
|
|
| parse_request |
|
|
| send_headers:before |
|
|
| send_headers |
|
|
| pre_get_posts:before |
|
|
| pre_get_posts |
|
|
| the_posts:before |
|
|
| the_posts |
|
|
| wp:before |
|
|
| wp |
|
|
| template_redirect:before |
|
|
| template_redirect |
|
|
| template_include:before |
|
|
| template_include |
|
|
| wp_head:before |
|
|
| wp_head |
|
|
| loop_start:before |
|
|
| loop_start |
|
|
| loop_end:before |
|
|
| loop_end |
|
|
| wp_footer:before |
|
|
| wp_footer |
|
|
| wp_footer:after |
|
|
| total (35) |
|
|
|
|
Scenario: Invalid stage specified
|
|
Given a WP install
|
|
|
|
When I try `wp profile stage foo_bar`
|
|
Then STDERR should be:
|
|
"""
|
|
Error: Invalid stage. Must be one of bootstrap, main_query, template, or use --all.
|
|
"""
|
|
|
|
@require-wp-4.0
|
|
Scenario: Invalid field name supplied to --fields
|
|
Given a WP install
|
|
|
|
When I try `wp profile stage template --fields=test`
|
|
Then STDERR should contain:
|
|
"""
|
|
Invalid field(s): test
|
|
"""
|
|
And the return code should be 1
|
|
|
|
@require-wp-4.0
|
|
Scenario: Identify callback_count for each hook
|
|
Given a WP install
|
|
|
|
When I run `wp profile stage bootstrap --fields=hook,callback_count`
|
|
Then STDOUT should be a table containing rows:
|
|
| hook | callback_count |
|
|
| muplugins_loaded | 2 |
|
|
|
|
@require-wp-4.0
|
|
Scenario: Use spotlight mode to filter out the zero-ish values
|
|
Given a WP install
|
|
|
|
When I run `wp profile stage bootstrap --fields=hook`
|
|
Then STDOUT should be a table containing rows:
|
|
| hook |
|
|
| init |
|
|
| wp_loaded:before |
|
|
| wp_loaded |
|
|
| wp_loaded:after |
|
|
|
|
When I run `wp profile stage bootstrap --fields=hook --spotlight`
|
|
Then STDOUT should be a table containing rows:
|
|
| hook |
|
|
| init |
|
|
| wp_loaded:after |
|
|
|
|
@require-wp-4.0
|
|
Scenario: Admin URL runs as a backend request and skips frontend stages
|
|
Given a WP install
|
|
|
|
When I run `wp profile stage --url=example.com/wp-admin/ --context=admin --fields=stage`
|
|
Then STDOUT should be a table containing rows:
|
|
| stage |
|
|
| bootstrap |
|
|
And STDOUT should not contain:
|
|
"""
|
|
main_query
|
|
"""
|
|
And STDOUT should not contain:
|
|
"""
|
|
template
|
|
"""
|
|
And STDERR should be empty
|
|
|
|
@require-wp-4.0
|
|
Scenario: Admin URL without --context=admin emits an error
|
|
Given a WP install
|
|
|
|
When I try `wp profile stage --url=example.com/wp-admin/ --fields=stage`
|
|
Then STDERR should contain:
|
|
"""
|
|
Profiling an admin URL requires --context=admin.
|
|
"""
|
|
And the return code should be 1
|