Changeset 47122 for trunk/tests/phpunit/tests/ajax/DimComment.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/DimComment.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 … … 55 55 public function _test_as_admin( $comment ) { 56 56 57 // Reset request 58 $this->_clear_post_action(); 59 60 // Become an administrator 57 // Reset request. 58 $this->_clear_post_action(); 59 60 // Become an administrator. 61 61 $this->_setRole( 'administrator' ); 62 62 63 // Set up a default request 63 // Set up a default request. 64 64 $_POST['id'] = $comment->comment_ID; 65 65 $_POST['_ajax_nonce'] = wp_create_nonce( 'approve-comment_' . $comment->comment_ID ); … … 69 69 $_POST['_url'] = admin_url( 'edit-comments.php' ); 70 70 71 // Save the comment status 71 // Save the comment status. 72 72 $prev_status = wp_get_comment_status( $comment->comment_ID ); 73 73 74 // Make the request 74 // Make the request. 75 75 try { 76 76 $this->_handleAjax( 'dim-comment' ); … … 79 79 } 80 80 81 // Get the response 81 // Get the response. 82 82 $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA ); 83 83 84 // Ensure everything is correct 84 // Ensure everything is correct. 85 85 $this->assertEquals( $comment->comment_ID, (string) $xml->response[0]->comment['id'] ); 86 86 $this->assertEquals( 'dim-comment_' . $comment->comment_ID, (string) $xml->response['action'] ); … … 88 88 $this->assertLessThanOrEqual( time(), (int) $xml->response[0]->comment[0]->supplemental[0]->time[0] ); 89 89 90 // Check the status 90 // Check the status. 91 91 $current = wp_get_comment_status( $comment->comment_ID ); 92 92 if ( in_array( $prev_status, array( 'unapproved', 'spam' ), true ) ) { … … 96 96 } 97 97 98 // The total is calculated based on a page break -OR- a random number. Let's look for both possible outcomes98 // The total is calculated based on a page break -OR- a random number. Let's look for both possible outcomes. 99 99 $comment_count = wp_count_comments( 0 ); 100 100 $recalc_total = $comment_count->total_comments; 101 101 102 // Delta is not specified, it will always be 1 lower than the request 102 // Delta is not specified, it will always be 1 lower than the request. 103 103 $total = $_POST['_total'] - 1; 104 104 105 // Check for either possible total 105 // Check for either possible total. 106 106 $this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ), true ) ); 107 107 } … … 116 116 public function _test_as_subscriber( $comment ) { 117 117 118 // Reset request 119 $this->_clear_post_action(); 120 121 // Become a subscriber 118 // Reset request. 119 $this->_clear_post_action(); 120 121 // Become a subscriber. 122 122 $this->_setRole( 'subscriber' ); 123 123 124 // Set up the $_POST request 124 // Set up the $_POST request. 125 125 $_POST['id'] = $comment->comment_ID; 126 126 $_POST['_ajax_nonce'] = wp_create_nonce( 'approve-comment_' . $comment->comment_ID ); … … 130 130 $_POST['_url'] = admin_url( 'edit-comments.php' ); 131 131 132 // Make the request 132 // Make the request. 133 133 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 134 134 $this->_handleAjax( 'dim-comment' ); … … 144 144 public function _test_with_bad_nonce( $comment ) { 145 145 146 // Reset request 147 $this->_clear_post_action(); 148 149 // Become a subscriber 146 // Reset request. 147 $this->_clear_post_action(); 148 149 // Become a subscriber. 150 150 $this->_setRole( 'administrator' ); 151 151 152 // Set up the $_POST request 152 // Set up the $_POST request. 153 153 $_POST['id'] = $comment->comment_ID; 154 154 $_POST['_ajax_nonce'] = wp_create_nonce( uniqid() ); … … 158 158 $_POST['_url'] = admin_url( 'edit-comments.php' ); 159 159 160 // Make the request 160 // Make the request. 161 161 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 162 162 $this->_handleAjax( 'dim-comment' ); … … 171 171 public function test_with_bad_id() { 172 172 173 // Reset request 174 $this->_clear_post_action(); 175 176 // Become a subscriber 173 // Reset request. 174 $this->_clear_post_action(); 175 176 // Become a subscriber. 177 177 $this->_setRole( 'administrator' ); 178 178 179 // Set up the $_POST request 179 // Set up the $_POST request. 180 180 $_POST['id'] = 12346789; 181 181 $_POST['_ajax_nonce'] = wp_create_nonce( 'dim-comment_12346789' ); … … 185 185 $_POST['_url'] = admin_url( 'edit-comments.php' ); 186 186 187 // Make the request, look for a timestamp in the exception 187 // Make the request, look for a timestamp in the exception. 188 188 try { 189 189 $this->_handleAjax( 'dim-comment' ); … … 191 191 } catch ( WPAjaxDieContinueException $e ) { 192 192 193 // Get the response 193 // Get the response. 194 194 $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA ); 195 195 196 // Ensure everything is correct 196 // Ensure everything is correct. 197 197 $this->assertEquals( '0', (string) $xml->response[0]->comment['id'] ); 198 198 $this->assertEquals( 'dim-comment_0', (string) $xml->response['action'] );
Note: See TracChangeset
for help on using the changeset viewer.