FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix dominant color upload process to not override potential third-party editors by spacedmonkey · Pull Request #401 · WordPress/performance · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .php  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
17 changes: 15 additions & 2 deletions modules/images/dominant-color/load.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,30 @@ function dominant_color_add_inline_style() {
*
* @since 1.2.0
*
* @param string[] $editors Array of available image editor class names. Defaults are 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD'.
* @return string[] Registered image editors class names.
*/
function dominant_color_set_image_editors() {
function dominant_color_set_image_editors( $editors ) {
if ( ! class_exists( 'Dominant_Color_Image_Editor_GD' ) ) {
require_once __DIR__ . '/class-dominant-color-image-editor-gd.php';
}
if ( ! class_exists( 'Dominant_Color_Image_Editor_Imagick' ) ) {
require_once __DIR__ . '/class-dominant-color-image-editor-imagick.php';
}

return array( 'Dominant_Color_Image_Editor_GD', 'Dominant_Color_Image_Editor_Imagick' );
$replaces = array(
'WP_Image_Editor_GD' => 'Dominant_Color_Image_Editor_GD',
'WP_Image_Editor_Imagick' => 'Dominant_Color_Image_Editor_Imagick',
);

foreach ( $replaces as $old => $new ) {
$key = array_search( $old, $editors, true );
if ( false !== $key ) {
$editors[ $key ] = $new;
}
}

return $editors;
}

/**
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public function test_has_transparency_metadata( $image_path, $expected_color, $e
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
$transparency_metadata = dominant_color_metadata( array(), $attachment_id );
if ( strpos( $image_path, '.gif' ) ) {
$expected_transparency = true; // all gif have alpha.
}
$this->assertArrayHasKey( 'has_transparency', $transparency_metadata );
$this->assertSame( $expected_transparency, $transparency_metadata['has_transparency'] );
}
Expand All @@ -72,6 +75,9 @@ public function test_has_transparency_metadata( $image_path, $expected_color, $e
public function test_dominant_color_has_transparency( $image_path, $expected_color, $expected_transparency ) {
// Creating attachment.
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
if ( strpos( $image_path, '.gif' ) ) {
$expected_transparency = true; // all gif have alpha.
}
$this->assertSame( $expected_transparency, dominant_color_has_transparency( $attachment_id ) );
}

Expand All @@ -92,6 +98,9 @@ public function test_tag_add_adjust_to_image_attributes( $image_path, $expected_

$filtered_image_tags_added = dominant_color_img_tag_add_dominant_color( $filtered_image_mock_lazy_load, 'the_content', $attachment_id );

if ( strpos( $image_path, '.gif' ) ) {
$expected_transparency = true; // all gif have alpha.
}
$this->assertStringContainsString( 'data-has-transparency="' . json_encode( $expected_transparency ) . '"', $filtered_image_tags_added );

foreach ( $expected_color as $color ) {
Expand All @@ -109,6 +118,60 @@ public function test_tag_add_adjust_to_image_attributes( $image_path, $expected_
}


/**
* Tests dominant_color_set_image_editors().
*
* @dataProvider provider_dominant_color_set_image_editors
*
* @covers ::dominant_color_set_image_editors
*/
public function test_dominant_color_set_image_editors( $existing, $expected ) {
$this->assertEqualSets( dominant_color_set_image_editors( $existing ), $expected );
}

public function provider_dominant_color_set_image_editors() {
return array(
'default' => array(
'existing' => array(
'WP_Image_Editor_GD',
'WP_Image_Editor_Imagick',
),
'expected' => array(
'Dominant_Color_Image_Editor_GD',
'Dominant_Color_Image_Editor_Imagick',
),
),
'filtered' => array(
'existing' => array(
'WP_Image_Editor_Filered_GD',
'WP_Image_Editor_Filered_Imagick',
),
'expected' => array(
'WP_Image_Editor_Filered_GD',
'WP_Image_Editor_Filered_Imagick',
),
),
'added' => array(
'existing' => array(
'WP_Image_Editor_Filered_GD',
'WP_Image_Editor_Filered_Imagick',
'WP_Image_Editor_GD',
'WP_Image_Editor_Imagick',
),
'expected' => array(
'WP_Image_Editor_Filered_GD',
'WP_Image_Editor_Filered_Imagick',
'Dominant_Color_Image_Editor_GD',
'Dominant_Color_Image_Editor_Imagick',
),
),
'empty' => array(
'existing' => array(),
'expected' => array(),
),
);
}

/**
* Tests dominant_color_rgb_to_hex().
*
Expand Down

Back | FazBrowse Home | New Git URL