WordPress.org

Make WordPress Core

Changeset 593 in tests


Ignore:
Timestamp:
03/29/12 11:57:38 (2 years ago)
Author:
westi
Message:

XMLRPC: Add test cases for mw_editPost based on the wp_editPost ones.

Bugs found:

  • Feature image setting doesn't work
  • mw_editPost eats content if you don't set all the fields or rejects the edit with a 500 error.
File:
1 copied

Legend:

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

    r591 r593  
    11<?php 
    22 
    3 class TestXMLRPCServer_wp_editPost extends WPXMLRPCServerTestCase { 
     3class TestXMLRPCServer_mw_editPost extends WPXMLRPCServerTestCase { 
    44 
    55    function test_invalid_username_password() { 
    6         $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'username', 'password' ) ); 
     6        $result = $this->myxmlrpcserver->mw_editPost( array( 1, 'username', 'password' ) ); 
    77        $this->assertInstanceOf( 'IXR_Error', $result ); 
    88        $this->assertEquals( 403, $result->code ); 
     
    1515 
    1616        $new_title = 'Post test (updated)'; 
    17         $post2 = array( 'post_title' => $new_title ); 
    18         $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) ); 
     17        $post2 = array( 'title' => $new_title ); 
     18        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post2 ) ); 
    1919        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    2020        $this->assertTrue($result); 
     
    3030 
    3131        $new_title = 'Post test (updated)'; 
    32         $post2 = array( 'post_title' => $new_title ); 
    33         $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) ); 
     32        $post2 = array( 'title' => $new_title ); 
     33        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', $post2 ) ); 
    3434        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    3535        $this->assertTrue($result); 
     
    4646 
    4747        $new_title = 'Post test (updated)'; 
    48         $post2 = array( 'post_title' => $new_title ); 
    49         $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) ); 
     48        $post2 = array( 'title' => $new_title ); 
     49        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post2 ) ); 
    5050        $this->assertInstanceOf( 'IXR_Error', $result ); 
    5151        $this->assertEquals( 401, $result->code ); 
     
    6161 
    6262        $author_id = get_user_by( 'login', 'author' )->ID; 
    63         $post2 = array( 'post_author' => $author_id ); 
    64         $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) ); 
     63        $post2 = array( 'wp_author_id' => $author_id ); 
     64        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', $post2 ) ); 
    6565        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    6666        $this->assertTrue($result); 
     
    7676 
    7777        $author_id = get_user_by( 'login', 'author' )->ID; 
    78         $post2 = array( 'post_author' => $author_id ); 
    79         $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) ); 
     78        $post2 = array( 'wp_author_id' => $author_id ); 
     79        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post2 ) ); 
    8080        $this->assertInstanceOf( 'IXR_Error', $result ); 
    8181        $this->assertEquals( 401, $result->code ); 
     
    109109 
    110110        // add featured image to post that does not have one 
    111         $post2 = array( 'featured_image' => $attachment_id ); 
    112         $result = $this->myxmlrpcserver->wp_editPost( array(1, 'author', 'author', $post_id, $post2 ) ); 
     111        $post2 = array( 'wp_featured_image' => $attachment_id ); 
     112        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post2 ) ); 
    113113        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    114114        $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); 
     
    116116        // edit the post without supplying a featured_image and check that it didn't change 
    117117        $post3 = array( 'post_content' => 'Updated post' ); 
    118         $result = $this->myxmlrpcserver->wp_editPost( array(1, 'author', 'author', $post_id, $post3 ) ); 
     118        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post3 ) ); 
    119119        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    120120        $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); 
    121121 
    122122        // create another attachment 
    123         $attachment2 = array_merge( $attachment, array( 'post_title' => 'Featured Image 2' ) ); 
     123        $attachment2 = array_merge( $attachment, array( 'title' => 'Featured Image 2' ) ); 
    124124        $attachment2_id = wp_insert_attachment( $attachment2, $upload['file'], $post_id ); 
    125125 
    126126        // change the post's featured_image 
    127         $post4 = array( 'featured_image' => $attachment2_id ); 
    128         $result = $this->myxmlrpcserver->wp_editPost( array(1, 'author', 'author', $post_id, $post4 ) ); 
     127        $post4 = array( 'wp_featured_image' => $attachment2_id ); 
     128        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post4 ) ); 
    129129        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    130130        $this->assertEquals( $attachment2_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); 
    131131 
    132132        // unset the post's featured_image 
    133         $post5 = array( 'featured_image' => '' ); 
    134         $result = $this->myxmlrpcserver->wp_editPost( array(1, 'author', 'author', $post_id, $post5 ) ); 
     133        $post5 = array( 'wp_featured_image' => '' ); 
     134        $result = $this->myxmlrpcserver->mw_editPost( array($post_id, 'author', 'author', $post5 ) ); 
    135135        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    136136        $this->assertEquals( '', get_post_meta( $post_id, '_thumbnail_id', true ) ); 
     
    139139    } 
    140140 
     141    function test_edit_basic_post_info() { 
     142        $contributor_id = get_user_by( 'login', 'contributor' )->ID; 
     143        $post = array( 'post_title' => 'Title', 'post_content' => 'Content', 'post_excerpt' => 'Excerpt', 'post_author' => $contributor_id ); 
     144        $post_id = wp_insert_post( $post ); 
     145 
     146        $post2 = array( 'title' => 'New Title', 'post_author' => $contributor_id ); 
     147        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post2 ) ); 
     148        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     149        $this->assertTrue($result); 
     150 
     151        $out = wp_get_single_post( $post_id ); 
     152        $this->assertEquals( $post2['title'], $out->post_title ); 
     153 
     154        $post3 = array( 'description' => 'New Content', 'post_author' => $contributor_id ); 
     155        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post3 ) ); 
     156        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     157        $this->assertTrue($result); 
     158 
     159        $out = wp_get_single_post( $post_id ); 
     160        $this->assertEquals( $post2['title'], $out->post_title ); 
     161        $this->assertEquals( $post3['description'], $out->post_content ); 
     162 
     163        $post4 = array( 'mt_excerpt' => 'New Excerpt', 'post_author' => $contributor_id ); 
     164        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post4 ) ); 
     165        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     166        $this->assertTrue($result); 
     167 
     168        $out = wp_get_single_post( $post_id ); 
     169        $this->assertEquals( $post2['title'], $out->post_title ); 
     170        $this->assertEquals( $post3['description'], $out->post_content ); 
     171        $this->assertEquals( $post4['mt_excerpt'], $out->post_excerpt ); 
     172 
     173    } 
     174 
    141175} 
Note: See TracChangeset for help on using the changeset viewer.