Skip to content

Commit

Permalink
Merge pull request #7124 from ampproject/enhancement/publisher-logo
Browse files Browse the repository at this point in the history
Add Site Health test to warn sites when fallback publisher logo.
  • Loading branch information
westonruter authored Jun 13, 2022
2 parents 2fe6367 + 8b24389 commit 2f3ada6
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/Admin/SiteHealth.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ public function add_tests( $tests ) {
'test' => [ $this, 'xdebug_extension' ],
];

$tests['direct']['amp_publisher_logo'] = [
'label' => esc_html__( 'Publisher Logo', 'amp' ),
'test' => [ $this, 'publisher_logo' ],
];

if ( $this->supports_async_rest_tests( $tests ) ) {
$tests['async'][ self::TEST_PAGE_CACHING ] = [
'label' => esc_html__( 'Page caching', 'amp' ),
Expand Down Expand Up @@ -1276,4 +1281,48 @@ private function is_intl_extension_needed() {

return false;
}

/**
* Gets the test result data for whether publisher logo is set or not.
*
* @return array
*/
public function publisher_logo() {
$description = esc_html__( 'The publisher logo used in Schema.org metadata. The site icon is used as the publisher logo when it is specified.', 'amp' );

if ( amp_get_asset_url( 'images/amp-page-fallback-wordpress-publisher-logo.png' ) !== amp_get_publisher_logo() ) {
$status = 'good';
$color = 'green';
$label = __( 'Publisher logo is defined', 'amp' );
} else {
$status = 'recommended';
$color = 'orange';
$label = __( 'Publisher logo is not defined', 'amp' );
$description .= ' ' . esc_html__( 'Currently, the fallback WordPress logo is used.', 'amp' );
}

if ( ! has_filter( 'amp_site_icon_url' ) && current_user_can( 'customize' ) ) {
$actions = wp_kses_post(
sprintf(
'<p><a class="button button-secondary" href="%s">%s</a></p>',
admin_url( 'customize.php?autofocus[control]=site_icon' ),
esc_html__( 'Update site icon', 'amp' )
)
);
} else {
$actions = '';
}

return array_merge(
compact( 'status', 'label', 'description' ),
[
'badge' => [
'label' => $this->get_badge_label(),
'color' => $color,
],
'actions' => wp_kses_post( $actions ),
'test' => 'amp_publisher_logo',
]
);
}
}
20 changes: 20 additions & 0 deletions tests/php/src/Admin/SiteHealthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public function test_add_tests() {
$tests = $this->instance->add_tests( [] );
$this->assertArrayHasKey( 'amp_icu_version', $tests['direct'] );
$this->assertArrayHasKey( 'amp_slug_definition_timing', $tests['direct'] );
$this->assertArrayHasKey( 'amp_publisher_logo', $tests['direct'] );

remove_filter( 'site_url', [ self::class, 'get_idn' ] );
remove_filter( 'amp_query_var', [ self::class, 'get_lite_query_var' ] );
Expand Down Expand Up @@ -1179,4 +1180,23 @@ public function assertAssocArraySubset( $expected, $actual ) {
wp_array_slice_assoc( $actual, array_keys( $expected ) )
);
}

/**
* @covers ::publisher_logo()
*/
public function test_publisher_logo() {

$output = $this->instance->publisher_logo();
$this->assertEquals( 'recommended', $output['status'] );

add_filter(
'amp_site_icon_url',
static function () {
return 'publisher-logo.png';
}
);

$output = $this->instance->publisher_logo();
$this->assertEquals( 'good', $output['status'] );
}
}

0 comments on commit 2f3ada6

Please sign in to comment.