<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[739] wp-testcase/test-xmlrpc-api: XMLRPC: Added more comprehensive tests for all the 3.4 post methods and wp.getTerms.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://unit-tests.trac.wordpress.org/changeset/739">739</a></dd>
<dt>Author</dt> <dd>maxcutler</dd>
<dt>Date</dt> <dd>2012-06-16 21:53:48 +0000 (Sat, 16 Jun 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>XMLRPC: Added more comprehensive tests for all the 3.4 post methods and wp.getTerms.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#wptestcasetestxmlrpcapitest_wp_editPostphp">wp-testcase/test-xmlrpc-api/test_wp_editPost.php</a></li>
<li><a href="#wptestcasetestxmlrpcapitest_wp_getPostphp">wp-testcase/test-xmlrpc-api/test_wp_getPost.php</a></li>
<li><a href="#wptestcasetestxmlrpcapitest_wp_getPostsphp">wp-testcase/test-xmlrpc-api/test_wp_getPosts.php</a></li>
<li><a href="#wptestcasetestxmlrpcapitest_wp_getTermsphp">wp-testcase/test-xmlrpc-api/test_wp_getTerms.php</a></li>
<li><a href="#wptestcasetestxmlrpcapitest_wp_newPostphp">wp-testcase/test-xmlrpc-api/test_wp_newPost.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#wptestcasetestxmlrpcapitest_wp_deletePostphp">wp-testcase/test-xmlrpc-api/test_wp_deletePost.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="wptestcasetestxmlrpcapitest_wp_deletePostphp"></a>
<div class="addfile"><h4>Added: wp-testcase/test-xmlrpc-api/test_wp_deletePost.php (0 => 739)</h4>
<pre class="diff"><span>
<span class="info">--- wp-testcase/test-xmlrpc-api/test_wp_deletePost.php                                (rev 0)
+++ wp-testcase/test-xmlrpc-api/test_wp_deletePost.php        2012-06-16 21:53:48 UTC (rev 739)
</span><span class="lines">@@ -0,0 +1,41 @@
</span><ins>+&lt;?php
+
+class TestXMLRPCServer_wp_deletePost extends WPXMLRPCServerTestCase {
+
+        function test_invalid_username_password() {
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_deletePost( array( 1, 'username', 'password', 0 ) );
+                $this-&gt;assertInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertEquals( 403, $result-&gt;code );
+        }
+
+        function test_invalid_post() {
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_deletePost( array( 1, 'editor', 'editor', 0 ) );
+                $this-&gt;assertInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertEquals( 404, $result-&gt;code );
+        }
+
+        function test_incapable_user() {
+                $this-&gt;_insert_quick_posts( 1 );
+                $post_id = array_pop( $this-&gt;post_ids );
+
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_deletePost( array( 1, 'subscriber', 'subscriber', $post_id ) );
+                $this-&gt;assertInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertEquals( 401, $result-&gt;code );
+
+                wp_delete_post( $post_id, true );
+        }
+
+        function test_post_deleted() {
+                $this-&gt;_insert_quick_posts( 1 );
+                $post_id = array_pop( $this-&gt;post_ids );
+
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_deletePost( array( 1, 'editor', 'editor', $post_id ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertTrue( $result );
+
+                $post = get_post( $post_id );
+                $this-&gt;assertEquals( 'trash', $post-&gt;post_status );
+
+                wp_delete_post( $post_id, true );
+        }
+}
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="wptestcasetestxmlrpcapitest_wp_editPostphp"></a>
<div class="modfile"><h4>Modified: wp-testcase/test-xmlrpc-api/test_wp_editPost.php (738 => 739)</h4>
<pre class="diff"><span>
<span class="info">--- wp-testcase/test-xmlrpc-api/test_wp_editPost.php        2012-06-16 18:21:01 UTC (rev 738)
+++ wp-testcase/test-xmlrpc-api/test_wp_editPost.php        2012-06-16 21:53:48 UTC (rev 739)
</span><span class="lines">@@ -109,13 +109,20 @@
</span><span class="cx"> 
</span><span class="cx">                 // add post thumbnail to post that does not have one
</span><span class="cx">                 $post2 = array( 'post_thumbnail' =&gt; $attachment_id );
</span><del>-                $result = $this-&gt;myxmlrpcserver-&gt;wp_editPost( array(1, 'author', 'author', $post_id, $post2 ) );
</del><ins>+                $result = $this-&gt;myxmlrpcserver-&gt;wp_editPost( array( 1, 'author', 'author', $post_id, $post2 ) );
</ins><span class="cx">                 $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
</span><span class="cx">                 $this-&gt;assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) );
</span><span class="cx"> 
</span><ins>+                // fetch the post to verify that it appears
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_getPost( array( 1, 'author', 'author', $post_id ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertArrayHasKey( 'post_thumbnail', $result );
+                $this-&gt;assertInternalType( 'array', $result['post_thumbnail'] );
+                $this-&gt;assertEquals( $attachment_id, $result['post_thumbnail']['attachment_id'] );
+
</ins><span class="cx">                 // edit the post without supplying a post_thumbnail and check that it didn't change
</span><span class="cx">                 $post3 = array( 'post_content' =&gt; 'Updated post' );
</span><del>-                $result = $this-&gt;myxmlrpcserver-&gt;wp_editPost( array(1, 'author', 'author', $post_id, $post3 ) );
</del><ins>+                $result = $this-&gt;myxmlrpcserver-&gt;wp_editPost( array( 1, 'author', 'author', $post_id, $post3 ) );
</ins><span class="cx">                 $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
</span><span class="cx">                 $this-&gt;assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) );
</span><span class="cx"> 
</span><span class="lines">@@ -125,16 +132,22 @@
</span><span class="cx"> 
</span><span class="cx">                 // change the post's post_thumbnail
</span><span class="cx">                 $post4 = array( 'post_thumbnail' =&gt; $attachment2_id );
</span><del>-                $result = $this-&gt;myxmlrpcserver-&gt;wp_editPost( array(1, 'author', 'author', $post_id, $post4 ) );
</del><ins>+                $result = $this-&gt;myxmlrpcserver-&gt;wp_editPost( array( 1, 'author', 'author', $post_id, $post4 ) );
</ins><span class="cx">                 $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
</span><span class="cx">                 $this-&gt;assertEquals( $attachment2_id, get_post_meta( $post_id, '_thumbnail_id', true ) );
</span><span class="cx"> 
</span><span class="cx">                 // unset the post's post_thumbnail
</span><span class="cx">                 $post5 = array( 'post_thumbnail' =&gt; '' );
</span><del>-                $result = $this-&gt;myxmlrpcserver-&gt;wp_editPost( array(1, 'author', 'author', $post_id, $post5 ) );
</del><ins>+                $result = $this-&gt;myxmlrpcserver-&gt;wp_editPost( array( 1, 'author', 'author', $post_id, $post5 ) );
</ins><span class="cx">                 $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
</span><span class="cx">                 $this-&gt;assertEquals( '', get_post_meta( $post_id, '_thumbnail_id', true ) );
</span><span class="cx"> 
</span><ins>+                // use invalid ID
+                $post6 = array( 'post_thumbnail' =&gt; 398420983409 );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_editPost( array( 1, 'author', 'author', $post_id, $post6 ) );
+                $this-&gt;assertInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertEquals( 404, $result-&gt;code );
+
</ins><span class="cx">                 remove_theme_support( 'post-thumbnails' );
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -152,6 +165,7 @@
</span><span class="cx">                                 array(
</span><span class="cx">                                         array( 'id' =&gt; $mid_delete ),
</span><span class="cx">                                         array( 'id' =&gt; $mid_edit, 'key' =&gt; 'custom_field_key', 'value' =&gt; '87654321' ),
</span><ins>+                                        array( 'key' =&gt; 'custom_field_to_create', 'value' =&gt; '12345678' )
</ins><span class="cx">                                 )
</span><span class="cx">                 );
</span><span class="cx"> 
</span><span class="lines">@@ -165,6 +179,38 @@
</span><span class="cx">                 $edited_object = get_metadata_by_mid( 'post', $mid_edit );
</span><span class="cx">                 $this-&gt;assertEquals( '87654321', $edited_object-&gt;meta_value );
</span><span class="cx">                 $this-&gt;assertFalse( get_metadata_by_mid( 'post', $mid_delete ) );
</span><ins>+
+                $created_object = get_post_meta( $post_id, 'custom_field_to_create', true );
+                $this-&gt;assertEquals( $created_object, '12345678' );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        function test_capable_unsticky() {
+                $this-&gt;author = get_user_by( 'login', 'editor' );
+                $this-&gt;_insert_quick_posts( 1 );
+                $post_id = array_pop( $this-&gt;post_ids );
+                stick_post( $post_id );
+
+                $post2 = array( 'sticky' =&gt; false );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertFalse( is_sticky( $post_id ) );
+
+                wp_delete_post( $post_id, true );
+        }
+
+        function test_password_transition_unsticky() {
+                // when transitioning to private status or adding a post password, post should be un-stuck
+                $this-&gt;author = get_user_by( 'login', 'editor' );
+                $this-&gt;_insert_quick_posts( 1 );
+                $post_id = array_pop( $this-&gt;post_ids );
+                stick_post( $post_id );
+
+                $post2 = array( 'post_password' =&gt; 'foobar',  'sticky' =&gt; false );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertFalse( is_sticky( $post_id ) );
+
+                wp_delete_post( $post_id, true );
+        }
+
</ins><span class="cx"> }
</span></span></pre></div>
<a id="wptestcasetestxmlrpcapitest_wp_getPostphp"></a>
<div class="modfile"><h4>Modified: wp-testcase/test-xmlrpc-api/test_wp_getPost.php (738 => 739)</h4>
<pre class="diff"><span>
<span class="info">--- wp-testcase/test-xmlrpc-api/test_wp_getPost.php        2012-06-16 18:21:01 UTC (rev 738)
+++ wp-testcase/test-xmlrpc-api/test_wp_getPost.php        2012-06-16 21:53:48 UTC (rev 739)
</span><span class="lines">@@ -1,11 +1,10 @@
</span><span class="cx"> &lt;?php
</span><span class="cx"> 
</span><del>-include_once(ABSPATH . WPINC . '/post-thumbnail-template.php'); 
-
</del><span class="cx"> class TestXMLRPCServer_wp_getPost extends WPXMLRPCServerTestCase {
</span><span class="cx">         var $post_data;
</span><span class="cx">         var $post_id;
</span><span class="cx">         var $post_date_ts;
</span><ins>+        var $post_custom_field;
</ins><span class="cx"> 
</span><span class="cx">         function setUp() {
</span><span class="cx">                 parent::setUp();
</span><span class="lines">@@ -19,6 +18,8 @@
</span><span class="cx">                         'post_date'  =&gt; strftime( &quot;%Y-%m-%d %H:%M:%S&quot;, $this-&gt;post_date_ts ),
</span><span class="cx">                 );
</span><span class="cx">                 $this-&gt;post_id = wp_insert_post( $this-&gt;post_data );
</span><ins>+                $this-&gt;post_custom_field = array( 'key' =&gt; 'test_custom_field', 'value' =&gt; 12345678);
+                $this-&gt;post_custom_field['id'] = add_post_meta( $this-&gt;post_id, $this-&gt;post_custom_field['key'], $this-&gt;post_custom_field['value'] );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function tearDown() {
</span><span class="lines">@@ -36,7 +37,7 @@
</span><span class="cx">         function test_valid_post() {
</span><span class="cx">                 add_theme_support( 'post-thumbnails' );
</span><span class="cx"> 
</span><del>-                $fields = array( 'post' );
</del><ins>+                $fields = array( 'post', 'custom_fields' );
</ins><span class="cx">                 $result = $this-&gt;myxmlrpcserver-&gt;wp_getPost( array( 1, 'author', 'author', $this-&gt;post_id, $fields ) );
</span><span class="cx">                 $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
</span><span class="cx"> 
</span><span class="lines">@@ -60,6 +61,7 @@
</span><span class="cx">                 $this-&gt;assertInternalType( 'bool', $result['sticky'] );
</span><span class="cx">                 $this-&gt;assertInternalType( 'string', $result['post_format'] );
</span><span class="cx">                 $this-&gt;assertInternalType( 'array', $result['post_thumbnail'] );
</span><ins>+                $this-&gt;assertInternalType( 'array', $result['custom_fields'] );
</ins><span class="cx"> 
</span><span class="cx">                 // Check expected values
</span><span class="cx">                 $this-&gt;assertStringMatchesFormat( '%d', $result['post_id'] );
</span><span class="lines">@@ -70,6 +72,9 @@
</span><span class="cx">                 $this-&gt;assertEquals( $this-&gt;post_data['post_excerpt'], $result['post_excerpt'] );
</span><span class="cx">                 $this-&gt;assertEquals( $this-&gt;post_data['post_content'], $result['post_content'] );
</span><span class="cx">                 $this-&gt;assertEquals( url_to_postid( $result['link'] ), $this-&gt;post_id );
</span><ins>+                $this-&gt;assertEquals( $this-&gt;post_custom_field['id'], $result['custom_fields'][0]['id'] );
+                $this-&gt;assertEquals( $this-&gt;post_custom_field['key'], $result['custom_fields'][0]['key'] );
+                $this-&gt;assertEquals( $this-&gt;post_custom_field['value'], $result['custom_fields'][0]['value'] );
</ins><span class="cx"> 
</span><span class="cx">                 remove_theme_support( 'post-thumbnails' );
</span><span class="cx">         }
</span></span></pre></div>
<a id="wptestcasetestxmlrpcapitest_wp_getPostsphp"></a>
<div class="modfile"><h4>Modified: wp-testcase/test-xmlrpc-api/test_wp_getPosts.php (738 => 739)</h4>
<pre class="diff"><span>
<span class="info">--- wp-testcase/test-xmlrpc-api/test_wp_getPosts.php        2012-06-16 18:21:01 UTC (rev 738)
+++ wp-testcase/test-xmlrpc-api/test_wp_getPosts.php        2012-06-16 21:53:48 UTC (rev 739)
</span><span class="lines">@@ -14,10 +14,102 @@
</span><span class="cx">                 $result = $this-&gt;myxmlrpcserver-&gt;wp_getPosts( array( 1, 'subscriber', 'subscriber' ) );
</span><span class="cx">                 $this-&gt;assertInstanceOf( 'IXR_Error', $result );
</span><span class="cx">                 $this-&gt;assertEquals( 401, $result-&gt;code );
</span><ins>+
+                $filter = array( 'post_type' =&gt; 'page' );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_getPosts( array( 1, 'subscriber', 'subscriber', $filter ) );
+                $this-&gt;assertInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertEquals( 401, $result-&gt;code );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function test_capable_user() {
</span><span class="cx">                 $result = $this-&gt;myxmlrpcserver-&gt;wp_getPosts( array( 1, 'editor', 'editor' ) );
</span><span class="cx">                 $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
</span><span class="cx">         }
</span><ins>+
+        function test_invalid_post_type() {
+                $filter = array( 'post_type' =&gt; 'invalid_post_type_name' );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_getPosts( array( 1, 'editor', 'editor', $filter ) );
+                $this-&gt;assertInstanceOf( 'IXR_Error', $result );
+        }
+
+        function test_filters() {
+                $cpt_name = 'test_wp_getposts_cpt';
+                register_post_type( $cpt_name, array(
+                        'taxonomies' =&gt; array( 'post_tag', 'category' ),
+                        'public' =&gt; true
+                ));
+
+                $num_posts = 17;
+                $this-&gt;_insert_quick_posts( $num_posts, $cpt_name );
+
+                // get them all
+                $filter = array( 'post_type' =&gt; $cpt_name, 'number' =&gt; $num_posts + 10 );
+                $results = $this-&gt;myxmlrpcserver-&gt;wp_getPosts( array( 1, 'editor', 'editor', $filter ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $results );
+                $this-&gt;assertEquals( $num_posts, count( $results ) );
+
+                // page through results
+                $posts_found = array();
+                $filter['number'] = 5;
+                $filter['offset'] = 0;
+                do {
+                        $presults = $this-&gt;myxmlrpcserver-&gt;wp_getPosts( array( 1, 'editor', 'editor', $filter ) );
+                        foreach( $presults as $post ) {
+                                $posts_found[] = $post['post_id'];
+                        }
+                        $filter['offset'] += $filter['number'];
+                } while ( count( $presults ) &gt; 0 );
+                // verify that $post_ids (populated by _insert_quick_posts) matches $posts_found
+                $this-&gt;assertEquals( 0, count( array_diff( $this-&gt;post_ids, $posts_found ) ) );
+
+                // add comments to some of the posts
+                $random_posts = array_rand( $this-&gt;post_ids, $num_posts / 2 );
+                foreach ( $random_posts as $i ) {
+                        $post = $this-&gt;post_ids[$i];
+                        $this-&gt;_insert_quick_comments( $post, rand( 1, 20 ) );
+                }
+
+                // get results ordered by comment count
+                $filter2 = array( 'post_type' =&gt; $cpt_name, 'number' =&gt; $num_posts, 'orderby' =&gt; 'comment_count', 'order' =&gt; 'DESC' );
+                $results2 = $this-&gt;myxmlrpcserver-&gt;wp_getPosts( array( 1, 'editor', 'editor', $filter2 ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $results2 );
+                $last_comment_count = 100;
+                foreach ( $results2 as $post ) {
+                        $comment_count = intval( get_comments_number( $post['post_id'] ) );
+                        $this-&gt;assertLessThanOrEqual( $last_comment_count, $comment_count );
+                        $last_comment_count = $comment_count;
+                }
+
+                // set one of the posts to draft and get drafts
+                $post = get_post( $this-&gt;post_ids[$random_posts[0]] );
+                $post-&gt;post_status = 'draft';
+                wp_update_post( $post );
+                $filter3 = array( 'post_type' =&gt; $cpt_name, 'post_status' =&gt; 'draft' );
+                $results3 = $this-&gt;myxmlrpcserver-&gt;wp_getPosts( array( 1, 'editor', 'editor', $filter3 ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $results3 );
+                $this-&gt;assertEquals( 1, count( $results3 ) );
+                $this-&gt;assertEquals( $post-&gt;ID, $results3[0]['post_id'] );
+        }
+
+        function test_fields() {
+                $this-&gt;_insert_quick_posts( 1 );
+
+                // check default fields
+                $results = $this-&gt;myxmlrpcserver-&gt;wp_getPosts( array( 1, 'editor', 'editor' ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $results );
+                $expected_fields = array( 'post_id', 'post_title', 'terms', 'custom_fields', 'link' ); // subset of expected fields
+                foreach( $expected_fields as $field ) {
+                        $this-&gt;assertArrayHasKey( $field, $results[0] );
+                }
+
+                // request specific fields and verify that only those are returned
+                $filter = array();
+                $fields = array( 'post_name', 'post_author', 'enclosure' );
+                $results2 = $this-&gt;myxmlrpcserver-&gt;wp_getPosts( array( 1, 'editor', 'editor', $filter, $fields ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $results2 );
+                $expected_fields = array_merge( $fields, array( 'post_id' ) );
+                foreach ( array_keys( $results2[0] ) as $field ) {
+                        $this-&gt;assertContains( $field, $expected_fields );
+                }
+        }
</ins><span class="cx"> }
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="wptestcasetestxmlrpcapitest_wp_getTermsphp"></a>
<div class="modfile"><h4>Modified: wp-testcase/test-xmlrpc-api/test_wp_getTerms.php (738 => 739)</h4>
<pre class="diff"><span>
<span class="info">--- wp-testcase/test-xmlrpc-api/test_wp_getTerms.php        2012-06-16 18:21:01 UTC (rev 738)
+++ wp-testcase/test-xmlrpc-api/test_wp_getTerms.php        2012-06-16 21:53:48 UTC (rev 739)
</span><span class="lines">@@ -1,20 +1,7 @@
</span><span class="cx"> &lt;?php
</span><span class="cx"> 
</span><span class="cx"> class TestXMLRPCServer_wp_getTerms extends WPXMLRPCServerTestCase {
</span><del>-        var $term;
</del><span class="cx"> 
</span><del>-        function setUp() {
-                parent::setUp();
-
-                $this-&gt;term = wp_insert_term( 'term'. rand_str() , 'category' );
-        }
-
-        function tearDown() {
-                parent::tearDown();
-
-                wp_delete_term( $this-&gt;term['term_id'], 'category' );
-        }
-
</del><span class="cx">         function test_invalid_username_password() {
</span><span class="cx">                 $result = $this-&gt;myxmlrpcserver-&gt;wp_getTerms( array( 1, 'username', 'password', 'category' ) );
</span><span class="cx">                 $this-&gt;assertInstanceOf( 'IXR_Error', $result );
</span><span class="lines">@@ -22,14 +9,14 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function test_empty_taxonomy() {
</span><del>-                $result = $this-&gt;myxmlrpcserver-&gt;wp_getTerms( array( 1, 'subscriber', 'subscriber', '' ) );
</del><ins>+                $result = $this-&gt;myxmlrpcserver-&gt;wp_getTerms( array( 1, 'editor', 'editor', '' ) );
</ins><span class="cx">                 $this-&gt;assertInstanceOf( 'IXR_Error', $result );
</span><span class="cx">                 $this-&gt;assertEquals( 403, $result-&gt;code );
</span><span class="cx">                 $this-&gt;assertEquals( __( 'Invalid taxonomy' ), $result-&gt;message );
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function test_invalid_taxonomy() {
</span><del>-                $result = $this-&gt;myxmlrpcserver-&gt;wp_getTerms( array( 1, 'subscriber', 'subscriber', 'not_existing' ) );
</del><ins>+                $result = $this-&gt;myxmlrpcserver-&gt;wp_getTerms( array( 1, 'editor', 'editor', 'not_existing' ) );
</ins><span class="cx">                 $this-&gt;assertInstanceOf( 'IXR_Error', $result );
</span><span class="cx">                 $this-&gt;assertEquals( 403, $result-&gt;code );
</span><span class="cx">                 $this-&gt;assertEquals( __( 'Invalid taxonomy' ), $result-&gt;message );
</span><span class="lines">@@ -42,12 +29,14 @@
</span><span class="cx">                 $this-&gt;assertEquals( __( 'You are not allowed to assign terms in this taxonomy.' ), $result-&gt;message );
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-
</del><span class="cx">         function test_valid_terms() {
</span><del>-                $result = $this-&gt;myxmlrpcserver-&gt;wp_getTerms( array( 1, 'editor', 'editor', 'category', $this-&gt;term['term_id'] ) );
-                $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
</del><ins>+                // make sure there's at least one category
+                $cat = wp_insert_term( 'term' . rand_str() , 'category' );
</ins><span class="cx"> 
</span><del>-                foreach( $result as $term ) {
</del><ins>+                $results = $this-&gt;myxmlrpcserver-&gt;wp_getTerms( array( 1, 'editor', 'editor', 'category' ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $results );
+
+                foreach( $results as $term ) {
</ins><span class="cx">                         $this-&gt;assertInternalType( 'int', $term['count'] );
</span><span class="cx"> 
</span><span class="cx">                         // We expect all other IDs to be strings not integers so we don't return something larger than an XMLRPC integer can describe.
</span><span class="lines">@@ -56,5 +45,95 @@
</span><span class="cx">                         $this-&gt;assertStringMatchesFormat( '%d', $term['term_taxonomy_id'] );
</span><span class="cx">                         $this-&gt;assertStringMatchesFormat( '%d', $term['parent'] );
</span><span class="cx">                 }
</span><ins>+
+                wp_delete_term( $cat['term_id'], 'category' );
</ins><span class="cx">         }
</span><ins>+
+        function test_custom_taxonomy() {
+                // create a taxonomy and some terms for it
+                $tax_name = 'wp_getTerms_custom_taxonomy';
+                $num_terms = 12;
+                register_taxonomy( $tax_name, 'post' );
+                for( $i = 0; $i &lt; $num_terms; $i++ )
+                        wp_insert_term( rand_str( 10 ), $tax_name );
+
+
+                // test fetching all terms
+                $results = $this-&gt;myxmlrpcserver-&gt;wp_getTerms( array( 1, 'editor', 'editor', $tax_name ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $results );
+
+                $this-&gt;assertEquals( $num_terms, count( $results ) );
+                foreach ( $results as $term ) {
+                        $this-&gt;assertEquals( $tax_name, $term['taxonomy'] );
+                }
+
+                // test paged results
+                $filter = array( 'number' =&gt; 5 );
+                $results2 = $this-&gt;myxmlrpcserver-&gt;wp_getTerms( array( 1, 'editor', 'editor', $tax_name, $filter ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $results );
+                $this-&gt;assertEquals( 5, count( $results2 ) );
+                $this-&gt;assertEquals( $results[1]['term_id'], $results2[1]['term_id'] ); // check one of the terms
+
+                $filter['offset'] = 10;
+                $results3 = $this-&gt;myxmlrpcserver-&gt;wp_getTerms( array( 1, 'editor', 'editor', $tax_name, $filter ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $results3 );
+                $this-&gt;assertEquals( $num_terms - 10, count( $results3 ) );
+                $this-&gt;assertEquals( $results[11]['term_id'], $results3[1]['term_id'] );
+
+                // test hide_empty (since none have been attached to posts yet, all should be hidden
+                $filter = array( 'hide_empty' =&gt; true );
+                $results4 = $this-&gt;myxmlrpcserver-&gt;wp_getTerms( array( 1, 'editor', 'editor', $tax_name, $filter ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $results4 );
+                $this-&gt;assertEquals( 0, count( $results4 ) );
+
+                unset($GLOBALS['wp_taxonomies'][$tax_name]);
+        }
+
+        function test_term_ordering() {
+                $cat1 = wp_create_category( 'wp.getTerms_' . rand_str( 16 ) );
+                $cat2 = wp_create_category( 'wp.getTerms_' . rand_str( 16 ) );
+
+                $this-&gt;_insert_quick_posts( 5, 'post', array( 'post_category' =&gt; array( $cat1 ) ) );
+                $this-&gt;_insert_quick_posts( 3, 'post', array( 'post_category' =&gt; array( $cat2 ) ) );
+
+                $filter = array( 'orderby' =&gt; 'count', 'order' =&gt; 'DESC' );
+                $results = $this-&gt;myxmlrpcserver-&gt;wp_getTerms( array( 1, 'editor', 'editor', 'category', $filter ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $results );
+                $this-&gt;assertNotEquals( 0, count( $results ) );
+
+                foreach( $results as $term ) {
+                        if ( $term['term_id'] == $cat1 ) {
+                                break;  // found cat1 first as expected
+                        }
+                        else if ( $term['term_id'] == $cat2 ) {
+                                $this-&gt;assertFalse( false, 'Incorrect category ordering.' );
+                        }
+                }
+
+                wp_delete_category( $cat1 );
+                wp_delete_category( $cat2 );
+        }
+
+        function test_terms_search() {
+                $name = rand_str( 30 );
+                $name_id = wp_create_category( $name );
+
+                // search by full name
+                $filter = array( 'search' =&gt; $name );
+                $results = $this-&gt;myxmlrpcserver-&gt;wp_getTerms( array( 1, 'editor', 'editor', 'category', $filter ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $results );
+                $this-&gt;assertEquals( 1, count( $results ) );
+                $this-&gt;assertEquals( $name, $results[0]['name'] );
+                $this-&gt;assertEquals( $name_id, $results[0]['term_id'] );
+
+                // search by partial name
+                $filter = array( 'search' =&gt; substr( $name, 0, 10 ) );
+                $results2 = $this-&gt;myxmlrpcserver-&gt;wp_getTerms( array( 1, 'editor', 'editor', 'category', $filter ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $results2 );
+                $this-&gt;assertEquals( 1, count( $results2 ) );
+                $this-&gt;assertEquals( $name, $results2[0]['name'] );
+                $this-&gt;assertEquals( $name_id, $results2[0]['term_id'] );
+
+                wp_delete_category( $name_id );
+        }
</ins><span class="cx"> }
</span></span></pre></div>
<a id="wptestcasetestxmlrpcapitest_wp_newPostphp"></a>
<div class="modfile"><h4>Modified: wp-testcase/test-xmlrpc-api/test_wp_newPost.php (738 => 739)</h4>
<pre class="diff"><span>
<span class="info">--- wp-testcase/test-xmlrpc-api/test_wp_newPost.php        2012-06-16 18:21:01 UTC (rev 738)
+++ wp-testcase/test-xmlrpc-api/test_wp_newPost.php        2012-06-16 21:53:48 UTC (rev 739)
</span><span class="lines">@@ -48,6 +48,19 @@
</span><span class="cx">                 $this-&gt;assertEquals( 401, $result-&gt;code );
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        function test_capable_private() {
+                $post = array( 'post_title' =&gt; 'Test', 'post_status' =&gt; 'private' );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_newPost( array( 1, 'editor', 'editor', $post ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
+        }
+
+        function test_incapable_private() {
+                $post = array( 'post_title' =&gt; 'Test', 'post_status' =&gt; 'private' );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_newPost( array( 1, 'contributor', 'contributor', $post ) );
+                $this-&gt;assertInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertEquals( 401, $result-&gt;code );
+        }
+
</ins><span class="cx">         function test_capable_other_author() {
</span><span class="cx">                 $other_author_id = get_user_by( 'login', 'author' )-&gt;ID;
</span><span class="cx">                 $post = array( 'post_title' =&gt; 'Test', 'post_author' =&gt; $other_author_id );
</span><span class="lines">@@ -107,4 +120,144 @@
</span><span class="cx">                 remove_theme_support( 'post-thumbnails' );
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        function test_invalid_post_status() {
+                $post = array( 'post_title' =&gt; 'Test', 'post_status' =&gt; 'foobar_status' );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_newPost( array( 1, 'author', 'author', $post ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertEquals( 'draft', get_post_status( $result ) );
+        }
+
+        function test_incapable_sticky() {
+                $post = array( 'post_title' =&gt; 'Test', 'sticky' =&gt; true );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_newPost( array( 1, 'contributor', 'contributor', $post ) );
+                $this-&gt;assertInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertEquals( 401, $result-&gt;code );
+        }
+
+        function test_capable_sticky() {
+                $post = array( 'post_title' =&gt; 'Test', 'sticky' =&gt; true );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_newPost( array( 1, 'editor', 'editor', $post ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertTrue( is_sticky( $result ) );
+        }
+
+        function test_private_sticky() {
+                $post = array( 'post_title' =&gt; 'Test', 'post_status' =&gt; 'private', 'sticky' =&gt; true );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_newPost( array( 1, 'editor', 'editor', $post ) );
+                $this-&gt;assertInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertEquals( 401, $result-&gt;code );
+        }
+
+        function test_post_format() {
+                $post = array( 'post_title' =&gt; 'Test', 'post_format' =&gt; 'quote' );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_newPost( array( 1, 'editor', 'editor', $post ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertEquals( 'quote', get_post_format( $result ) );
+        }
+
+        function test_invalid_post_format() {
+                $post = array( 'post_title' =&gt; 'Test', 'post_format' =&gt; 'tumblr' );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_newPost( array( 1, 'editor', 'editor', $post ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertEquals( '', get_post_format( $result ) );
+        }
+
+        function test_invalid_taxonomy() {
+                $post = array(
+                        'post_title' =&gt; 'Test',
+                        'terms' =&gt; array(
+                                'foobar_nonexistant' =&gt; array( 1 )
+                        )
+                );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_newPost( array( 1, 'editor', 'editor', $post ) );
+                $this-&gt;assertInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertEquals( 401, $result-&gt;code );
+
+                $post2 = array(
+                        'post_title' =&gt; 'Test',
+                        'terms_names' =&gt; array(
+                                'foobar_nonexistant' =&gt; array( 1 )
+                        )
+                );
+                $result2 = $this-&gt;myxmlrpcserver-&gt;wp_newPost( array( 1, 'editor', 'editor', $post2 ) );
+                $this-&gt;assertInstanceOf( 'IXR_Error', $result2 );
+                $this-&gt;assertEquals( 401, $result2-&gt;code );
+        }
+
+        function test_invalid_term_id() {
+                $post = array(
+                        'post_title' =&gt; 'Test',
+                        'terms' =&gt; array(
+                                'post_tag' =&gt; array( 1390490823409 )
+                        )
+                );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_newPost( array( 1, 'editor', 'editor', $post ) );
+                $this-&gt;assertInstanceOf( 'IXR_Error', $result );
+                $this-&gt;assertEquals( 403, $result-&gt;code );
+        }
+
+        function test_terms() {
+                $tag1 = wp_create_tag ( rand_str( 30 ) );
+                $tag2 = wp_create_tag ( rand_str( 30 ) );
+                $tag3 = wp_create_tag ( rand_str( 30 ) );
+
+                $post = array(
+                        'post_title' =&gt; 'Test',
+                        'terms' =&gt; array(
+                                'post_tag' =&gt; array( $tag2['term_id'], $tag3['term_id'] )
+                        )
+                );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_newPost( array( 1, 'editor', 'editor', $post ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
+
+                $post_tags = wp_get_object_terms( $result, 'post_tag', array( 'fields' =&gt; 'ids' ) );
+                $this-&gt;assertNotContains( $tag1['term_id'], $post_tags );
+                $this-&gt;assertContains( $tag2['term_id'], $post_tags );
+                $this-&gt;assertContains( $tag3['term_id'], $post_tags );
+        }
+
+        function test_terms_names() {
+                $ambiguous_name = rand_str( 30 );
+                $parent_cat = wp_create_category( $ambiguous_name );
+                $child_cat = wp_create_category( $ambiguous_name, $parent_cat );
+
+                $cat1_name = rand_str( 30 );
+                $cat1 = wp_create_category( $cat1_name, $parent_cat );
+                $cat2_name = rand_str( 30 );
+
+                // first a post with valid categories; one that already exists and one to be created
+                $post = array(
+                        'post_title' =&gt; 'Test',
+                        'terms_names' =&gt; array(
+                                'category' =&gt; array( $cat1_name, $cat2_name )
+                        )
+                );
+                $result = $this-&gt;myxmlrpcserver-&gt;wp_newPost( array( 1, 'editor', 'editor', $post ) );
+                $this-&gt;assertNotInstanceOf( 'IXR_Error', $result );
+                // verify that cat2 was created
+                $cat2 = get_term_by( 'name', $cat2_name, 'category' );
+                $this-&gt;assertNotEmpty( $cat2 );
+                // check that both categories were set on the post
+                $post_cats = wp_get_object_terms( $result, 'category', array( 'fields' =&gt; 'ids' ) );
+                $this-&gt;assertContains( $cat1, $post_cats );
+                $this-&gt;assertContains( $cat2-&gt;term_id, $post_cats );
+
+                // create a second post attempting to use the ambiguous name
+                $post2 = array(
+                        'post_title' =&gt; 'Test',
+                        'terms_names' =&gt; array(
+                                'category' =&gt; array( $cat1_name, $ambiguous_name )
+                        )
+                );
+                $result2 = $this-&gt;myxmlrpcserver-&gt;wp_newPost( array( 1, 'editor', 'editor', $post2 ) );
+                $this-&gt;assertInstanceOf( 'IXR_Error', $result2 );
+                $this-&gt;assertEquals( 401, $result2-&gt;code );
+
+                // cleanup
+                wp_delete_term( $child_cat, 'category' );
+                wp_delete_term( $cat1, 'category' );
+                wp_delete_term( $cat2-&gt;term_id, 'category' );
+                wp_delete_term( $parent_cat, 'category' );
+        }
+
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>