Make WordPress Core

Changeset 31647


Ignore:
Timestamp:
03/06/2015 08:37:08 PM (11 years ago)
Author:
wonderboymusic
Message:

Add unit tests for wp_attachment_is(), checks the whitelist and arbitrary extension.

See #25275.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r31646 r31647  
    50925092
    50935093        $check = wp_check_filetype( $file );
    5094         if ( empty( $check['ext'] ) || 'import' !== $post->post_mime_type ) {
     5094        if ( empty( $check['ext'] ) ) {
    50955095                return false;
    50965096        }
     5097
    50975098        $ext = $check['ext'];
     5099
     5100        if ( 'import' !== $post->post_mime_type ) {
     5101                return $type === $ext;
     5102        }
    50985103
    50995104        switch ( $type ) {
  • trunk/tests/phpunit/tests/post/attachments.php

    r31614 r31647  
    440440        }
    441441
     442        public function test_wp_attachment_is() {
     443                $filename = DIR_TESTDATA . '/images/test-image.jpg';
     444                $contents = file_get_contents( $filename );
     445
     446                $upload = wp_upload_bits( basename( $filename ), null, $contents );
     447                $attachment_id = $this->_make_attachment( $upload );
     448
     449                $this->assertTrue( wp_attachment_is_image( $attachment_id ) );
     450                $this->assertTrue( wp_attachment_is( 'image', $attachment_id ) );
     451                $this->assertFalse( wp_attachment_is( 'audio', $attachment_id ) );
     452                $this->assertFalse( wp_attachment_is( 'video', $attachment_id ) );
     453        }
     454
     455        public function test_wp_attachment_is_default() {
     456                $filename = DIR_TESTDATA . '/images/test-image.psd';
     457                $contents = file_get_contents( $filename );
     458
     459                $upload = wp_upload_bits( basename( $filename ), null, $contents );
     460                $attachment_id = $this->_make_attachment( $upload );
     461
     462                $this->assertFalse( wp_attachment_is_image( $attachment_id ) );
     463                $this->assertTrue( wp_attachment_is( 'psd', $attachment_id ) );
     464                $this->assertFalse( wp_attachment_is( 'audio', $attachment_id ) );
     465                $this->assertFalse( wp_attachment_is( 'video', $attachment_id ) );
     466        }
    442467}
Note: See TracChangeset for help on using the changeset viewer.