Changeset 512 in tests
- Timestamp:
- 02/02/2012 12:49:18 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wp-testcase/test_admin_includes_ajax_actions.php
r506 r512 12 12 */ 13 13 include_once(DIR_TESTDATA . '/sample_blogs.php'); 14 15 /**16 * Admin ajax functions to be tested17 */18 include_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );19 14 20 15 /** … … 34 29 * @since 3.4.0 35 30 */ 36 class AjaxTestextends _WPDataset2 {31 class WPAjaxTestCase extends _WPDataset2 { 37 32 38 33 /** … … 119 114 * If you're testing ajax and you expect wp_die(<anything>), you must use: 120 115 * <code> 121 * $this->setExpectedException('WPAjaxDieException'); 122 * $this->assertEquals(<anything>, $this->_last_message); 116 * $this->setExpectedException('WPAjaxDieException', '<anything>'); 123 117 * </code> 124 118 * @param string $message … … 168 162 } 169 163 } 170 171 /**172 * Testing ajax comment functionality173 *174 * @package WordPress175 * @subpackage Unit Tests176 * @since 3.4.0177 */178 class TestAjaxComments extends AjaxTest {179 180 /**181 * List of comments182 * @var array183 */184 protected $_comments = array();185 186 /**187 * Set up the test fixture188 */189 public function setUp() {190 parent::setUp();191 $this->_comments = get_comments(array(192 'status' => 'all',193 'search' => '',194 'user_id' => '',195 'offset' => 2,196 'number' => 20,197 'post_id' => 0,198 'type' => '',199 'orderby' => '',200 'order' => ''201 ));202 }203 204 /**205 * Delete a comment as an administrator (expects success)206 */207 public function test_ajax_trash_comment_as_admin() {208 209 // Become an administrator210 $this->_setRole( 'administrator' );211 212 // Set up the $_POST request213 $comment = $this->_comments[0];214 $_POST['id'] = $comment->comment_ID;215 $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );216 $_POST['trash'] = 1;217 $_POST['_total'] = wp_count_comments( 0 );218 $_POST['_per_page'] = 20;219 $_POST['_page'] = 2;220 $_POST['_url'] = admin_url( 'edit-comments.php' );221 222 // Make the request223 $this->_handleAjax( 'delete-comment' );224 225 // Get the response226 $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );227 228 // Ensure everything is correct229 $this->assertEquals( (string) $xml->response[0]->comment['id'], $comment->comment_ID );230 $this->assertEquals( (string) $xml->response['action'], 'delete-comment_' . $comment->comment_ID );231 $this->assertGreaterThanOrEqual( time() - 10, (int) $xml->response[0]->comment[0]->supplemental[0]->time[0] );232 $this->assertLessThanOrEqual( time(), (int) $xml->response[0]->comment[0]->supplemental[0]->time[0] );233 }234 235 /**236 * Delete a comment as a subscriber (expects permission denied)237 */238 public function test_ajax_trash_comment_as_subscriber() {239 240 // Become a subscriber241 $this->_setRole( 'subscriber' );242 243 // Set up the $_POST request244 $comment = $this->_comments[1];245 $_POST['id'] = $comment->comment_ID;246 $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );247 $_POST['trash'] = 1;248 $_POST['_total'] = wp_count_comments( 0 );249 $_POST['_per_page'] = 20;250 $_POST['_page'] = 2;251 $_POST['_url'] = admin_url( 'edit-comments.php' );252 253 // Make the request254 $this->setExpectedException( 'WPAjaxDieException' );255 $this->_handleAjax( 'delete-comment' );256 257 // Get the response258 $this->assertEquals( -1, $this->_last_response );259 }260 261 /**262 * @todo wp_ajax_dim_comment()263 * @todo wp_ajax_get_comments()264 * @todo wp_ajax_replyto_comment()265 * @todo wp_ajax_edit_comment()266 */267 }
Note: See TracChangeset
for help on using the changeset viewer.