Changeset 47122 for trunk/tests/phpunit/tests/ajax/GetComments.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/GetComments.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 … … 46 46 public function test_as_admin() { 47 47 48 // Become an administrator 48 // Become an administrator. 49 49 $this->_setRole( 'administrator' ); 50 50 51 // Set up a default request 51 // Set up a default request. 52 52 $_POST['_ajax_nonce'] = wp_create_nonce( 'get-comments' ); 53 53 $_POST['action'] = 'get-comments'; 54 54 $_POST['p'] = self::$comment_post->ID; 55 55 56 // Make the request 56 // Make the request. 57 57 try { 58 58 $this->_handleAjax( 'get-comments' ); … … 61 61 } 62 62 63 // Get the response 63 // Get the response. 64 64 $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA ); 65 65 66 // Check the meta data 66 // Check the meta data. 67 67 $this->assertEquals( 1, (string) $xml->response[0]->comments['position'] ); 68 68 $this->assertEquals( 0, (string) $xml->response[0]->comments['id'] ); 69 69 $this->assertEquals( 'get-comments_0', (string) $xml->response['action'] ); 70 70 71 // Check the payload 71 // Check the payload. 72 72 $this->assertNotEmpty( (string) $xml->response[0]->comments[0]->response_data ); 73 73 74 // And supplemental is empty 74 // And supplemental is empty. 75 75 $this->assertEmpty( (string) $xml->response[0]->comments[0]->supplemental ); 76 76 } … … 84 84 public function test_as_subscriber() { 85 85 86 // Become a subscriber 86 // Become a subscriber. 87 87 $this->_setRole( 'subscriber' ); 88 88 89 // Set up a default request 89 // Set up a default request. 90 90 $_POST['_ajax_nonce'] = wp_create_nonce( 'get-comments' ); 91 91 $_POST['action'] = 'get-comments'; 92 92 $_POST['p'] = self::$comment_post->ID; 93 93 94 // Make the request 94 // Make the request. 95 95 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 96 96 $this->_handleAjax( 'get-comments' ); … … 105 105 public function test_bad_nonce() { 106 106 107 // Become an administrator 107 // Become an administrator. 108 108 $this->_setRole( 'administrator' ); 109 109 110 // Set up a default request 110 // Set up a default request. 111 111 $_POST['_ajax_nonce'] = wp_create_nonce( uniqid() ); 112 112 $_POST['action'] = 'get-comments'; 113 113 $_POST['p'] = self::$comment_post->ID; 114 114 115 // Make the request 115 // Make the request. 116 116 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 117 117 $this->_handleAjax( 'get-comments' ); … … 126 126 public function test_invalid_post() { 127 127 128 // Become an administrator 128 // Become an administrator. 129 129 $this->_setRole( 'administrator' ); 130 130 131 // Set up a default request 131 // Set up a default request. 132 132 $_POST['_ajax_nonce'] = wp_create_nonce( 'get-comments' ); 133 133 $_POST['action'] = 'get-comments'; 134 134 $_POST['p'] = 'b0rk'; 135 135 136 // Make the request 136 // Make the request. 137 137 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 138 138 $this->_handleAjax( 'get-comments' ); … … 147 147 public function test_post_with_no_comments() { 148 148 149 // Become an administrator 149 // Become an administrator. 150 150 $this->_setRole( 'administrator' ); 151 151 152 // Set up a default request 152 // Set up a default request. 153 153 $_POST['_ajax_nonce'] = wp_create_nonce( 'get-comments' ); 154 154 $_POST['action'] = 'get-comments'; 155 155 $_POST['p'] = self::$no_comment_post->ID; 156 156 157 // Make the request 157 // Make the request. 158 158 $this->setExpectedException( 'WPAjaxDieStopException', '1' ); 159 159 $this->_handleAjax( 'get-comments' );
Note: See TracChangeset
for help on using the changeset viewer.