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 all 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
21 changes: 12 additions & 9 deletions .github/workflows/build-test-measure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ jobs:
needs: pre-run
env:
WP_CORE_DIR: /tmp/wordpress
WP_TESTS_DIR: /tmp/wordpress-tests-lib
WP_ENVIRONMENT_TYPE: local
services:
mysql:
image: mariadb:latest
Expand Down Expand Up @@ -544,18 +546,24 @@ jobs:
if: needs.pre-run.outputs.changed-php-count > 0
run: cp -r "$PWD" "$WP_CORE_DIR/src/wp-content/plugins/amp"

- name: Setup required WP constants
- name: Override default PHPUnit configuration
if: ${{ matrix.experimental == true && needs.pre-run.outputs.changed-php-count > 0 }}
run: |
echo "WP_ENVIRONMENT_TYPE=local" >> $GITHUB_ENV
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

- name: Run tests
if: ${{ matrix.coverage == false && needs.pre-run.outputs.changed-php-count > 0 }}
run: |
phpunit --version
phpunit --verbose
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/amp
env:
WP_TESTS_DIR: /tmp/wordpress-tests-lib

- name: Run multisite tests
if: ${{ matrix.multisite == true && needs.pre-run.outputs.changed-php-count > 0 }}
Expand All @@ -564,7 +572,6 @@ jobs:
phpunit --verbose
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/amp
env:
WP_TESTS_DIR: /tmp/wordpress-tests-lib
WP_MULTISITE: 1

- name: Run tests with coverage
Expand All @@ -573,17 +580,13 @@ jobs:
phpunit --version
phpunit --verbose --coverage-clover ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/amp/build/logs/clover.xml
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/amp
env:
WP_TESTS_DIR: /tmp/wordpress-tests-lib

- name: Run external HTTP tests
if: ${{ matrix.external-http == true && needs.pre-run.outputs.changed-php-count > 0 }}
run: |
phpunit --version
phpunit --testsuite external-http --verbose
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/amp
env:
WP_TESTS_DIR: /tmp/wordpress-tests-lib

- name: Upload code coverage report
if: ${{ matrix.coverage == true && needs.pre-run.outputs.changed-php-count > 0 && github.actor != 'dependabot[bot]' }}
Expand Down
19 changes: 14 additions & 5 deletions includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -1225,12 +1225,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 1241 in includes/class-amp-theme-support.php

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1241 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