Make WordPress Core

Changeset 55070


Ignore:
Timestamp:
01/15/2023 01:36:10 PM (22 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use more specific assertions in image saving tests.

When passed a WP_Image_Editor instance as the $image parameter, wp_save_image_file() returns an array on success, so we can specifically check for an array instead of any non-empty result.

Likewise, in PDF tests, when creating an attachment is expected to return an integer ID and not a WP_Error object, we can specifically check for that.

Follow-up to [1061/tests], [38949], [39617], [42792], [53529], [53530], [53531], [55019], [55066].

See #56793.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/functions.php

    r55066 r55070  
    284284
    285285        // Make assertions.
    286         $this->assertNotEmpty( $ret, 'Image failed to save - "empty" response returned.' );
    287286        $this->assertNotWPError( $ret, 'Image failed to save - WP_Error returned.' );
     287        $this->assertIsArray( $ret, 'Image failed to save - non-array response returned.' );
    288288        $this->assertSame( $mime_type, $this->get_mime_type( $ret['path'] ), 'Mime type of the saved image does not match.' );
    289289
     
    375375
    376376        // Make assertions.
    377         $this->assertNotEmpty( $ret, 'Image failed to save - "empty" response returned.' );
    378377        $this->assertNotWPError( $ret, 'Image failed to save - WP_Error returned.' );
     378        $this->assertIsArray( $ret, 'Image failed to save - non-array response returned.' );
    379379        $this->assertSame( $mime_type, $this->get_mime_type( $ret['path'] ), 'Mime type of the saved image did not override file name.' );
    380380
     
    421421
    422422        // Make assertions.
    423         $this->assertNotEmpty( $ret, 'Image failed to save - "empty" response returned.' );
    424423        $this->assertNotWPError( $ret, 'Image failed to save - WP Error returned.' );
     424        $this->assertIsArray( $ret, 'Image failed to save - non-array response returned.' );
    425425        $this->assertSame( $mime_type, $this->get_mime_type( $ret['path'] ), 'Mime type of the saved image was not inferred correctly.' );
    426426
     
    680680        );
    681681
    682         $this->assertNotEmpty( $attachment_id );
     682        $this->assertNotWPError( $attachment_id, 'Could not create attachment - WP_Error returned.' );
     683        $this->assertIsInt( $attachment_id, 'Could not create attachment - non-integer response returned.' );
    683684
    684685        $temp_dir = get_temp_dir();
     
    757758        );
    758759
    759         $this->assertNotEmpty( $attachment_id );
     760        $this->assertNotWPError( $attachment_id, 'Could not create attachment - WP_Error returned.' );
     761        $this->assertIsInt( $attachment_id, 'Could not create attachment - non-integer response returned.' );
    760762
    761763        $temp_dir = get_temp_dir();
     
    830832        );
    831833
    832         $this->assertNotEmpty( $attachment_id );
     834        $this->assertNotWPError( $attachment_id, 'Could not create attachment - WP_Error returned.' );
     835        $this->assertIsInt( $attachment_id, 'Could not create attachment - non-integer response returned.' );
    833836
    834837        add_image_size( 'test-size', 100, 100 );
Note: See TracChangeset for help on using the changeset viewer.