@@ -49,16 +49,21 @@ public function tear_down() {
4949 /**
5050 * Calls edit_comment() with a comment ID and a new parent, as submitted from the Edit Comment screen.
5151 *
52- * @param int $comment_id Comment ID.
53- * @param int $comment_parent New parent comment ID.
52+ * @param int $comment_id Comment ID.
53+ * @param int $comment_parent New parent comment ID.
54+ * @param string|null $comment_status Optional. New comment status.
5455 * @return int|WP_Error The edit_comment() return value.
5556 */
56- private function update_comment_parent ( $ comment_id , $ comment_parent ) {
57+ private function update_comment_parent ( $ comment_id , $ comment_parent, $ comment_status = null ) {
5758 $ _POST = array (
5859 'comment_ID ' => $ comment_id ,
5960 'comment_parent ' => $ comment_parent ,
6061 );
6162
63+ if ( null !== $ comment_status ) {
64+ $ _POST ['comment_status ' ] = $ comment_status ;
65+ }
66+
6267 return edit_comment ();
6368 }
6469
@@ -75,6 +80,69 @@ public function test_should_update_comment_parent() {
7580 $ this ->assertSame ( (string ) $ parent_id , get_comment ( $ comment_id )->comment_parent );
7681 }
7782
83+ /**
84+ * @ticket 65688
85+ */
86+ public function test_should_reject_unapproved_parent_for_approved_comment () {
87+ $ parent_id = self ::factory ()->comment ->create (
88+ array (
89+ 'comment_post_ID ' => self ::$ post_id ,
90+ 'comment_approved ' => '0 ' ,
91+ )
92+ );
93+ $ comment_id = self ::factory ()->comment ->create ( array ( 'comment_post_ID ' => self ::$ post_id ) );
94+
95+ $ result = $ this ->update_comment_parent ( $ comment_id , $ parent_id );
96+
97+ $ this ->assertWPError ( $ result );
98+ $ this ->assertSame ( 'comment_parent_invalid ' , $ result ->get_error_code () );
99+ $ this ->assertSame ( '0 ' , get_comment ( $ comment_id )->comment_parent );
100+ }
101+
102+ /**
103+ * @ticket 65688
104+ */
105+ public function test_should_reject_unapproved_parent_when_comment_is_approved_in_same_update () {
106+ $ parent_id = self ::factory ()->comment ->create (
107+ array (
108+ 'comment_post_ID ' => self ::$ post_id ,
109+ 'comment_approved ' => '0 ' ,
110+ )
111+ );
112+ $ comment_id = self ::factory ()->comment ->create (
113+ array (
114+ 'comment_post_ID ' => self ::$ post_id ,
115+ 'comment_approved ' => '0 ' ,
116+ )
117+ );
118+
119+ $ result = $ this ->update_comment_parent ( $ comment_id , $ parent_id , '1 ' );
120+
121+ $ this ->assertWPError ( $ result );
122+ $ this ->assertSame ( 'comment_parent_invalid ' , $ result ->get_error_code () );
123+ $ this ->assertSame ( '0 ' , get_comment ( $ comment_id )->comment_approved );
124+ $ this ->assertSame ( '0 ' , get_comment ( $ comment_id )->comment_parent );
125+ }
126+
127+ /**
128+ * @ticket 65688
129+ */
130+ public function test_should_allow_unapproved_parent_when_comment_is_unapproved_in_same_update () {
131+ $ parent_id = self ::factory ()->comment ->create (
132+ array (
133+ 'comment_post_ID ' => self ::$ post_id ,
134+ 'comment_approved ' => '0 ' ,
135+ )
136+ );
137+ $ comment_id = self ::factory ()->comment ->create ( array ( 'comment_post_ID ' => self ::$ post_id ) );
138+
139+ $ result = $ this ->update_comment_parent ( $ comment_id , $ parent_id , '0 ' );
140+
141+ $ this ->assertSame ( 1 , $ result );
142+ $ this ->assertSame ( '0 ' , get_comment ( $ comment_id )->comment_approved );
143+ $ this ->assertSame ( (string ) $ parent_id , get_comment ( $ comment_id )->comment_parent );
144+ }
145+
78146 /**
79147 * @ticket 65570
80148 */
0 commit comments