Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-wp-site-icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function additional_sizes( $sizes = array() ) {
foreach ( $this->site_icon_sizes as $size ) {
if ( $size < $this->min_size ) {
$only_crop_sizes[ 'site_icon-' . $size ] = array(
'width ' => $size,
'width' => $size,
'height' => $size,
'crop' => true,
);
Expand Down
41 changes: 39 additions & 2 deletions tests/phpunit/tests/image/siteIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function test_additional_sizes() {
$sizes = array();
foreach ( $this->wp_site_icon->site_icon_sizes as $size ) {
$sizes[ 'site_icon-' . $size ] = array(
'width ' => $size,
'width' => $size,
'height' => $size,
'crop' => true,
);
Expand All @@ -82,7 +82,7 @@ public function test_additional_sizes_with_filter() {
$sizes = array();
foreach ( $this->wp_site_icon->site_icon_sizes as $size ) {
$sizes[ 'site_icon-' . $size ] = array(
'width ' => $size,
'width' => $size,
'height' => $size,
'crop' => true,
);
Expand All @@ -98,6 +98,43 @@ public function test_additional_sizes_with_filter() {
unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes, true ) ] );
}

/**
* Tests that the registered sub-sizes are generated as square crops.
*
* @ticket 65345
*
* @covers WP_Site_Icon::additional_sizes
*/
public function test_additional_sizes_generate_square_subsizes() {
// A non-square source, large enough for every site icon size.
$filename = DIR_TESTDATA . '/images/waffles.jpg';
$upload = wp_upload_bits( wp_basename( $filename ), null, file_get_contents( $filename ) );

$attachment_id = $this->_make_attachment( $upload );
$file = get_attached_file( $attachment_id );

$editor = wp_get_image_editor( $file );

if ( is_wp_error( $editor ) ) {
$this->markTestSkipped( $editor->get_error_message() );
}

add_filter( 'intermediate_image_sizes_advanced', array( $this->wp_site_icon, 'additional_sizes' ) );
$metadata = wp_generate_attachment_metadata( $attachment_id, $file );
remove_filter( 'intermediate_image_sizes_advanced', array( $this->wp_site_icon, 'additional_sizes' ) );

foreach ( $this->wp_site_icon->site_icon_sizes as $size ) {
$size_name = 'site_icon-' . $size;

$this->assertArrayHasKey( $size_name, $metadata['sizes'], "The {$size_name} sub-size was not generated." );
$this->assertSame(
array( $size, $size ),
array( $metadata['sizes'][ $size_name ]['width'], $metadata['sizes'][ $size_name ]['height'] ),
"The {$size_name} sub-size is not a square crop."
);
}
}

public function test_insert_cropped_attachment() {
$attachment_id = $this->insert_attachment();
$parent_url = get_post( $attachment_id )->guid;
Expand Down
Loading