Make WordPress Core


Ignore:
Timestamp:
09/05/2022 07:22:27 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/MediaEdit.php

    r53561 r54073  
    9898        $file_path = dirname( get_attached_file( $id ) );
    9999
     100        $files_that_should_not_exist = array();
     101
    100102        foreach ( $sizes1 as $key => $size ) {
    101103            if ( $sizes2[ $key ]['file'] !== $size['file'] ) {
    102                 $files_that_shouldnt_exist[] = $file_path . '/' . $size['file'];
     104                $files_that_should_not_exist[] = $file_path . '/' . $size['file'];
    103105            }
    104106        }
    105107
    106         foreach ( $files_that_shouldnt_exist as $file ) {
    107             $this->assertFileDoesNotExist( $file, 'IMAGE_EDIT_OVERWRITE is leaving garbage image files behind.' );
     108        if ( ! empty( $files_that_should_not_exist ) ) {
     109            foreach ( $files_that_should_not_exist as $file ) {
     110                $this->assertFileDoesNotExist( $file, 'IMAGE_EDIT_OVERWRITE is leaving garbage image files behind.' );
     111            }
     112        } else {
     113            /*
     114             * This assertion will always pass due to the "if" condition, but prevents this test
     115             * from being marked as "risky" due to the test not performing any assertions.
     116             */
     117            $this->assertSame( array(), $files_that_should_not_exist );
    108118        }
    109119    }
Note: See TracChangeset for help on using the changeset viewer.