-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve test coverage for Optimization Detective #1817
Changes from 8 commits
37e075f
d7ac348
921c2d3
89c6e76
62da920
91c1d65
af9182b
be2086d
275d102
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ | |
} | ||
// @codeCoverageIgnoreEnd | ||
|
||
// The addition of the following hooks is tested in Test_OD_Hooks::test_hooks_added() and Test_OD_Storage_Post_Type::test_add_hooks(). | ||
|
||
// @codeCoverageIgnoreStart | ||
add_action( 'init', 'od_initialize_extensions', PHP_INT_MAX ); | ||
Comment on lines
+15
to
18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too bad, I guess there is no way to manually indicate that this is covered by the tests for the hooks added? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the only way may be to have a test that removes all filters/actions, and then does a Note that the coverage of |
||
add_filter( 'template_include', 'od_buffer_output', PHP_INT_MAX ); | ||
OD_URL_Metrics_Post_Type::add_hooks(); | ||
|
@@ -20,3 +23,4 @@ | |
add_filter( 'site_status_tests', 'od_add_rest_api_availability_test' ); | ||
add_action( 'admin_init', 'od_maybe_run_rest_api_health_check' ); | ||
add_action( 'after_plugin_row_meta', 'od_render_rest_api_health_check_admin_notice_in_plugin_row', 30 ); | ||
// @codeCoverageIgnoreEnd |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>...</title> | ||
</head> | ||
<body> | ||
<div id="page"> | ||
<img src="https://example.com/image.jpg" alt="" width="100" height="100"> | ||
</div> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
return static function (): void { | ||
|
||
add_action( | ||
'od_register_tag_visitors', | ||
static function ( OD_Tag_Visitor_Registry $registry ): void { | ||
$registry->register( | ||
'img-preload', | ||
static function ( OD_Tag_Visitor_Context $context ): bool { | ||
if ( 'IMG' === $context->processor->get_tag() ) { | ||
$context->link_collection->add_link( | ||
array( | ||
'rel' => 'preload', | ||
'as' => 'image', | ||
'href' => $context->processor->get_attribute( 'src' ), | ||
) | ||
); | ||
} | ||
return false; | ||
} | ||
); | ||
} | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale for this change? How was the previous implementation problematic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was no code coverage for the
return
in:In practice, the
$schema
should always have atype
specified given it is enforced by\OD_URL_Metric::extend_schema_with_optional_properties()
. At the entrypoint where this method is called in\OD_Strict_URL_Metric::get_json_schema()
it is absolutely defined, which the new typing makes clear. But there is less certainty about the nested properties, so this just moves theisset(...['type'])
check down below, which has the same effect but also improves coverage.