Changeset 47122 for trunk/tests/phpunit/tests/ajax/EditComment.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/EditComment.php
r46586 r47122 2 2 3 3 /** 4 * Admin ajax functions to be tested4 * Admin Ajax functions to be tested. 5 5 */ 6 6 require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' ); 7 7 8 8 /** 9 * Testing ajax comment functionality9 * Testing Ajax comment functionality. 10 10 * 11 11 * @package WordPress … … 41 41 public function test_as_admin() { 42 42 43 // Become an administrator 43 // Become an administrator. 44 44 $this->_setRole( 'administrator' ); 45 45 46 // Get a comment 47 $comments = get_comments( 48 array( 49 'post_id' => $this->_comment_post->ID, 50 ) 51 ); 52 $comment = array_pop( $comments ); 53 54 // Set up a default request 55 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 56 $_POST['comment_ID'] = $comment->comment_ID; 57 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 58 59 // Make the request 46 // Get a comment. 47 $comments = get_comments( 48 array( 49 'post_id' => $this->_comment_post->ID, 50 ) 51 ); 52 $comment = array_pop( $comments ); 53 54 // Set up a default request. 55 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 56 $_POST['comment_ID'] = $comment->comment_ID; 57 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 58 59 // Make the request. 60 60 try { 61 61 $this->_handleAjax( 'edit-comment' ); … … 64 64 } 65 65 66 // Get the response 66 // Get the response. 67 67 $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA ); 68 68 69 // Check the meta data 69 // Check the meta data. 70 70 $this->assertEquals( -1, (string) $xml->response[0]->edit_comment['position'] ); 71 71 $this->assertEquals( $comment->comment_ID, (string) $xml->response[0]->edit_comment['id'] ); 72 72 $this->assertEquals( 'edit-comment_' . $comment->comment_ID, (string) $xml->response['action'] ); 73 73 74 // Check the payload 74 // Check the payload. 75 75 $this->assertNotEmpty( (string) $xml->response[0]->edit_comment[0]->response_data ); 76 76 77 // And supplemental is empty 77 // And supplemental is empty. 78 78 $this->assertEmpty( (string) $xml->response[0]->edit_comment[0]->supplemental ); 79 79 } … … 85 85 global $wpdb; 86 86 87 // Become an editor 87 // Become an editor. 88 88 $this->_setRole( 'editor' ); 89 89 90 // Get a comment 91 $comments = get_comments( 92 array( 93 'post_id' => $this->_comment_post->ID, 94 ) 95 ); 96 $comment = array_pop( $comments ); 97 98 // Manually update the comment_post_ID, because wp_update_comment() will prevent it. 90 // Get a comment. 91 $comments = get_comments( 92 array( 93 'post_id' => $this->_comment_post->ID, 94 ) 95 ); 96 $comment = array_pop( $comments ); 97 98 // Manually update the comment_post_ID, because wp_update_comment() will prevent it.. 99 99 $wpdb->update( $wpdb->comments, array( 'comment_post_ID' => 0 ), array( 'comment_ID' => $comment->comment_ID ) ); 100 100 clean_comment_cache( $comment->comment_ID ); 101 101 102 // Set up a default request 103 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 104 $_POST['comment_ID'] = $comment->comment_ID; 105 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 106 107 // Make the request 102 // Set up a default request. 103 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 104 $_POST['comment_ID'] = $comment->comment_ID; 105 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 106 107 // Make the request. 108 108 try { 109 109 $this->_handleAjax( 'edit-comment' ); … … 112 112 } 113 113 114 // Get the response 114 // Get the response. 115 115 $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA ); 116 116 117 // Check the meta data 117 // Check the meta data. 118 118 $this->assertEquals( -1, (string) $xml->response[0]->edit_comment['position'] ); 119 119 $this->assertEquals( $comment->comment_ID, (string) $xml->response[0]->edit_comment['id'] ); 120 120 $this->assertEquals( 'edit-comment_' . $comment->comment_ID, (string) $xml->response['action'] ); 121 121 122 // Check the payload 122 // Check the payload. 123 123 $this->assertNotEmpty( (string) $xml->response[0]->edit_comment[0]->response_data ); 124 124 125 // And supplemental is empty 125 // And supplemental is empty. 126 126 $this->assertEmpty( (string) $xml->response[0]->edit_comment[0]->supplemental ); 127 127 } … … 135 135 public function test_as_subscriber() { 136 136 137 // Become a n administrator137 // Become a subscriber. 138 138 $this->_setRole( 'subscriber' ); 139 139 140 // Get a comment 141 $comments = get_comments( 142 array( 143 'post_id' => $this->_comment_post->ID, 144 ) 145 ); 146 $comment = array_pop( $comments ); 147 148 // Set up a default request 149 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 150 $_POST['comment_ID'] = $comment->comment_ID; 151 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 152 153 // Make the request 140 // Get a comment. 141 $comments = get_comments( 142 array( 143 'post_id' => $this->_comment_post->ID, 144 ) 145 ); 146 $comment = array_pop( $comments ); 147 148 // Set up a default request. 149 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 150 $_POST['comment_ID'] = $comment->comment_ID; 151 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 152 153 // Make the request. 154 154 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 155 155 $this->_handleAjax( 'edit-comment' ); … … 164 164 public function test_bad_nonce() { 165 165 166 // Become an administrator 166 // Become an administrator. 167 167 $this->_setRole( 'administrator' ); 168 168 169 // Get a comment 170 $comments = get_comments( 171 array( 172 'post_id' => $this->_comment_post->ID, 173 ) 174 ); 175 $comment = array_pop( $comments ); 176 177 // Set up a default request 169 // Get a comment. 170 $comments = get_comments( 171 array( 172 'post_id' => $this->_comment_post->ID, 173 ) 174 ); 175 $comment = array_pop( $comments ); 176 177 // Set up a default request. 178 178 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( uniqid() ); 179 179 $_POST['comment_ID'] = $comment->comment_ID; 180 180 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 181 181 182 // Make the request 182 // Make the request. 183 183 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 184 184 $this->_handleAjax( 'get-comments' ); … … 193 193 public function test_invalid_comment() { 194 194 195 // Become an administrator 195 // Become an administrator. 196 196 $this->_setRole( 'administrator' ); 197 197 198 // Set up a default request 198 // Set up a default request. 199 199 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 200 200 $_POST['comment_ID'] = 123456789; 201 201 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 202 202 203 // Make the request 203 // Make the request. 204 204 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 205 205 $this->_handleAjax( 'edit-comment' );
Note: See TracChangeset
for help on using the changeset viewer.