Make WordPress Core

Ticket #54147: xmlrpc-term-names-test.diff

File xmlrpc-term-names-test.diff, 1.8 KB (added by redsweater, 4 years ago)

Unit test confirming the fix for the bug

  • tests/phpunit/tests/xmlrpc/wp/editPost.php

    From ab8bea156522bedbe334e988aca79fb6f80300b0 Mon Sep 17 00:00:00 2001
    From: Daniel Jalkut <jalkut@red-sweater.com>
    Date: Mon, 20 Sep 2021 14:40:45 -0400
    Subject: [PATCH] Confirm the fix for Ticket 54147
    
    ---
     tests/phpunit/tests/xmlrpc/wp/editPost.php | 33 ++++++++++++++++++++++
     1 file changed, 33 insertions(+)
    
    diff --git a/tests/phpunit/tests/xmlrpc/wp/editPost.php b/tests/phpunit/tests/xmlrpc/wp/editPost.php
    index a3cd49eb0f..9e42bf50e1 100644
    a b class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase { 
    528528                $after = get_post( $post_id );
    529529                $this->assertSame( '0000-00-00 00:00:00', $after->post_date_gmt );
    530530        }
     531
     532        /**
     533         * @ticket 54147
     534         */
     535        function test_tags_updated_with_empty_term_names() {
     536                $editor_id = $this->make_user_by_role( 'editor' );
     537
     538                // Create a post with a tag
     539                $post_content = array(
     540                        'post_title'   => 'Tags Removal Test',
     541                        'post_content' => 'Content',
     542                        'terms_names'      => array(
     543                                'post_tag' => array( "tag1" ),
     544                        ),
     545                );
     546
     547                $post_id = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post_content ) );
     548                $this->assertNotIXRError( $post_id );
     549
     550                $before_tags = wp_get_object_terms( $post_id, 'post_tag', array( 'fields' => 'ids' ) );
     551                $this->assertNotEmpty( $before_tags );
     552
     553                // Updating with empty terms_names should remove any existing tags
     554                $struct = array( 'terms_names' => array(
     555                                'post_tag'      => array(),
     556                        ),
     557                );
     558                $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $struct ) );
     559                $this->assertNotIXRError( $result );
     560
     561                $after_tags = wp_get_object_terms( $post_id, 'post_tag', array( 'fields' => 'ids' ) );
     562                $this->assertEmpty( $after_tags );
     563        }
    531564}