Skip to content
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 deprecated _admin_bar_bump_cb; Fix failing PHP unit tests #7635

Merged
merged 17 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/build-test-measure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,20 @@ jobs:
run: |
echo "WP_ENVIRONMENT_TYPE=local" >> $GITHUB_ENV

- name: Override default PHPUnit configuration
if: ${{ matrix.experimental == true && needs.pre-run.outputs.changed-php-count > 0 }}
run: |
cp phpunit.xml.dist phpunit.xml

# Avoid converting deprecations, errors, notices, and warnings to exceptions in experimental mode.
sed -i 's/convertDeprecationsToExceptions="true"/convertDeprecationsToExceptions="false"/g' phpunit.xml
sed -i 's/convertErrorsToExceptions="true"/convertErrorsToExceptions="false"/g' phpunit.xml
sed -i 's/convertNoticesToExceptions="true"/convertNoticesToExceptions="false"/g' phpunit.xml
sed -i 's/convertWarningsToExceptions="true"/convertWarningsToExceptions="false"/g' phpunit.xml
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/amp
Copy link
Member

Choose a reason for hiding this comment

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

😎

env:
WP_TESTS_DIR: /tmp/wordpress-tests-lib
westonruter marked this conversation as resolved.
Show resolved Hide resolved

- name: Run tests
if: ${{ matrix.coverage == false && needs.pre-run.outputs.changed-php-count > 0 }}
run: |
Expand Down
43 changes: 37 additions & 6 deletions includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@
*/
const READER_MODE_TEMPLATE_DIRECTORY = 'amp';

/**
* `wp-emoji-styles` styles handle.
*
* @var string
*/
const WP_EMOJI_STYLES = 'wp-emoji-styles';

thelovekesh marked this conversation as resolved.
Show resolved Hide resolved
/**
* Sanitizers, with keys as class names and values as arguments.
*
Expand Down Expand Up @@ -848,7 +855,13 @@
// Prevent emoji detection and emoji loading since platforms/browsers now support emoji natively (and Twemoji is not AMP-compatible).
add_filter( 'wp_resource_hints', [ __CLASS__, 'filter_resource_hints_to_remove_emoji_dns_prefetch' ], 10, 2 );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );

if ( function_exists( 'wp_enqueue_emoji_styles' ) ) {
// By default, emoji styles are enqueued at priority 10.
add_action( 'wp_print_styles', [ __CLASS__, 'dequeue_emoji_styles' ], 11 );

Check warning on line 861 in includes/class-amp-theme-support.php

View check run for this annotation

Codecov / codecov/patch

includes/class-amp-theme-support.php#L861

Added line #L861 was not covered by tests
} else {
remove_action( 'wp_print_styles', 'print_emoji_styles' );
}
westonruter marked this conversation as resolved.
Show resolved Hide resolved

// The AMP version of the skip link is implemented by AMP_Accessibility_Sanitizer::add_skip_link().
remove_action( 'wp_footer', 'gutenberg_the_skip_link' );
Expand Down Expand Up @@ -907,6 +920,15 @@
);
}

/**
* Dequeue emoji styles.
*
* @since 2.4.3
*/
public static function dequeue_emoji_styles() {
wp_dequeue_style( self::WP_EMOJI_STYLES );
}

Check warning on line 930 in includes/class-amp-theme-support.php

View check run for this annotation

Codecov / codecov/patch

includes/class-amp-theme-support.php#L928-L930

Added lines #L928 - L930 were not covered by tests

