Make WordPress Core


Ignore:
Timestamp:
09/25/2020 02:09:32 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Correct the check for image sizes in some REST API attachments controller tests.

If the sizes data could not be retrieved, the controller returns an empty object instead of an array.

This makes sure that the value is in fact an array before proceeding, and outputs a proper message in case of failure, instead of an obscure PHP error further in the test.

Follow-up to [49044].

See #50913, #51393.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php

    r49044 r49046  
    605605        remove_image_size( 'rest-api-test' );
    606606
    607         $this->assertNotEmpty( $data['media_details']['sizes'] );
     607        $this->assertInternalType( 'array', $data['media_details']['sizes'], 'Could not retrieve the sizes data.' );
    608608        $this->assertSame( $image_src[0], $data['media_details']['sizes']['rest-api-test']['source_url'] );
    609609        $this->assertSame( 'image/jpeg', $data['media_details']['sizes']['rest-api-test']['mime_type'] );
     
    634634        remove_image_size( 'rest-api-test' );
    635635
    636         $this->assertNotEmpty( $data['media_details']['sizes'] );
     636        $this->assertInternalType( 'array', $data['media_details']['sizes'], 'Could not retrieve the sizes data.' );
    637637        $this->assertFalse( isset( $data['media_details']['sizes']['rest-api-test']['source_url'] ) );
    638638    }
Note: See TracChangeset for help on using the changeset viewer.