WordPress.org

Make WordPress Core

Changeset 592 in tests


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

XMLRPC: Add test cases for mw_newPost based on the wp_newPost ones.

Bugs Found:

  • New featured image code doesn't work.
  • You can set the post_author to an invalid value.
File:
1 copied

Legend:

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

    r591 r592  
    11<?php 
    22 
    3 class TestXMLRPCServer_wp_newPost extends WPXMLRPCServerTestCase { 
     3class TestXMLRPCServer_mw_newPost extends WPXMLRPCServerTestCase { 
    44 
    55    function test_invalid_username_password() { 
    6         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'username', 'password' ) ); 
     6        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'username', 'password' ) ); 
    77        $this->assertInstanceOf( 'IXR_Error', $result ); 
    88        $this->assertEquals( 403, $result->code ); 
     
    1010 
    1111    function test_incapable_user() { 
    12         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'subscriber', 'subscriber' ) ); 
     12        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'subscriber', 'subscriber' ) ); 
    1313        $this->assertInstanceOf( 'IXR_Error', $result ); 
    1414        $this->assertEquals( 401, $result->code ); 
     
    1616 
    1717    function test_no_content() { 
    18         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author' ) ); 
     18        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author' ) ); 
    1919        $this->assertInstanceOf( 'IXR_Error', $result ); 
    2020        $this->assertEquals( 500, $result->code ); 
     
    2323 
    2424    function test_basic_content() { 
    25         $post = array( 'post_title' => 'Test' ); 
    26         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 
     25        $post = array( 'title' => 'Test' ); 
     26        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) ); 
    2727        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    2828        $this->assertStringMatchesFormat( '%d', $result ); 
     
    3030 
    3131    function test_ignore_id() { 
    32         $post = array( 'post_title' => 'Test', 'ID' => 103948 ); 
    33         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 
     32        $post = array( 'title' => 'Test', 'ID' => 103948 ); 
     33        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) ); 
    3434        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    3535        $this->assertNotEquals( '103948', $result ); 
     
    3737 
    3838    function test_capable_publish() { 
    39         $post = array( 'post_title' => 'Test', 'post_status' => 'publish' ); 
    40         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 
     39        $post = array( 'title' => 'Test', 'post_status' => 'publish' ); 
     40        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) ); 
    4141        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    4242    } 
    4343 
    4444    function test_incapable_publish() { 
    45         $post = array( 'post_title' => 'Test', 'post_status' => 'publish' ); 
    46         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) ); 
     45        $post = array( 'title' => 'Test', 'post_status' => 'publish' ); 
     46        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'contributor', 'contributor', $post ) ); 
    4747        $this->assertInstanceOf( 'IXR_Error', $result ); 
    4848        $this->assertEquals( 401, $result->code ); 
     
    5151    function test_capable_other_author() { 
    5252        $other_author_id = get_user_by( 'login', 'author' )->ID; 
    53         $post = array( 'post_title' => 'Test', 'post_author' => $other_author_id ); 
    54         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 
     53        $post = array( 'title' => 'Test', 'wp_author_id' => $other_author_id ); 
     54        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) ); 
    5555        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    5656    } 
     
    5858    function test_incapable_other_author() { 
    5959        $other_author_id = get_user_by( 'login', 'author' )->ID; 
    60         $post = array( 'post_title' => 'Test', 'post_author' => $other_author_id ); 
    61         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) ); 
     60        $post = array( 'title' => 'Test', 'wp_author_id' => $other_author_id ); 
     61        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'contributor', 'contributor', $post ) ); 
    6262        $this->assertInstanceOf( 'IXR_Error', $result ); 
    6363        $this->assertEquals( 401, $result->code ); 
    6464    } 
    6565 
     66    //TODO Raise Trac ticket for this bug 
    6667    function test_invalid_author() { 
    67         $post = array( 'post_title' => 'Test', 'post_author' => 99999999 ); 
    68         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 
     68        $post = array( 'title' => 'Test', 'wp_author_id' => 99999999 ); 
     69        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) ); 
    6970        $this->assertInstanceOf( 'IXR_Error', $result ); 
    7071        $this->assertEquals( 404, $result->code ); 
     
    7374    function test_empty_author() { 
    7475        $my_author_id = get_user_by( 'login', 'author' )->ID; 
    75         $post = array( 'post_title' => 'Test' ); 
    76         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 
     76        $post = array( 'title' => 'Test' ); 
     77        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) ); 
    7778        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    7879        $this->assertStringMatchesFormat( '%d', $result ); 
     
    100101        $attachment_id = wp_insert_attachment( $attachment, $upload['file'] ); 
    101102 
    102         $post = array( 'post_title' => 'Featured Image Test', 'featured_image' => $attachment_id ); 
    103         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 
     103        $post = array( 'title' => 'Featured Image Test', 'wp_featured_image' => $attachment_id ); 
     104        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) ); 
    104105        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    105106        $this->assertEquals( $attachment_id, get_post_meta( $result, '_thumbnail_id', true ) ); 
Note: See TracChangeset for help on using the changeset viewer.