-
Notifications
You must be signed in to change notification settings - Fork 384
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
Fix the order in which ensure_required_markup() is called #1041
Conversation
This is a regression introduced by me in 0154620 |
includes/class-amp-theme-support.php
Outdated
$scripts[] = $script; | ||
} | ||
foreach ( $scripts as $script ) { | ||
$head->appendChild( $script ); |
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.
The $head
is undefined. We should grab it with DOMXPath
and only do the script gathering if it is defined.
It would be good to add a new test case for the bug this is fixed so that it doesn't re-surface. For example another test like |
$original_html = trim( ob_get_clean() ); | ||
$removed_nodes = array(); | ||
$sanitized_html = AMP_Theme_Support::prepare_response( $original_html, array( | ||
'validation_error_callback' => function( $removed ) use ( &$removed_nodes ) { |
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.
I don't think we need validation_error_callback
here since $removed_nodes
is never checked. Alternative, you could $this->assertEmpty( $removed_nodes )
to verify that nothing got stripped out.
}, | ||
) ); | ||
|
||
$this->assertContains( '<meta charset="' . get_bloginfo( 'charset' ) . '">', $sanitized_html ); |
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.
Since AMP must be UTF-8, should this use not be a literal UTF-8?
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.
Agree; changed to $this->assertContains( '<meta charset="utf-8">', $sanitized_html );
* | ||
* @global WP_Widget_Factory $wp_widget_factory | ||
* @global WP_Scripts $wp_scripts | ||
* @covers AMP_Theme_Support::validate_non_amp_theme() |
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 is no such method as AMP_Theme_Support::validate_non_amp_theme()
. It should be AMP_Theme_Support:: prepare_response()
.
AMP_Theme_Support::init(); | ||
AMP_Theme_Support::finish_init(); | ||
$wp_widget_factory = new WP_Widget_Factory(); | ||
wp_widgets_init(); |
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.
Since no widgets are being tested in this response, I think the references to $wp_widget_factory
and wp_widgets_init()
in this PR can be removed.
0c6c205
to
6ce2206
Compare
6ce2206
to
d61de17
Compare
…ed (and fail) for unknown reason See xwp/wp-dev-lib#270
e7f90a7
to
6cef7e6
Compare
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.
@amedina thanks for fixing the viewport bug 👍I left my CR below.
* @covers AMP_Theme_Support::prepare_response() | ||
*/ | ||
public function test_validate_non_amp_theme() { | ||
global $wp_widget_factory, $wp_scripts; |
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.
$wp_widget_factory
doesn't seem to be used in this method and the $wp_scripts
are already reset in the tearDown()
method.
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.
Removed.
</html> | ||
<?php | ||
$original_html = trim( ob_get_clean() ); | ||
$removed_nodes = array(); |
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.
$removed_nodes
doesn't seem to be used in this method.
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.
Done.
includes/class-amp-theme-support.php
Outdated
|
||
if ( isset( $head ) ) { | ||
// Make sure scripts from the body get moved to the head. | ||
$scripts = array(); |
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.
Any reason to store the scripts in a var and run two loops rather than doing the following:
foreach ( $xpath->query( '//body//script[ @custom-element or @custom-template ]' ) as $script ) {
$head->appendChild( $script );
}
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.
Makes sense :)
@@ -220,7 +220,6 @@ public function test_prepare_response() { | |||
* @covers AMP_Theme_Support::prepare_response() | |||
*/ | |||
public function test_validate_non_amp_theme() { | |||
global $wp_widget_factory, $wp_scripts; | |||
$wp_scripts = null; |
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.
This line still needs to be removed and this PR will be good to go. Thanks @amedina, great stuff!
e4c7388
to
38edc74
Compare
The order in which
ensure_required_markup
was being called was causing the viewport meta tag to be stripped out by the sanitizer.