WordPress.org

Make WordPress Core

Changeset 515 in tests


Ignore:
Timestamp:
02/07/12 00:11:12 (3 years ago)
Author:
kurtpayne
Message:

Renamed this into a separate class dedicated to testing the wp_ajax_delete_comment() function. Fixed some phpdoc comments and two bugs:

  • The total was being returned inconsistently (based on a random number). The test now expects either value
  • The test_ajax_trash_comment_no_id() method was being run as a subscriber, not as an administrator
File:
1 moved

Legend:

Unmodified
Added
Removed
  • wp-testcase/test-ajax-actions/test_admin_ajax_delete_comments.php

    r514 r515  
    1717 * @subpackage Unit Tests 
    1818 * @since      3.4.0 
     19 * @group      Ajax 
    1920 */ 
    20 class TestAjaxComments extends WPAjaxTestCase { 
     21class TestAjaxCommentsDelete extends WPAjaxTestCase { 
    2122 
    2223    /** 
     
    3536            'search'  => '', 
    3637            'user_id' => '', 
    37             'offset'  => 2, 
     38            'offset'  => 1, 
    3839            'number'  => 20, 
    3940            'post_id' => 0, 
     
    6263     * Test as a privilged user (administrator) 
    6364     * Expects test to pass 
     65     * @param mixed $comment Comment object 
     66     * @param string action trash, untrash, etc. 
     67     * @return void 
    6468     */ 
    6569    public function _test_as_admin( $comment, $action ) { 
     
    9498        // trash, spam, delete should make the total go down 
    9599        if ( in_array( $action, array( 'trash', 'spam', 'delete' ) ) ) { 
    96             $this->assertEquals( $_POST['_total'] - 1, (int) $xml->response[0]->comment[0]->supplemental[0]->total[0] ); 
     100            $total = $_POST['_total'] - 1; 
    97101 
    98102        // unspam, untrash should make the total go up 
    99103        } elseif ( in_array( $action, array( 'untrash', 'unspam' ) ) ) { 
    100             $this->assertEquals( $_POST['_total'] + 1, (int) $xml->response[0]->comment[0]->supplemental[0]->total[0] ); 
     104            $total = $_POST['_total'] + 1; 
    101105        } 
     106         
     107        // The total is calculated based on a page break -OR- a random number.  Let's look for both possible outcomes 
     108        $comment_count = wp_count_comments( 0 ); 
     109        $recalc_total = $comment_count->total_comments; 
     110 
     111        // Check for either possible total 
     112        $this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0] , array( $total, $recalc_total ) ) ); 
    102113    } 
    103114     
     
    105116     * Test as a non-privileged user (subscriber) 
    106117     * Expects test to fail 
     118     * @param mixed $comment Comment object 
     119     * @param string action trash, untrash, etc. 
     120     * @return void 
    107121     */ 
    108122    public function _test_as_subscriber( $comment, $action ) { 
     
    132146     * Test with a bad nonce 
    133147     * Expects test to fail 
     148     * @param mixed $comment Comment object 
     149     * @param string action trash, untrash, etc. 
     150     * @return void 
    134151     */ 
    135152    public function _test_with_bad_nonce( $comment, $action ) { 
     
    158175     * Test with a bad id 
    159176     * Expects test to fail 
     177     * @param mixed $comment Comment object 
     178     * @param string action trash, untrash, etc. 
     179     * @return void 
    160180     */ 
    161181    public function _test_with_bad_id( $comment, $action ) { 
     
    184204     * Test doubling the action (e.g. trash a trashed comment) 
    185205     * Expects test to fail 
     206     * @param mixed $comment Comment object 
     207     * @param string action trash, untrash, etc. 
     208     * @return void 
    186209     */ 
    187210    public function _test_double_action( $comment, $action ) { 
     
    210233    } 
    211234 
    212  
    213      
    214      
    215235    /** 
    216236     * Delete a comment as an administrator (expects success) 
    217      * @ignore 
     237     * @return void 
    218238     */ 
    219239    public function test_ajax_comment_trash_actions_as_administrator() { 
     
    236256    /** 
    237257     * Delete a comment as a subscriber (expects permission denied) 
    238      * @ignore 
     258     * @return void 
    239259     */ 
    240260    public function test_ajax_comment_trash_actions_as_subscriber() { 
     
    257277    /** 
    258278     * Delete a comment with no id 
    259      * @ignore 
     279     * @return void 
    260280     */ 
    261281    public function test_ajax_trash_comment_no_id() { 
     
    263283        // Test trash/untrash 
    264284        $comment = array_pop( $this->_comments ); 
    265         $this->_test_as_subscriber( $comment, 'trash' ); 
    266         $this->_test_as_subscriber( $comment, 'untrash' ); 
    267          
    268         // Test spam/unspam 
    269         $comment = array_pop( $this->_comments ); 
    270         $this->_test_as_subscriber( $comment, 'spam' ); 
    271         $this->_test_as_subscriber( $comment, 'unspam' ); 
    272          
    273         // Test delete 
    274         $comment = array_pop( $this->_comments ); 
    275         $this->_test_as_subscriber( $comment, 'delete' ); 
     285        $this->_test_as_admin( $comment, 'trash' ); 
     286        $this->_test_as_admin( $comment, 'untrash' ); 
     287         
     288        // Test spam/unspam 
     289        $comment = array_pop( $this->_comments ); 
     290        $this->_test_as_admin( $comment, 'spam' ); 
     291        $this->_test_as_admin( $comment, 'unspam' ); 
     292         
     293        // Test delete 
     294        $comment = array_pop( $this->_comments ); 
     295        $this->_test_as_admin( $comment, 'delete' ); 
    276296    } 
    277297 
    278298    /** 
    279299     * Delete a comment with a bad nonce 
    280      * @ignore 
     300     * @return void 
    281301     */ 
    282302    public function test_ajax_trash_comment_bad_nonce() { 
     
    299319    /** 
    300320     * Test trashing an already trashed comment, etc. 
     321     * @return void 
    301322     */ 
    302323    public function test_ajax_trash_double_action() { 
     
    318339 
    319340    /** 
    320      * @todo wp_ajax_dim_comment() 
    321341     * @todo wp_ajax_get_comments() 
    322342     * @todo wp_ajax_replyto_comment() 
Note: See TracChangeset for help on using the changeset viewer.