XML-RPC: in wp_xmlrpc_server::wp_editTerm(), check ! empty when applying parent logic.

Adds unit tests.

Props hrishiv90, markoheijnen, sam2kb.
Fixes #21977.


git-svn-id: https://develop.svn.wordpress.org/trunk@34580 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2015-09-26 05:30:34 +00:00
parent 90ad5546d5
commit 881808bb11
2 changed files with 15 additions and 4 deletions

View File

@ -1934,7 +1934,7 @@ class wp_xmlrpc_server extends IXR_Server {
return new IXR_Error( 403, __( 'The term name cannot be empty.' ) );
}
if ( isset( $content_struct['parent'] ) ) {
if ( ! empty( $content_struct['parent'] ) ) {
if ( ! $taxonomy['hierarchical'] )
return new IXR_Error( 403, __( "This taxonomy is not hierarchical so you can't set a parent." ) );

View File

@ -92,9 +92,20 @@ class Tests_XMLRPC_wp_editTerm extends WP_XMLRPC_UnitTestCase {
$this->make_user_by_role( 'editor' );
$result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => '', 'name' => 'test' ) ) );
$this->assertInstanceOf( 'IXR_Error', $result );
$this->assertEquals( 500, $result->code );
$this->assertEquals( __('Empty Term'), $result->message );
$this->assertNotInstanceOf( 'IXR_Error', $result );
$this->assertTrue( $result );
}
function test_parent_null() {
$this->make_user_by_role( 'editor' );
$result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => NULL, 'name' => 'test' ) ) );
$this->assertNotInstanceOf( 'IXR_Error', $result );
$this->assertInternalType( 'boolean', $result );
$term = get_term( $this->child_term['term_id'], 'category' );
$this->assertEquals( '0', $term->parent );
}
function test_parent_invalid() {