Media: Some documentation and test improvements for WebP support:

* Document that WebP constants are only defined in PHP 7.1+.
* Correct the `$filename` parameter type in `wp_get_webp_info()`.
* Use a consistent message when skipping tests due to the lack of WebP support.
* Remove unnecessary `else` branches after `markTestSkipped()`.
* Replace `assertEquals()` with more appropriate assertions.

Follow-up to [50810].

See #35725.

git-svn-id: https://develop.svn.wordpress.org/trunk@50814 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2021-05-05 17:06:17 +00:00
parent 596a24c692
commit 462560edba
7 changed files with 38 additions and 28 deletions
+5 -5
View File
@@ -1240,11 +1240,11 @@ class Tests_Functions extends WP_UnitTestCase {
// let's restrict comparison to expected keys only.
if ( is_array( $expected ) ) {
foreach ( $expected as $k => $v ) {
$this->assertEquals( true, isset( $result[ $k ] ) );
$this->assertEquals( $expected[ $k ], $result[ $k ] );
$this->assertArrayHasKey( $k, $result );
$this->assertSame( $expected[ $k ], $result[ $k ] );
}
} else {
$this->assertEquals( $expected, $result );
$this->assertSame( $expected, $result );
}
}
@@ -1312,7 +1312,7 @@ class Tests_Functions extends WP_UnitTestCase {
}
/**
* Data provider for test_wp_get_image_mime();
* Data provider for test_wp_get_image_mime().
*/
public function _wp_get_image_mime() {
$data = array(
@@ -1367,7 +1367,7 @@ class Tests_Functions extends WP_UnitTestCase {
}
/**
* Data profider for test_wp_getimagesize();
* Data profider for test_wp_getimagesize().
*/
public function data_wp_getimagesize() {
$data = array(
+6 -5
View File
@@ -205,16 +205,17 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase {
*/
public function test_wp_get_webp_info( $file, $expected ) {
$editor = wp_get_image_editor( $file );
if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/webp' ) ) {
$this->markTestSkipped( sprintf( 'Skipping test: no WebP support in the editor engine %s on this system.', $this->editor_engine ) );
} else {
$file_data = wp_get_webp_info( $file );
$this->assertSame( $file_data, $expected );
$this->markTestSkipped( sprintf( 'No WebP support in the editor engine %s on this system.', $this->editor_engine ) );
}
$file_data = wp_get_webp_info( $file );
$this->assertSame( $file_data, $expected );
}
/**
* Data provider for test_wp_get_webp_info();
* Data provider for test_wp_get_webp_info().
*/
public function _test_wp_get_webp_info() {
return array(
+2 -1
View File
@@ -99,7 +99,8 @@ class Tests_Image_Functions extends WP_UnitTestCase {
// Add WebP images if the image editor supports them.
$file = DIR_TESTDATA . '/images/test-image.webp';
$editor = wp_get_image_editor( $file );
if ( ( ! is_wp_error( $editor ) ) && $editor->supports_mime_type( 'image/webp' ) ) {
if ( ! is_wp_error( $editor ) && $editor->supports_mime_type( 'image/webp' ) ) {
$files = array_merge(
$files,
array(
+9 -9
View File
@@ -70,16 +70,16 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase
// Check if the editor supports the webp mime type.
if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/webp' ) ) {
$this->markTestSkipped( sprintf( 'Skipping test: no WebP support in the editor engine %s on this system.', $this->editor_engine ) );
} else {
$image = $this->resize_helper( $file, 25, 25 );
$this->assertSame( 'test-image-25x25.webp', wp_basename( $image ) );
list($w, $h, $type) = wp_getimagesize( $image );
$this->assertSame( 25, $w );
$this->assertSame( 25, $h );
$this->assertSame( IMAGETYPE_WEBP, $type );
unlink( $image );
$this->markTestSkipped( sprintf( 'No WebP support in the editor engine %s on this system.', $this->editor_engine ) );
}
$image = $this->resize_helper( $file, 25, 25 );
$this->assertSame( 'test-image-25x25.webp', wp_basename( $image ) );
list($w, $h, $type) = wp_getimagesize( $image );
$this->assertSame( 25, $w );
$this->assertSame( 25, $h );
$this->assertSame( IMAGETYPE_WEBP, $type );
unlink( $image );
}
function test_resize_larger() {