thelovekesh marked this conversation as resolved.
Show resolved Hide resolved
/**
* Filter resource hints to remove the emoji CDN (s.w.org).
*
Expand Down Expand Up @@ -1225,12 +1247,21 @@
} else {
$header_callback = '_admin_bar_bump_cb';
}
remove_action( 'wp_head', $header_callback );

// @see <https://core.trac.wordpress.org/ticket/58775>.
if ( ! function_exists( 'wp_enqueue_admin_bar_header_styles' ) ) {
remove_action( 'wp_head', $header_callback );
}

if ( '__return_false' !== $header_callback ) {
ob_start();
$header_callback();
$style = ob_get_clean();
$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $style ) ); // See wp_add_inline_style().
if ( ! function_exists( 'wp_enqueue_admin_bar_header_styles' ) ) {
ob_start();
$header_callback();
$style = ob_get_clean();
$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $style ) ); // See wp_add_inline_style().
} else {
$data = '';

Check warning on line 1263 in includes/class-amp-theme-support.php

View check run for this annotation

Codecov / codecov/patch

includes/class-amp-theme-support.php#L1263

Added line #L1263 was not covered by tests
}

// Override AMP's position:relative on the body for the sake of the AMP viewer, which is not relevant an an Admin Bar context.
if ( amp_is_dev_mode() ) {
Expand Down
5 changes: 4 additions & 1 deletion src/Support/SupportData.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@
$loopback_status = ( ! empty( $loopback_status->status ) ) ? $loopback_status->status : '';
}

if ( function_exists( 'wp_is_https_supported' ) ) {
if ( function_exists( 'wp_get_https_detection_errors' ) ) {
$https_errors = wp_get_https_detection_errors();
$is_ssl = empty( $https_errors );

Check warning on line 256 in src/Support/SupportData.php

View check run for this annotation

Codecov / codecov/patch

src/Support/SupportData.php#L255-L256

Added lines #L255 - L256 were not covered by tests
} elseif ( function_exists( 'wp_is_https_supported' ) ) {
$is_ssl = wp_is_https_supported();
} else {
$is_ssl = is_ssl();
Expand Down
27 changes: 16 additions & 11 deletions tests/php/src/DevTools/LikelyCulpritDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ public function single_step_trace_data() {
],

'parent theme' => [
[ get_template_directory() . '/functions.php' ],
[ '{{ get_template_directory }}/functions.php' ],
'theme',
'default',
],

'child theme' => [
[ get_stylesheet_directory() . '/functions.php' ],
[ '{{ get_stylesheet_directory }}/functions.php' ],
'theme',
'default',
],
Expand Down Expand Up @@ -167,8 +167,8 @@ public function multi_step_trace_data() {
__FILE__, // AMP plugin is skipped.
WP_PLUGIN_DIR . '/bad-plugin/bad-plugin.php', // <== Likely culprit.
WP_CONTENT_DIR . '/mu-plugins/bad-mu-plugin.php',
get_template_directory() . '/functions.php',
get_stylesheet_directory() . '/functions.php',
'{{ get_template_directory }}/functions.php',
'{{ get_stylesheet_directory }}/functions.php',
],
'plugin',
'bad-plugin',
Expand All @@ -180,8 +180,8 @@ public function multi_step_trace_data() {
__FILE__, // AMP plugin is skipped.
WP_CONTENT_DIR . '/mu-plugins/bad-mu-plugin.php', // <== Likely culprit.
WP_PLUGIN_DIR . '/bad-plugin/bad-plugin.php',
get_template_directory() . '/functions.php',
get_stylesheet_directory() . '/functions.php',
'{{ get_template_directory }}/functions.php',
'{{ get_stylesheet_directory }}/functions.php',
],
'mu-plugin',
'bad-mu-plugin.php',
Expand All @@ -191,10 +191,10 @@ public function multi_step_trace_data() {
[
ABSPATH . '/wp-includes/some-file.php', // Core is skipped.
__FILE__, // AMP plugin is skipped.
get_template_directory() . '/functions.php', // <== Likely culprit.
'{{ get_template_directory }}/functions.php', // <== Likely culprit.
WP_PLUGIN_DIR . '/bad-plugin/bad-plugin.php',
WP_CONTENT_DIR . '/mu-plugins/bad-mu-plugin.php',
get_stylesheet_directory() . '/functions.php',
'{{ get_stylesheet_directory }}/functions.php',
],
'theme',
'default',
Expand All @@ -204,10 +204,10 @@ public function multi_step_trace_data() {
[
ABSPATH . '/wp-includes/some-file.php', // Core is skipped.
__FILE__, // AMP plugin is skipped.
get_stylesheet_directory() . '/functions.php', // <== Likely culprit.
'{{ get_stylesheet_directory }}/functions.php', // <== Likely culprit.
WP_PLUGIN_DIR . '/bad-plugin/bad-plugin.php',
WP_CONTENT_DIR . '/mu-plugins/bad-mu-plugin.php',
get_template_directory() . '/functions.php',
'{{ get_template_directory }}/functions.php',
],
'theme',
'default',
Expand Down Expand Up @@ -275,7 +275,12 @@ public function test_analyze_trace( $file_stack, $expected_type, $expected_name
private function get_trace_from_file_stack( $file_stack ) {
return array_map(
static function ( $file ) {
return [ 'file' => $file ];
$file = str_replace( '{{ get_template_directory }}', get_template_directory(), $file );
$file = str_replace( '{{ get_stylesheet_directory }}', get_stylesheet_directory(), $file );

return [
'file' => $file,
];
Comment on lines -278 to +283
Copy link
Member

Choose a reason for hiding this comment

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

😎

},
$file_stack
);
Expand Down
Loading
Loading