@@ -616,6 +616,37 @@ public function test_create_item_parent_non_hierarchical_taxonomy() {
616
616
$ this ->assertErrorResponse ( 'rest_taxonomy_not_hierarchical ' , $ response , 400 );
617
617
}
618
618
619
+ public function test_create_item_with_meta () {
620
+ wp_set_current_user ( self ::$ administrator );
621
+ $ request = new WP_REST_Request ( 'POST ' , '/wp/v2/tags ' );
622
+ $ request ->set_param ( 'name ' , 'My Awesome Term ' );
623
+ $ request ->set_param ( 'meta ' , array ( 'test_tag_single ' => 'hello ' ) );
624
+ $ response = rest_get_server ()->dispatch ( $ request );
625
+ $ this ->assertEquals ( 201 , $ response ->get_status () );
626
+ $ headers = $ response ->get_headers ();
627
+ $ data = $ response ->get_data ();
628
+ $ this ->assertContains ( '/wp/v2/tags/ ' . $ data ['id ' ], $ headers ['Location ' ] );
629
+ $ this ->assertEquals ( 'My Awesome Term ' , $ data ['name ' ] );
630
+ $ this ->assertEquals ( 'hello ' , get_term_meta ( $ data ['id ' ], 'test_tag_single ' , true ) );
631
+ }
632
+
633
+ public function test_create_item_with_meta_wrong_id () {
634
+ wp_set_current_user ( self ::$ administrator );
635
+ $ existing_tag_id = $ this ->factory ->tag ->create ( array ( 'name ' => 'My Not So Awesome Term ' ) );
636
+ $ request = new WP_REST_Request ( 'POST ' , '/wp/v2/tags ' );
637
+ $ request ->set_param ( 'name ' , 'My Awesome Term ' );
638
+ $ request ->set_param ( 'meta ' , array ( 'test_tag_single ' => 'hello ' ) );
639
+ $ request ->set_param ( 'id ' , $ existing_tag_id );
640
+ $ response = rest_get_server ()->dispatch ( $ request );
641
+ $ this ->assertEquals ( 201 , $ response ->get_status () );
642
+ $ headers = $ response ->get_headers ();
643
+ $ data = $ response ->get_data ();
644
+ $ this ->assertContains ( '/wp/v2/tags/ ' . $ data ['id ' ], $ headers ['Location ' ] );
645
+ $ this ->assertEquals ( 'My Awesome Term ' , $ data ['name ' ] );
646
+ $ this ->assertEquals ( '' , get_term_meta ( $ existing_tag_id , 'test_tag_single ' , true ) );
647
+ $ this ->assertEquals ( 'hello ' , get_term_meta ( $ data ['id ' ], 'test_tag_single ' , true ) );
648
+ }
649
+
619
650
public function test_update_item () {
620
651
wp_set_current_user ( self ::$ administrator );
621
652
$ orig_args = array (
0 commit comments