Make WordPress Core


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

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

See #25275.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.