Changeset 47122 for trunk/tests/phpunit/tests/ajax/ReplytoComment.php
- Timestamp:
- 01/29/2020 12:43:23 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/ReplytoComment.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 … … 51 51 public function test_as_admin() { 52 52 53 // Become an administrator 54 $this->_setRole( 'administrator' ); 55 56 // Get a comment 53 // Become an administrator. 54 $this->_setRole( 'administrator' ); 55 56 // Get a comment. 57 57 $comments = get_comments( 58 58 array( … … 62 62 $comment = array_pop( $comments ); 63 63 64 // Set up a default request 64 // Set up a default request. 65 65 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 66 66 $_POST['comment_ID'] = $comment->comment_ID; … … 68 68 $_POST['comment_post_ID'] = self::$comment_post->ID; 69 69 70 // Make the request 70 // Make the request. 71 71 try { 72 72 $this->_handleAjax( 'replyto-comment' ); … … 75 75 } 76 76 77 // Get the response 77 // Get the response. 78 78 $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA ); 79 79 80 // Check the meta data 80 // Check the meta data. 81 81 $this->assertEquals( -1, (string) $xml->response[0]->comment['position'] ); 82 82 $this->assertGreaterThan( 0, (int) $xml->response[0]->comment['id'] ); 83 83 $this->assertNotEmpty( (string) $xml->response['action'] ); 84 84 85 // Check the payload 85 // Check the payload. 86 86 $this->assertNotEmpty( (string) $xml->response[0]->comment[0]->response_data ); 87 87 88 // And supplemental is empty 88 // And supplemental is empty. 89 89 $this->assertEmpty( (string) $xml->response[0]->comment[0]->supplemental ); 90 90 } … … 98 98 public function test_as_subscriber() { 99 99 100 // Become an administrator 100 // Become an administrator. 101 101 $this->_setRole( 'subscriber' ); 102 102 103 // Get a comment 103 // Get a comment. 104 104 $comments = get_comments( 105 105 array( … … 109 109 $comment = array_pop( $comments ); 110 110 111 // Set up a default request 111 // Set up a default request. 112 112 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 113 113 $_POST['comment_ID'] = $comment->comment_ID; … … 115 115 $_POST['comment_post_ID'] = self::$comment_post->ID; 116 116 117 // Make the request 117 // Make the request. 118 118 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 119 119 $this->_handleAjax( 'replyto-comment' ); … … 128 128 public function test_bad_nonce() { 129 129 130 // Become an administrator 131 $this->_setRole( 'administrator' ); 132 133 // Get a comment 130 // Become an administrator. 131 $this->_setRole( 'administrator' ); 132 133 // Get a comment. 134 134 $comments = get_comments( 135 135 array( … … 139 139 $comment = array_pop( $comments ); 140 140 141 // Set up a default request 141 // Set up a default request. 142 142 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( uniqid() ); 143 143 $_POST['comment_ID'] = $comment->comment_ID; … … 145 145 $_POST['comment_post_ID'] = self::$comment_post->ID; 146 146 147 // Make the request 147 // Make the request. 148 148 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 149 149 $this->_handleAjax( 'replyto-comment' ); … … 158 158 public function test_invalid_post() { 159 159 160 // Become an administrator 161 $this->_setRole( 'administrator' ); 162 163 // Set up a default request 160 // Become an administrator. 161 $this->_setRole( 'administrator' ); 162 163 // Set up a default request. 164 164 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 165 165 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 166 166 $_POST['comment_post_ID'] = 123456789; 167 167 168 // Make the request 168 // Make the request. 169 169 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 170 170 $this->_handleAjax( 'replyto-comment' ); … … 179 179 public function test_with_draft_post() { 180 180 181 // Become an administrator 182 $this->_setRole( 'administrator' ); 183 184 // Set up a default request 181 // Become an administrator. 182 $this->_setRole( 'administrator' ); 183 184 // Set up a default request. 185 185 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 186 186 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 187 187 $_POST['comment_post_ID'] = self::$draft_post->ID; 188 188 189 // Make the request 189 // Make the request. 190 190 $this->setExpectedException( 'WPAjaxDieStopException', 'ERROR: you are replying to a comment on a draft post.' ); 191 191 $this->_handleAjax( 'replyto-comment' ); … … 202 202 global $wpdb; 203 203 204 // Become an administrator 205 $this->_setRole( 'administrator' ); 206 207 // Set up a default request 208 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 209 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 210 $_POST['comment_post_ID'] = self::$comment_post->ID; 211 212 // Block comments from being saved, simulate a DB error 204 // Become an administrator. 205 $this->_setRole( 'administrator' ); 206 207 // Set up a default request. 208 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 209 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 210 $_POST['comment_post_ID'] = self::$comment_post->ID; 211 212 // Block comments from being saved, simulate a DB error. 213 213 add_filter( 'query', array( $this, '_block_comments' ) ); 214 214 215 // Make the request 215 // Make the request. 216 216 try { 217 217 $wpdb->suppress_errors( true ); … … 247 247 public function test_pre_comments_approved() { 248 248 249 // Become an administrator 250 $this->_setRole( 'administrator' ); 251 252 // Set up a default request 253 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 254 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 255 $_POST['comment_post_ID'] = self::$comment_post->ID; 256 257 // Simulate filter check error 249 // Become an administrator. 250 $this->_setRole( 'administrator' ); 251 252 // Set up a default request. 253 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 254 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 255 $_POST['comment_post_ID'] = self::$comment_post->ID; 256 257 // Simulate filter check error. 258 258 add_filter( 'pre_comment_approved', array( $this, '_pre_comment_approved_filter' ), 10, 2 ); 259 259 260 // Make the request 260 // Make the request. 261 261 $this->setExpectedException( 'WPAjaxDieStopException', 'pre_comment_approved filter fails for new comment' ); 262 262 $this->_handleAjax( 'replyto-comment' );
Note: See TracChangeset
for help on using the changeset viewer.