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

Suppress Site Health ICU test if site or home URL is not an IDN #4698

Merged
merged 5 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
39 changes: 33 additions & 6 deletions src/Admin/SiteHealth.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,42 @@ public function add_tests( $tests ) {
'label' => esc_html__( 'cURL multi functions', 'amp' ),
'test' => [ $this, 'curl_multi_functions' ],
];
$tests['direct']['amp_icu_version'] = [
'label' => esc_html__( 'ICU version', 'amp' ),
'test' => [ $this, 'icu_version' ],
];
$tests['direct']['amp_css_transient_caching'] = [

if ( function_exists( 'idn_to_utf8' ) ) {
pierlon marked this conversation as resolved.
Show resolved Hide resolved
$has_idn = false;

// Publisher’s own origins.
pierlon marked this conversation as resolved.
Show resolved Hide resolved
$domains = array_unique(
[
wp_parse_url( site_url(), PHP_URL_HOST ),
wp_parse_url( home_url(), PHP_URL_HOST ),
]
);

foreach ( $domains as $domain ) {
// The third parameter is set explicitly to prevent issues with newer PHP versions compiled with an old ICU version.
// phpcs:ignore PHPCompatibility.Constants.RemovedConstants.intl_idna_variant_2003Deprecated
$unicode_domain = idn_to_utf8( $domain, IDNA_DEFAULT, defined( 'INTL_IDNA_VARIANT_UTS46' ) ? INTL_IDNA_VARIANT_UTS46 : INTL_IDNA_VARIANT_2003 );

if ( $unicode_domain && $domain !== $unicode_domain ) {
$has_idn = true;
break;
}
}

if ( $has_idn ) {
$tests['direct']['amp_icu_version'] = [
'label' => esc_html__( 'ICU version', 'amp' ),
'test' => [ $this, 'icu_version' ],
];
}
}

$tests['direct']['amp_css_transient_caching'] = [
'label' => esc_html__( 'Transient caching of stylesheets', 'amp' ),
'test' => [ $this, 'css_transient_caching' ],
];
$tests['direct']['amp_xdebug_extension'] = [
$tests['direct']['amp_xdebug_extension'] = [
'label' => esc_html__( 'Xdebug extension', 'amp' ),
'test' => [ $this, 'xdebug_extension' ],
];
Expand Down
15 changes: 14 additions & 1 deletion tests/php/test-class-site-health.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,21 @@ public function test_add_tests() {
$this->assertArrayHasKey( 'direct', $tests );
$this->assertArrayHasKey( 'amp_persistent_object_cache', $tests['direct'] );
$this->assertArrayHasKey( 'amp_curl_multi_functions', $tests['direct'] );
$this->assertArrayHasKey( 'amp_icu_version', $tests['direct'] );
$this->assertArrayNotHasKey( 'amp_icu_version', $tests['direct'] );
$this->assertArrayHasKey( 'amp_xdebug_extension', $tests['direct'] );


// Test that the the ICU version test is added only when site URL is an IDN.
add_filter( 'site_url', [ self::class, 'get_idn' ], 10, 4 );

$tests = $this->instance->add_tests( [] );
$this->assertArrayHasKey( 'amp_icu_version', $tests['direct'] );

remove_filter( 'site_url', [ self::class, 'get_idn' ] );
}

public static function get_idn() {
pierlon marked this conversation as resolved.
Show resolved Hide resolved
return 'https://xn--e28h.com';
}

/**
Expand Down