Skip to content

Commit 8ffe5df

Browse files
Revert: Load the WP_Image_Editor_GD class if it doesn't exist
1 parent 834eeb5 commit 8ffe5df

File tree

9 files changed

+80
-85
lines changed

9 files changed

+80
-85
lines changed

‎modules/images/dominant-color/class-dominant-color-image-editor-gd.php‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
* @since 1.2.0
1010
*/
1111

12-
if ( ! class_exists( 'WP_Image_Editor_GD' ) ) {
13-
require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
14-
require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php';
15-
}
16-
1712
/**
1813
* WordPress Image Editor Class for Image Manipulation through GD
1914
* with dominant color detection.

‎tests/admin/load-tests.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function test_perflab_add_modules_page() {
6868
remove_all_filters( 'plugin_action_links_' . plugin_basename( PERFLAB_MAIN_FILE ) );
6969

7070
// Rely on current user to be an administrator (with 'manage_options' capability).
71-
$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
71+
$user_id = $this->factory()->user->create( array( 'role' => 'administrator' ) );
7272
wp_set_current_user( $user_id );
7373
$hook_suffix = perflab_add_modules_page();
7474
$this->assertSame( get_plugin_page_hookname( PERFLAB_MODULES_SCREEN, 'options-general.php' ), $hook_suffix );

‎tests/modules/images/dominant-color/dominant-color-image-editor-gd-test.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static function () {
3030
*/
3131
public function test_get_dominant_color( $image_path, $expected_color, $expected_transparency ) {
3232

33-
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
33+
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
3434
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
3535

3636
$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
@@ -50,7 +50,7 @@ public function test_get_dominant_color( $image_path, $expected_color, $expected
5050
*/
5151
public function test_get_dominant_color_invalid( $image_path, $expected_color, $expected_transparency ) {
5252

53-
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
53+
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
5454
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
5555

5656
$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
@@ -68,7 +68,7 @@ public function test_get_dominant_color_invalid( $image_path, $expected_color, $
6868
*/
6969
public function test_get_dominant_color_none_images( $image_path ) {
7070

71-
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
71+
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
7272
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
7373

7474
$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );

‎tests/modules/images/dominant-color/dominant-color-image-editor-imageick-test.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static function () {
3232
*/
3333
public function test_get_dominant_color( $image_path, $expected_color, $expected_transparency ) {
3434

35-
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
35+
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
3636
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
3737

3838
$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
@@ -52,7 +52,7 @@ public function test_get_dominant_color( $image_path, $expected_color, $expected
5252
*/
5353
public function test_get_dominant_color_invalid( $image_path, $expected_color, $expected_transparency ) {
5454

55-
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
55+
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
5656
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
5757

5858
$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
@@ -70,7 +70,7 @@ public function test_get_dominant_color_invalid( $image_path, $expected_color, $
7070
*/
7171
public function test_get_dominant_color_none_images( $image_path ) {
7272

73-
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
73+
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
7474
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
7575

7676
$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );

‎tests/modules/images/dominant-color/dominant-color-test.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function test_dominant_color_metadata( $image_path, $expected_color, $exp
2222
$this->assertEmpty( $dominant_color_metadata );
2323

2424
// Creating attachment.
25-
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
25+
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
2626
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
2727
$dominant_color_metadata = dominant_color_metadata( array(), $attachment_id );
2828
$this->assertArrayHasKey( 'dominant_color', $dominant_color_metadata );
@@ -39,7 +39,7 @@ public function test_dominant_color_metadata( $image_path, $expected_color, $exp
3939
*/
4040
public function test_dominant_color_get_dominant_color( $image_path, $expected_color, $expected_transparency ) {
4141
// Creating attachment.
42-
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
42+
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
4343
$this->assertContains( dominant_color_get_dominant_color( $attachment_id ), $expected_color );
4444
}
4545

@@ -55,7 +55,7 @@ public function test_has_transparency_metadata( $image_path, $expected_color, $e
5555
$transparency_metadata = dominant_color_metadata( array(), 1 );
5656
$this->assertEmpty( $transparency_metadata );
5757

58-
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
58+
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
5959
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
6060
$transparency_metadata = dominant_color_metadata( array(), $attachment_id );
6161
$this->assertArrayHasKey( 'has_transparency', $transparency_metadata );
@@ -71,7 +71,7 @@ public function test_has_transparency_metadata( $image_path, $expected_color, $e
7171
*/
7272
public function test_dominant_color_has_transparency( $image_path, $expected_color, $expected_transparency ) {
7373
// Creating attachment.
74-
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
74+
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
7575
$this->assertSame( $expected_transparency, dominant_color_has_transparency( $attachment_id ) );
7676
}
7777

@@ -83,7 +83,7 @@ public function test_dominant_color_has_transparency( $image_path, $expected_col
8383
* @covers ::dominant_color_img_tag_add_dominant_color
8484
*/
8585
public function test_tag_add_adjust_to_image_attributes( $image_path, $expected_color, $expected_transparency ) {
86-
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
86+
$attachment_id = $this->factory->attachment->create_upload_object( $image_path );
8787
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
8888

8989
list( $src, $width, $height ) = wp_get_attachment_image_src( $attachment_id );

‎tests/modules/images/webp-uploads/helper-tests.php‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,29 @@ public function data_provider_invalid_arguments_for_webp_uploads_generate_additi
3131

3232
add_filter( 'wp_image_editors', '__return_empty_array' );
3333
yield 'when no editor is present' => array(
34-
self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
34+
$this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
3535
'medium',
3636
array(),
3737
'image/avif',
3838
);
3939

4040
remove_filter( 'wp_image_editors', '__return_empty_array' );
4141
yield 'when using a mime that is not supported' => array(
42-
self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
42+
$this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
4343
'medium',
4444
array(),
4545
'image/avif',
4646
);
4747

4848
yield 'when no dimension is provided' => array(
49-
self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
49+
$this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
5050
'medium',
5151
array(),
5252
'image/webp',
5353
);
5454

5555
yield 'when both dimensions are negative numbers' => array(
56-
self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
56+
$this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
5757
'medium',
5858
array(
5959
'width' => -10,
@@ -63,7 +63,7 @@ public function data_provider_invalid_arguments_for_webp_uploads_generate_additi
6363
);
6464

6565
yield 'when both dimensions are zero' => array(
66-
self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
66+
$this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
6767
'medium',
6868
array(
6969
'width' => 0,
@@ -82,7 +82,7 @@ public function it_should_create_an_image_with_the_default_suffix_in_the_same_lo
8282
// Create JPEG and WebP so that both versions are generated.
8383
$this->opt_in_to_jpeg_and_webp();
8484

85-
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
85+
$attachment_id = $this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
8686
$size_data = array(
8787
'width' => 300,
8888
'height' => 300,
@@ -107,7 +107,7 @@ public function it_should_create_an_image_with_the_default_suffix_in_the_same_lo
107107
* @test
108108
*/
109109
public function it_should_create_a_file_in_the_specified_location_with_the_specified_name() {
110-
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
110+
$attachment_id = $this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
111111
$size_data = array(
112112
'width' => 300,
113113
'height' => 300,
@@ -131,7 +131,7 @@ public function it_should_create_a_file_in_the_specified_location_with_the_speci
131131
* @test
132132
*/
133133
public function it_should_prevent_processing_an_image_with_corrupted_metadata( callable $callback, $size ) {
134-
$attachment_id = self::factory()->attachment->create_upload_object(
134+
$attachment_id = $this->factory->attachment->create_upload_object(
135135
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/balloons.webp'
136136
);
137137
$metadata = wp_get_attachment_metadata( $attachment_id );
@@ -175,7 +175,7 @@ function ( $metadata ) {
175175
* @test
176176
*/
177177
public function it_should_prevent_to_create_an_image_size_when_attached_file_does_not_exists() {
178-
$attachment_id = self::factory()->attachment->create_upload_object(
178+
$attachment_id = $this->factory->attachment->create_upload_object(
179179
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg'
180180
);
181181
$file = get_attached_file( $attachment_id );
@@ -199,7 +199,7 @@ public function it_should_prevent_to_create_an_image_size_when_attached_file_doe
199199
* @test
200200
*/
201201
public function it_should_prevent_to_create_a_subsize_if_the_image_editor_does_not_exists() {
202-
$attachment_id = self::factory()->attachment->create_upload_object(
202+
$attachment_id = $this->factory->attachment->create_upload_object(
203203
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg'
204204
);
205205

@@ -216,7 +216,7 @@ public function it_should_prevent_to_create_a_subsize_if_the_image_editor_does_n
216216
* @test
217217
*/
218218
public function it_should_prevent_to_upload_a_mime_that_is_not_supported_by_wordpress() {
219-
$attachment_id = self::factory()->attachment->create_upload_object(
219+
$attachment_id = $this->factory->attachment->create_upload_object(
220220
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg'
221221
);
222222
$result = webp_uploads_generate_image_size( $attachment_id, 'medium', 'image/avif' );
@@ -231,7 +231,7 @@ public function it_should_prevent_to_upload_a_mime_that_is_not_supported_by_word
231231
*/
232232
public function it_should_prevent_to_process_an_image_when_the_editor_does_not_support_the_format() {
233233
// Make sure no editor is available.
234-
$attachment_id = self::factory()->attachment->create_upload_object(
234+
$attachment_id = $this->factory->attachment->create_upload_object(
235235
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg'
236236
);
237237

@@ -255,7 +255,7 @@ function () {
255255
public function it_should_create_an_image_with_filter_webp_uploads_pre_generate_additional_image_source() {
256256
remove_all_filters( 'webp_uploads_pre_generate_additional_image_source' );
257257

258-
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
258+
$attachment_id = $this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
259259

260260
add_filter(
261261
'webp_uploads_pre_generate_additional_image_source',
@@ -289,7 +289,7 @@ function () {
289289
public function it_should_use_filesize_when_filter_webp_uploads_pre_generate_additional_image_source_returns_filesize() {
290290
remove_all_filters( 'webp_uploads_pre_generate_additional_image_source' );
291291

292-
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
292+
$attachment_id = $this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
293293

294294
add_filter(
295295
'webp_uploads_pre_generate_additional_image_source',
@@ -324,7 +324,7 @@ function () {
324324
public function it_should_return_an_error_when_filter_webp_uploads_pre_generate_additional_image_source_returns_wp_error() {
325325
remove_all_filters( 'webp_uploads_pre_generate_additional_image_source' );
326326

327-
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
327+
$attachment_id = $this->factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' );
328328

329329
add_filter(
330330
'webp_uploads_pre_generate_additional_image_source',
@@ -547,8 +547,8 @@ private function mock_empty_action( $action ) {
547547
* @test
548548
*/
549549
public function it_should_add_original_image_extension_to_the_webp_file_name_to_ensure_it_is_unique( $jpeg_image, $jpg_image ) {
550-
$jpeg_image_attachment_id = self::factory()->attachment->create_upload_object( $jpeg_image );
551-
$jpg_image_attachment_id = self::factory()->attachment->create_upload_object( $jpg_image );
550+
$jpeg_image_attachment_id = $this->factory->attachment->create_upload_object( $jpeg_image );
551+
$jpg_image_attachment_id = $this->factory->attachment->create_upload_object( $jpg_image );
552552

553553
$size_data = array(
554554
'width' => 300,

0 commit comments

Comments
 (0)