WordPress.org

Make WordPress Core

Changeset 739 in tests


Ignore:
Timestamp:
06/16/12 21:53:48 (22 months ago)
Author:
maxcutler
Message:

XMLRPC: Added more comprehensive tests for all the 3.4 post methods and wp.getTerms.

Location:
wp-testcase/test-xmlrpc-api
Files:
1 added
5 edited

Legend:

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

    r697 r739  
    110110        // add post thumbnail to post that does not have one 
    111111        $post2 = array( 'post_thumbnail' => $attachment_id ); 
    112         $result = $this->myxmlrpcserver->wp_editPost( array(1, 'author', 'author', $post_id, $post2 ) ); 
     112        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post2 ) ); 
    113113        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    114114        $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); 
     115 
     116        // fetch the post to verify that it appears 
     117        $result = $this->myxmlrpcserver->wp_getPost( array( 1, 'author', 'author', $post_id ) ); 
     118        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     119        $this->assertArrayHasKey( 'post_thumbnail', $result ); 
     120        $this->assertInternalType( 'array', $result['post_thumbnail'] ); 
     121        $this->assertEquals( $attachment_id, $result['post_thumbnail']['attachment_id'] ); 
    115122 
    116123        // edit the post without supplying a post_thumbnail and check that it didn't change 
    117124        $post3 = array( 'post_content' => 'Updated post' ); 
    118         $result = $this->myxmlrpcserver->wp_editPost( array(1, 'author', 'author', $post_id, $post3 ) ); 
     125        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post3 ) ); 
    119126        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    120127        $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); 
     
    126133        // change the post's post_thumbnail 
    127134        $post4 = array( 'post_thumbnail' => $attachment2_id ); 
    128         $result = $this->myxmlrpcserver->wp_editPost( array(1, 'author', 'author', $post_id, $post4 ) ); 
     135        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post4 ) ); 
    129136        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    130137        $this->assertEquals( $attachment2_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); 
     
    132139        // unset the post's post_thumbnail 
    133140        $post5 = array( 'post_thumbnail' => '' ); 
    134         $result = $this->myxmlrpcserver->wp_editPost( array(1, 'author', 'author', $post_id, $post5 ) ); 
     141        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post5 ) ); 
    135142        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    136143        $this->assertEquals( '', get_post_meta( $post_id, '_thumbnail_id', true ) ); 
     144 
     145        // use invalid ID 
     146        $post6 = array( 'post_thumbnail' => 398420983409 ); 
     147        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post6 ) ); 
     148        $this->assertInstanceOf( 'IXR_Error', $result ); 
     149        $this->assertEquals( 404, $result->code ); 
    137150 
    138151        remove_theme_support( 'post-thumbnails' ); 
     
    153166                    array( 'id' => $mid_delete ), 
    154167                    array( 'id' => $mid_edit, 'key' => 'custom_field_key', 'value' => '87654321' ), 
     168                    array( 'key' => 'custom_field_to_create', 'value' => '12345678' ) 
    155169                ) 
    156170        ); 
     
    166180        $this->assertEquals( '87654321', $edited_object->meta_value ); 
    167181        $this->assertFalse( get_metadata_by_mid( 'post', $mid_delete ) ); 
     182 
     183        $created_object = get_post_meta( $post_id, 'custom_field_to_create', true ); 
     184        $this->assertEquals( $created_object, '12345678' ); 
     185    } 
     186 
     187    function test_capable_unsticky() { 
     188        $this->author = get_user_by( 'login', 'editor' ); 
     189        $this->_insert_quick_posts( 1 ); 
     190        $post_id = array_pop( $this->post_ids ); 
     191        stick_post( $post_id ); 
     192 
     193        $post2 = array( 'sticky' => false ); 
     194        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) ); 
     195        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     196        $this->assertFalse( is_sticky( $post_id ) ); 
     197 
     198        wp_delete_post( $post_id, true ); 
     199    } 
     200 
     201    function test_password_transition_unsticky() { 
     202        // when transitioning to private status or adding a post password, post should be un-stuck 
     203        $this->author = get_user_by( 'login', 'editor' ); 
     204        $this->_insert_quick_posts( 1 ); 
     205        $post_id = array_pop( $this->post_ids ); 
     206        stick_post( $post_id ); 
     207 
     208        $post2 = array( 'post_password' => 'foobar',  'sticky' => false ); 
     209        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) ); 
     210        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     211        $this->assertFalse( is_sticky( $post_id ) ); 
     212 
     213        wp_delete_post( $post_id, true ); 
    168214    } 
    169215 
  • wp-testcase/test-xmlrpc-api/test_wp_getPost.php

    r701 r739  
    11<?php 
    2  
    3 include_once(ABSPATH . WPINC . '/post-thumbnail-template.php');  
    42 
    53class TestXMLRPCServer_wp_getPost extends WPXMLRPCServerTestCase { 
     
    75    var $post_id; 
    86    var $post_date_ts; 
     7    var $post_custom_field; 
    98 
    109    function setUp() { 
     
    2019        ); 
    2120        $this->post_id = wp_insert_post( $this->post_data ); 
     21        $this->post_custom_field = array( 'key' => 'test_custom_field', 'value' => 12345678); 
     22        $this->post_custom_field['id'] = add_post_meta( $this->post_id, $this->post_custom_field['key'], $this->post_custom_field['value'] ); 
    2223    } 
    2324 
     
    3738        add_theme_support( 'post-thumbnails' ); 
    3839 
    39         $fields = array( 'post' ); 
     40        $fields = array( 'post', 'custom_fields' ); 
    4041        $result = $this->myxmlrpcserver->wp_getPost( array( 1, 'author', 'author', $this->post_id, $fields ) ); 
    4142        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     
    6162        $this->assertInternalType( 'string', $result['post_format'] ); 
    6263        $this->assertInternalType( 'array', $result['post_thumbnail'] ); 
     64        $this->assertInternalType( 'array', $result['custom_fields'] ); 
    6365 
    6466        // Check expected values 
     
    7173        $this->assertEquals( $this->post_data['post_content'], $result['post_content'] ); 
    7274        $this->assertEquals( url_to_postid( $result['link'] ), $this->post_id ); 
     75        $this->assertEquals( $this->post_custom_field['id'], $result['custom_fields'][0]['id'] ); 
     76        $this->assertEquals( $this->post_custom_field['key'], $result['custom_fields'][0]['key'] ); 
     77        $this->assertEquals( $this->post_custom_field['value'], $result['custom_fields'][0]['value'] ); 
    7378 
    7479        remove_theme_support( 'post-thumbnails' ); 
  • wp-testcase/test-xmlrpc-api/test_wp_getPosts.php

    r738 r739  
    1515        $this->assertInstanceOf( 'IXR_Error', $result ); 
    1616        $this->assertEquals( 401, $result->code ); 
     17 
     18        $filter = array( 'post_type' => 'page' ); 
     19        $result = $this->myxmlrpcserver->wp_getPosts( array( 1, 'subscriber', 'subscriber', $filter ) ); 
     20        $this->assertInstanceOf( 'IXR_Error', $result ); 
     21        $this->assertEquals( 401, $result->code ); 
    1722    } 
    1823 
     
    2126        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
    2227    } 
     28 
     29    function test_invalid_post_type() { 
     30        $filter = array( 'post_type' => 'invalid_post_type_name' ); 
     31        $result = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter ) ); 
     32        $this->assertInstanceOf( 'IXR_Error', $result ); 
     33    } 
     34 
     35    function test_filters() { 
     36        $cpt_name = 'test_wp_getposts_cpt'; 
     37        register_post_type( $cpt_name, array( 
     38            'taxonomies' => array( 'post_tag', 'category' ), 
     39            'public' => true 
     40        )); 
     41 
     42        $num_posts = 17; 
     43        $this->_insert_quick_posts( $num_posts, $cpt_name ); 
     44 
     45        // get them all 
     46        $filter = array( 'post_type' => $cpt_name, 'number' => $num_posts + 10 ); 
     47        $results = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter ) ); 
     48        $this->assertNotInstanceOf( 'IXR_Error', $results ); 
     49        $this->assertEquals( $num_posts, count( $results ) ); 
     50 
     51        // page through results 
     52        $posts_found = array(); 
     53        $filter['number'] = 5; 
     54        $filter['offset'] = 0; 
     55        do { 
     56            $presults = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter ) ); 
     57            foreach( $presults as $post ) { 
     58                $posts_found[] = $post['post_id']; 
     59            } 
     60            $filter['offset'] += $filter['number']; 
     61        } while ( count( $presults ) > 0 ); 
     62        // verify that $post_ids (populated by _insert_quick_posts) matches $posts_found 
     63        $this->assertEquals( 0, count( array_diff( $this->post_ids, $posts_found ) ) ); 
     64 
     65        // add comments to some of the posts 
     66        $random_posts = array_rand( $this->post_ids, $num_posts / 2 ); 
     67        foreach ( $random_posts as $i ) { 
     68            $post = $this->post_ids[$i]; 
     69            $this->_insert_quick_comments( $post, rand( 1, 20 ) ); 
     70        } 
     71 
     72        // get results ordered by comment count 
     73        $filter2 = array( 'post_type' => $cpt_name, 'number' => $num_posts, 'orderby' => 'comment_count', 'order' => 'DESC' ); 
     74        $results2 = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter2 ) ); 
     75        $this->assertNotInstanceOf( 'IXR_Error', $results2 ); 
     76        $last_comment_count = 100; 
     77        foreach ( $results2 as $post ) { 
     78            $comment_count = intval( get_comments_number( $post['post_id'] ) ); 
     79            $this->assertLessThanOrEqual( $last_comment_count, $comment_count ); 
     80            $last_comment_count = $comment_count; 
     81        } 
     82 
     83        // set one of the posts to draft and get drafts 
     84        $post = get_post( $this->post_ids[$random_posts[0]] ); 
     85        $post->post_status = 'draft'; 
     86        wp_update_post( $post ); 
     87        $filter3 = array( 'post_type' => $cpt_name, 'post_status' => 'draft' ); 
     88        $results3 = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter3 ) ); 
     89        $this->assertNotInstanceOf( 'IXR_Error', $results3 ); 
     90        $this->assertEquals( 1, count( $results3 ) ); 
     91        $this->assertEquals( $post->ID, $results3[0]['post_id'] ); 
     92    } 
     93 
     94    function test_fields() { 
     95        $this->_insert_quick_posts( 1 ); 
     96 
     97        // check default fields 
     98        $results = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor' ) ); 
     99        $this->assertNotInstanceOf( 'IXR_Error', $results ); 
     100        $expected_fields = array( 'post_id', 'post_title', 'terms', 'custom_fields', 'link' ); // subset of expected fields 
     101        foreach( $expected_fields as $field ) { 
     102            $this->assertArrayHasKey( $field, $results[0] ); 
     103        } 
     104 
     105        // request specific fields and verify that only those are returned 
     106        $filter = array(); 
     107        $fields = array( 'post_name', 'post_author', 'enclosure' ); 
     108        $results2 = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter, $fields ) ); 
     109        $this->assertNotInstanceOf( 'IXR_Error', $results2 ); 
     110        $expected_fields = array_merge( $fields, array( 'post_id' ) ); 
     111        foreach ( array_keys( $results2[0] ) as $field ) { 
     112            $this->assertContains( $field, $expected_fields ); 
     113        } 
     114    } 
    23115} 
  • wp-testcase/test-xmlrpc-api/test_wp_getTerms.php

    r732 r739  
    22 
    33class TestXMLRPCServer_wp_getTerms extends WPXMLRPCServerTestCase { 
    4     var $term; 
    5  
    6     function setUp() { 
    7         parent::setUp(); 
    8  
    9         $this->term = wp_insert_term( 'term'. rand_str() , 'category' ); 
    10     } 
    11  
    12     function tearDown() { 
    13         parent::tearDown(); 
    14  
    15         wp_delete_term( $this->term['term_id'], 'category' ); 
    16     } 
    174 
    185    function test_invalid_username_password() { 
     
    2310 
    2411    function test_empty_taxonomy() { 
    25         $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'subscriber', 'subscriber', '' ) ); 
     12        $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', '' ) ); 
    2613        $this->assertInstanceOf( 'IXR_Error', $result ); 
    2714        $this->assertEquals( 403, $result->code ); 
     
    3017 
    3118    function test_invalid_taxonomy() { 
    32         $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'subscriber', 'subscriber', 'not_existing' ) ); 
     19        $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'not_existing' ) ); 
    3320        $this->assertInstanceOf( 'IXR_Error', $result ); 
    3421        $this->assertEquals( 403, $result->code ); 
     
    4330    } 
    4431 
     32    function test_valid_terms() { 
     33        // make sure there's at least one category 
     34        $cat = wp_insert_term( 'term' . rand_str() , 'category' ); 
    4535 
    46     function test_valid_terms() { 
    47         $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'category', $this->term['term_id'] ) ); 
    48         $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     36        $results = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'category' ) ); 
     37        $this->assertNotInstanceOf( 'IXR_Error', $results ); 
    4938 
    50         foreach( $result as $term ) { 
     39        foreach( $results as $term ) { 
    5140            $this->assertInternalType( 'int', $term['count'] ); 
    5241 
     
    5746            $this->assertStringMatchesFormat( '%d', $term['parent'] ); 
    5847        } 
     48 
     49        wp_delete_term( $cat['term_id'], 'category' ); 
     50    } 
     51 
     52    function test_custom_taxonomy() { 
     53        // create a taxonomy and some terms for it 
     54        $tax_name = 'wp_getTerms_custom_taxonomy'; 
     55        $num_terms = 12; 
     56        register_taxonomy( $tax_name, 'post' ); 
     57        for( $i = 0; $i < $num_terms; $i++ ) 
     58            wp_insert_term( rand_str( 10 ), $tax_name ); 
     59 
     60 
     61        // test fetching all terms 
     62        $results = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', $tax_name ) ); 
     63        $this->assertNotInstanceOf( 'IXR_Error', $results ); 
     64 
     65        $this->assertEquals( $num_terms, count( $results ) ); 
     66        foreach ( $results as $term ) { 
     67            $this->assertEquals( $tax_name, $term['taxonomy'] ); 
     68        } 
     69 
     70        // test paged results 
     71        $filter = array( 'number' => 5 ); 
     72        $results2 = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', $tax_name, $filter ) ); 
     73        $this->assertNotInstanceOf( 'IXR_Error', $results ); 
     74        $this->assertEquals( 5, count( $results2 ) ); 
     75        $this->assertEquals( $results[1]['term_id'], $results2[1]['term_id'] ); // check one of the terms 
     76 
     77        $filter['offset'] = 10; 
     78        $results3 = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', $tax_name, $filter ) ); 
     79        $this->assertNotInstanceOf( 'IXR_Error', $results3 ); 
     80        $this->assertEquals( $num_terms - 10, count( $results3 ) ); 
     81        $this->assertEquals( $results[11]['term_id'], $results3[1]['term_id'] ); 
     82 
     83        // test hide_empty (since none have been attached to posts yet, all should be hidden 
     84        $filter = array( 'hide_empty' => true ); 
     85        $results4 = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', $tax_name, $filter ) ); 
     86        $this->assertNotInstanceOf( 'IXR_Error', $results4 ); 
     87        $this->assertEquals( 0, count( $results4 ) ); 
     88 
     89        unset($GLOBALS['wp_taxonomies'][$tax_name]); 
     90    } 
     91 
     92    function test_term_ordering() { 
     93        $cat1 = wp_create_category( 'wp.getTerms_' . rand_str( 16 ) ); 
     94        $cat2 = wp_create_category( 'wp.getTerms_' . rand_str( 16 ) ); 
     95 
     96        $this->_insert_quick_posts( 5, 'post', array( 'post_category' => array( $cat1 ) ) ); 
     97        $this->_insert_quick_posts( 3, 'post', array( 'post_category' => array( $cat2 ) ) ); 
     98 
     99        $filter = array( 'orderby' => 'count', 'order' => 'DESC' ); 
     100        $results = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'category', $filter ) ); 
     101        $this->assertNotInstanceOf( 'IXR_Error', $results ); 
     102        $this->assertNotEquals( 0, count( $results ) ); 
     103 
     104        foreach( $results as $term ) { 
     105            if ( $term['term_id'] == $cat1 ) { 
     106                break;  // found cat1 first as expected 
     107            } 
     108            else if ( $term['term_id'] == $cat2 ) { 
     109                $this->assertFalse( false, 'Incorrect category ordering.' ); 
     110            } 
     111        } 
     112 
     113        wp_delete_category( $cat1 ); 
     114        wp_delete_category( $cat2 ); 
     115    } 
     116 
     117    function test_terms_search() { 
     118        $name = rand_str( 30 ); 
     119        $name_id = wp_create_category( $name ); 
     120 
     121        // search by full name 
     122        $filter = array( 'search' => $name ); 
     123        $results = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'category', $filter ) ); 
     124        $this->assertNotInstanceOf( 'IXR_Error', $results ); 
     125        $this->assertEquals( 1, count( $results ) ); 
     126        $this->assertEquals( $name, $results[0]['name'] ); 
     127        $this->assertEquals( $name_id, $results[0]['term_id'] ); 
     128 
     129        // search by partial name 
     130        $filter = array( 'search' => substr( $name, 0, 10 ) ); 
     131        $results2 = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'category', $filter ) ); 
     132        $this->assertNotInstanceOf( 'IXR_Error', $results2 ); 
     133        $this->assertEquals( 1, count( $results2 ) ); 
     134        $this->assertEquals( $name, $results2[0]['name'] ); 
     135        $this->assertEquals( $name_id, $results2[0]['term_id'] ); 
     136 
     137        wp_delete_category( $name_id ); 
    59138    } 
    60139} 
  • wp-testcase/test-xmlrpc-api/test_wp_newPost.php

    r701 r739  
    4444    function test_incapable_publish() { 
    4545        $post = array( 'post_title' => 'Test', 'post_status' => 'publish' ); 
     46        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) ); 
     47        $this->assertInstanceOf( 'IXR_Error', $result ); 
     48        $this->assertEquals( 401, $result->code ); 
     49    } 
     50 
     51    function test_capable_private() { 
     52        $post = array( 'post_title' => 'Test', 'post_status' => 'private' ); 
     53        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 
     54        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     55    } 
     56 
     57    function test_incapable_private() { 
     58        $post = array( 'post_title' => 'Test', 'post_status' => 'private' ); 
    4659        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) ); 
    4760        $this->assertInstanceOf( 'IXR_Error', $result ); 
     
    108121    } 
    109122 
     123    function test_invalid_post_status() { 
     124        $post = array( 'post_title' => 'Test', 'post_status' => 'foobar_status' ); 
     125        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 
     126        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     127        $this->assertEquals( 'draft', get_post_status( $result ) ); 
     128    } 
     129 
     130    function test_incapable_sticky() { 
     131        $post = array( 'post_title' => 'Test', 'sticky' => true ); 
     132        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) ); 
     133        $this->assertInstanceOf( 'IXR_Error', $result ); 
     134        $this->assertEquals( 401, $result->code ); 
     135    } 
     136 
     137    function test_capable_sticky() { 
     138        $post = array( 'post_title' => 'Test', 'sticky' => true ); 
     139        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 
     140        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     141        $this->assertTrue( is_sticky( $result ) ); 
     142    } 
     143 
     144    function test_private_sticky() { 
     145        $post = array( 'post_title' => 'Test', 'post_status' => 'private', 'sticky' => true ); 
     146        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 
     147        $this->assertInstanceOf( 'IXR_Error', $result ); 
     148        $this->assertEquals( 401, $result->code ); 
     149    } 
     150 
     151    function test_post_format() { 
     152        $post = array( 'post_title' => 'Test', 'post_format' => 'quote' ); 
     153        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 
     154        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     155        $this->assertEquals( 'quote', get_post_format( $result ) ); 
     156    } 
     157 
     158    function test_invalid_post_format() { 
     159        $post = array( 'post_title' => 'Test', 'post_format' => 'tumblr' ); 
     160        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 
     161        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     162        $this->assertEquals( '', get_post_format( $result ) ); 
     163    } 
     164 
     165    function test_invalid_taxonomy() { 
     166        $post = array( 
     167            'post_title' => 'Test', 
     168            'terms' => array( 
     169                'foobar_nonexistant' => array( 1 ) 
     170            ) 
     171        ); 
     172        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 
     173        $this->assertInstanceOf( 'IXR_Error', $result ); 
     174        $this->assertEquals( 401, $result->code ); 
     175 
     176        $post2 = array( 
     177            'post_title' => 'Test', 
     178            'terms_names' => array( 
     179                'foobar_nonexistant' => array( 1 ) 
     180            ) 
     181        ); 
     182        $result2 = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post2 ) ); 
     183        $this->assertInstanceOf( 'IXR_Error', $result2 ); 
     184        $this->assertEquals( 401, $result2->code ); 
     185    } 
     186 
     187    function test_invalid_term_id() { 
     188        $post = array( 
     189            'post_title' => 'Test', 
     190            'terms' => array( 
     191                'post_tag' => array( 1390490823409 ) 
     192            ) 
     193        ); 
     194        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 
     195        $this->assertInstanceOf( 'IXR_Error', $result ); 
     196        $this->assertEquals( 403, $result->code ); 
     197    } 
     198 
     199    function test_terms() { 
     200        $tag1 = wp_create_tag ( rand_str( 30 ) ); 
     201        $tag2 = wp_create_tag ( rand_str( 30 ) ); 
     202        $tag3 = wp_create_tag ( rand_str( 30 ) ); 
     203 
     204        $post = array( 
     205            'post_title' => 'Test', 
     206            'terms' => array( 
     207                'post_tag' => array( $tag2['term_id'], $tag3['term_id'] ) 
     208            ) 
     209        ); 
     210        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 
     211        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     212 
     213        $post_tags = wp_get_object_terms( $result, 'post_tag', array( 'fields' => 'ids' ) ); 
     214        $this->assertNotContains( $tag1['term_id'], $post_tags ); 
     215        $this->assertContains( $tag2['term_id'], $post_tags ); 
     216        $this->assertContains( $tag3['term_id'], $post_tags ); 
     217    } 
     218 
     219    function test_terms_names() { 
     220        $ambiguous_name = rand_str( 30 ); 
     221        $parent_cat = wp_create_category( $ambiguous_name ); 
     222        $child_cat = wp_create_category( $ambiguous_name, $parent_cat ); 
     223 
     224        $cat1_name = rand_str( 30 ); 
     225        $cat1 = wp_create_category( $cat1_name, $parent_cat ); 
     226        $cat2_name = rand_str( 30 ); 
     227 
     228        // first a post with valid categories; one that already exists and one to be created 
     229        $post = array( 
     230            'post_title' => 'Test', 
     231            'terms_names' => array( 
     232                'category' => array( $cat1_name, $cat2_name ) 
     233            ) 
     234        ); 
     235        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 
     236        $this->assertNotInstanceOf( 'IXR_Error', $result ); 
     237        // verify that cat2 was created 
     238        $cat2 = get_term_by( 'name', $cat2_name, 'category' ); 
     239        $this->assertNotEmpty( $cat2 ); 
     240        // check that both categories were set on the post 
     241        $post_cats = wp_get_object_terms( $result, 'category', array( 'fields' => 'ids' ) ); 
     242        $this->assertContains( $cat1, $post_cats ); 
     243        $this->assertContains( $cat2->term_id, $post_cats ); 
     244 
     245        // create a second post attempting to use the ambiguous name 
     246        $post2 = array( 
     247            'post_title' => 'Test', 
     248            'terms_names' => array( 
     249                'category' => array( $cat1_name, $ambiguous_name ) 
     250            ) 
     251        ); 
     252        $result2 = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post2 ) ); 
     253        $this->assertInstanceOf( 'IXR_Error', $result2 ); 
     254        $this->assertEquals( 401, $result2->code ); 
     255 
     256        // cleanup 
     257        wp_delete_term( $child_cat, 'category' ); 
     258        wp_delete_term( $cat1, 'category' ); 
     259        wp_delete_term( $cat2->term_id, 'category' ); 
     260        wp_delete_term( $parent_cat, 'category' ); 
     261    } 
     262 
    110263} 
Note: See TracChangeset for help on using the changeset viewer.