Tests: Prevent an Ajax test for IMAGE_EDIT_OVERWRITE from being marked as risky.

This affects `Tests_Ajax_MediaEdit::testImageEditOverwriteConstant()`.

In case the `$files_that_should_not_exist` file list is empty, the test would be marked as risky, since it would not perform any assertions.

This small tweak prevents that from happening.

Follow-up to [38113].

Props jrf.
See #55652.

git-svn-id: https://develop.svn.wordpress.org/trunk@54073 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2022-09-05 19:22:27 +00:00
parent 10f6d876c9
commit 3ab0dc20b3

View File

@ -97,14 +97,24 @@ class Tests_Ajax_MediaEdit extends WP_Ajax_UnitTestCase {
$file_path = dirname( get_attached_file( $id ) );
$files_that_should_not_exist = array();
foreach ( $sizes1 as $key => $size ) {
if ( $sizes2[ $key ]['file'] !== $size['file'] ) {
$files_that_shouldnt_exist[] = $file_path . '/' . $size['file'];
$files_that_should_not_exist[] = $file_path . '/' . $size['file'];
}
}
foreach ( $files_that_shouldnt_exist as $file ) {
$this->assertFileDoesNotExist( $file, 'IMAGE_EDIT_OVERWRITE is leaving garbage image files behind.' );
if ( ! empty( $files_that_should_not_exist ) ) {
foreach ( $files_that_should_not_exist as $file ) {
$this->assertFileDoesNotExist( $file, 'IMAGE_EDIT_OVERWRITE is leaving garbage image files behind.' );
}
} else {
/*
* This assertion will always pass due to the "if" condition, but prevents this test
* from being marked as "risky" due to the test not performing any assertions.
*/
$this->assertSame( array(), $files_that_should_not_exist );
}
}
}