Make WordPress Core


Ignore:
Timestamp:
08/27/2016 05:24:58 PM (8 years ago)
Author:
johnbillion
Message:

Media: Add a $wp_error parameter to wp_insert_attachment() to give it parity with wp_insert_post().

Fixes #37813
Props grapplerulrich, mrahmadawais

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r38398 r38408  
    17971797        return $data;
    17981798    }
     1799
     1800    /**
     1801     * @ticket 37813
     1802     */
     1803    public function test_return_type_when_inserting_attachment_with_error_in_data() {
     1804        $data = array(
     1805            'post_status'  => 'public',
     1806            'post_content' => 'Attachment content',
     1807            'post_title'   => 'Attachment Title',
     1808            'post_date'    => '2012-02-30 00:00:00',
     1809        );
     1810
     1811        $attachment_id = wp_insert_attachment( $data, '', 0, true );
     1812        $this->assertWPError( $attachment_id );
     1813        $this->assertEquals( 'invalid_date', $attachment_id->get_error_code() );
     1814
     1815        $attachment_id = wp_insert_attachment( $data, '', 0 );
     1816        $this->assertSame( 0, $attachment_id );
     1817    }
    17991818}
    18001819
Note: See TracChangeset for help on using the changeset viewer.