WordPress.org

Make WordPress Core

Changeset 555 in tests


Ignore:
Timestamp:
02/26/12 16:58:12 (2 years ago)
Author:
maxcutler
Message:

XMLRPC: Add tests for 'featured_image' field support in wp.getPost, wp.newPost and wp.editPost. See #18429

Location:
wp-testcase/test-xmlrpc-api
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test-xmlrpc-api/test_wp_editPost.php

    r548 r555  
    8585    } 
    8686 
     87    function test_featured_image() { 
     88        $author_id = get_user_by( 'login', 'author' )->ID; 
     89        $post = array( 'post_title' => 'Featured Image Test', 'post_author' => $author_id ); 
     90        $post_id = wp_insert_post( $post ); 
     91 
     92        $this->assertEquals( '', get_post_meta( $post_id, '_thumbnail_id', true ) ); 
     93 
     94        // create attachment 
     95        $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' ); 
     96        $contents = file_get_contents( $filename ); 
     97        $upload = wp_upload_bits( $filename, 'image/jpeg', $contents ); 
     98        $this->assertTrue( empty( $upload['error'] ) ); 
     99 
     100        $attachment = array( 
     101            'post_title' => 'Featured Image', 
     102            'post_type' => 'attachment', 
     103            'post_mime_type' => 'image/jpeg', 
     104            'guid' => $upload['url'] 
     105        ); 
     106        $attachment_id = wp_insert_attachment( $attachment, $upload['file'], $post_id ); 
     107 
     108        // add featured image to post that does not have one 
     109        $post2 = array( 'featured_image' => $attachment_id ); 
     110        $result = $this->myxmlrpcserver->wp_editPost( array(1, 'author', 'author', $post_id, $post2 ) ); 
     111        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     112        $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); 
     113 
     114        // edit the post without supplying a featured_image and check that it didn't change 
     115        $post3 = array( 'post_content' => 'Updated post' ); 
     116        $result = $this->myxmlrpcserver->wp_editPost( array(1, 'author', 'author', $post_id, $post3 ) ); 
     117        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     118        $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); 
     119 
     120        // create another attachment 
     121        $attachment2 = array_merge( $attachment, array( 'post_title' => 'Featured Image 2' ) ); 
     122        $attachment2_id = wp_insert_attachment( $attachment2, $upload['file'], $post_id ); 
     123 
     124        // change the post's featured_image 
     125        $post4 = array( 'featured_image' => $attachment2_id ); 
     126        $result = $this->myxmlrpcserver->wp_editPost( array(1, 'author', 'author', $post_id, $post4 ) ); 
     127        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     128        $this->assertEquals( $attachment2_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); 
     129 
     130        // unset the post's featured_image 
     131        $post5 = array( 'featured_image' => '' ); 
     132        $result = $this->myxmlrpcserver->wp_editPost( array(1, 'author', 'author', $post_id, $post5 ) ); 
     133        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     134        $this->assertEquals( '', get_post_meta( $post_id, '_thumbnail_id', true ) ); 
     135    } 
     136 
    87137} 
  • wp-testcase/test-xmlrpc-api/test_wp_getPost.php

    r554 r555  
    5656        $this->assertInternalType( 'bool', $result['sticky'] ); 
    5757        $this->assertInternalType( 'string', $result['post_format'] ); 
     58        $this->assertInternalType( 'string', $result['featured_image'] ); 
    5859 
    5960        // Check expected values 
     
    6869        $this->assertEquals( $this->post_data['post_content'], $result['post_content'] ); 
    6970        $this->assertEquals( url_to_postid( $result['link'] ), $this->post_id ); 
     71        $this->assertEquals( '', $result['featured_image'] ); 
    7072    } 
    7173 
  • wp-testcase/test-xmlrpc-api/test_wp_newPost.php

    r548 r555  
    8181    } 
    8282 
     83    function test_featured_image() { 
     84        // create attachment 
     85        $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' ); 
     86        $contents = file_get_contents( $filename ); 
     87        $upload = wp_upload_bits( $filename, 'image/jpeg', $contents ); 
     88        $this->assertTrue( empty( $upload['error'] ) ); 
     89 
     90        $attachment = array( 
     91            'post_title' => 'Featured Image', 
     92            'post_type' => 'attachment', 
     93            'post_mime_type' => 'image/jpeg', 
     94            'guid' => $upload['url'] 
     95        ); 
     96        $attachment_id = wp_insert_attachment( $attachment, $upload['file'] ); 
     97 
     98        $post = array( 'post_title' => 'Featured Image Test', 'featured_image' => $attachment_id ); 
     99        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 
     100        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     101        $this->assertEquals( $attachment_id, get_post_meta( $result, '_thumbnail_id', true ) ); 
     102    } 
     103 
    83104} 
Note: See TracChangeset for help on using the changeset viewer.