Tests: Refactor Tests_Image_Functions::test_is_displayable_image_negative() to use a data provider.

Using a data provider has a number of advantages:
1. If the first test case fails, it won't prevent the other test cases from being tested.
2. While the assertion used in this test method ''does'' have a "failure message" (👍), the output from PHPUnit itself will already be more descriptive in case of failure when using a data provider.
3. Using named test cases in the data provider will also make the `--testdox` output much more descriptive and informative.

The actual cases being tested, or the test itself have not been changed.

Includes:
* Adding a `@covers` annotation.

Follow-up to [184/tests], [53495], [53497], [53521], [53523], [53524], [53525].

Props jrf.
See #55652.

git-svn-id: https://develop.svn.wordpress.org/trunk@53526 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2022-06-19 15:34:21 +00:00
parent 2b9472a669
commit d143e9420f

View File

@ -87,8 +87,8 @@ class Tests_Image_Functions extends WP_UnitTestCase {
// These are all image files recognized by PHP.
$files = array(
'test-image-cmyk.jpg',
'test-image.bmp',
'test-image-grayscale.jpg',
'test-image.bmp',
'test-image.gif',
'test-image.png',
'test-image.tiff',
@ -180,12 +180,31 @@ class Tests_Image_Functions extends WP_UnitTestCase {
return $this->text_array_to_dataprovider( $files );
}
public function test_is_displayable_image_negative() {
/**
* @dataProvider data_is_displayable_image_negative
*
* @covers ::file_is_displayable_image
*
* @param string $file File name.
*/
public function test_is_displayable_image_negative( $file ) {
$this->assertFalse(
file_is_displayable_image( DIR_TESTDATA . '/images/' . $file ),
"file_is_displayable_image( '$file' ) should return false"
);
}
/**
* Data provider.
*
* @return array
*/
public function data_is_displayable_image_negative() {
// These are image files but aren't suitable for web pages because of compatibility or size issues.
$files = array(
// 'test-image-cmyk.jpg', Allowed in r9727.
// 'test-image.bmp', Allowed in r28589.
// 'test-image-grayscale.jpg', Allowed in r9727.
// 'test-image.bmp', Allowed in r28589.
'test-image.pct',
'test-image.tga',
'test-image.sgi',
@ -196,9 +215,7 @@ class Tests_Image_Functions extends WP_UnitTestCase {
'test-image-zip.tiff',
);
foreach ( $files as $file ) {
$this->assertFalse( file_is_displayable_image( DIR_TESTDATA . '/images/' . $file ), "file_is_valid_image($file) should return false" );
}
return $this->text_array_to_dataprovider( $files );
}
/**