Make WordPress Core

Changeset 833 in tests


Ignore:
Timestamp:
07/01/2012 06:30:34 PM (14 years ago)
Author:
kurtpayne
Message:

Port AJAX tests to new test runner. Fixes #51 and #46. props duck_.

Location:
trunk
Files:
10 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/bootstrap.php

    r807 r833  
    5454require dirname( __FILE__ ) . '/wp-testlib/testcase.php';
    5555require dirname( __FILE__ ) . '/wp-testlib/testcase-xmlrpc.php';
     56require dirname( __FILE__ ) . '/wp-testlib/testcase-ajax.php';
    5657require dirname( __FILE__ ) . '/wp-testlib/exceptions.php';
    5758require dirname( __FILE__ ) . '/wp-testlib/utils.php';
  • trunk/wp-testcase/test-ajax-actions/test_admin_ajax_compression_test.php

    r734 r833  
    11<?php
    2 
    3 /**
    4  * Get WPAjaxTestCase class
    5  */
    6 require_once( DIR_TESTCASE . '/test_admin_includes_ajax_actions.php' );
    72
    83/**
     
    1914 * @group      Ajax
    2015 */
    21 class TestAjaxCompressionTest extends WPAjaxTestCase {
     16class TestAjaxCompressionTest extends WP_Ajax_UnitTestCase {
    2217       
    2318        /**
     
    2520         */
    2621        public function test_logged_out() {
    27 
    28                 // Become an administrator
    2922                $this->logout();
    3023
  • trunk/wp-testcase/test-ajax-actions/test_admin_ajax_delete_comments.php

    r722 r833  
    11<?php
    2 
    3 /**
    4  * Get WPAjaxTestCase class
    5  */
    6 require_once( DIR_TESTCASE . '/test_admin_includes_ajax_actions.php' );
    72
    83/**
     
    1914 * @group      Ajax
    2015 */
    21 class TestAjaxCommentsDelete extends WPAjaxTestCase {
     16class TestAjaxCommentsDelete extends WP_Ajax_UnitTestCase {
    2217
    2318        /**
     
    3126         */
    3227        public function setUp() {
    33                 parent::setUp();       
    34                 $this->_comments = get_comments(array(
    35                         'status'  => 'all',
    36                         'search'  => '',
    37                         'user_id' => '',
    38                         'offset'  => 1,
    39                         'number'  => 20,
    40                         'post_id' => 0,
    41                         'type'    => '',
    42                         'orderby' => '',
    43                         'order'   => ''
    44                 ));
     28                parent::setUp();
     29                $post_id = $this->factory->post->create();
     30                $this->_comments = $this->factory->comment->create_post_comments( $post_id, 15 );
     31                $this->_comments = array_map( 'get_comment', $this->_comments );
    4532        }
    4633
  • trunk/wp-testcase/test-ajax-actions/test_admin_ajax_dim_comments.php

    r722 r833  
    11<?php
    2 
    3 /**
    4  * Get WPAjaxTestCase class
    5  */
    6 require_once( DIR_TESTCASE . '/test_admin_includes_ajax_actions.php' );
    72
    83/**
     
    1914 * @group      Ajax
    2015 */
    21 class TestAjaxCommentsDim extends WPAjaxTestCase {
     16class TestAjaxCommentsDim extends WP_Ajax_UnitTestCase {
    2217
    2318        /**
     
    3126         */
    3227        public function setUp() {
    33                 parent::setUp();       
    34                 $this->_comments = get_comments(array(
    35                         'status'  => 'all',
    36                         'search'  => '',
    37                         'user_id' => '',
    38                         'offset'  => 1,
    39                         'number'  => 20,
    40                         'post_id' => 0,
    41                         'type'    => '',
    42                         'orderby' => '',
    43                         'order'   => ''
    44                 ));
     28                parent::setUp();
     29                $post_id = $this->factory->post->create();
     30                $this->_comments = $this->factory->comment->create_post_comments( $post_id, 15 );
     31                $this->_comments = array_map( 'get_comment', $this->_comments );
    4532        }
    4633
  • trunk/wp-testcase/test-ajax-actions/test_admin_ajax_edit_comment.php

    r722 r833  
    11<?php
    2 
    3 /**
    4  * Get WPAjaxTestCase class
    5  */
    6 require_once( DIR_TESTCASE . '/test_admin_includes_ajax_actions.php' );
    72
    83/**
     
    1914 * @group      Ajax
    2015 */
    21 class TestAjaxCommentsEdit extends WPAjaxTestCase {
     16class TestAjaxCommentsEdit extends WP_Ajax_UnitTestCase {
    2217
    2318        /**
     
    3126         */
    3227        public function setUp() {
    33                 global $wpdb;
    3428                parent::setUp();
    35                 $posts = $wpdb->get_results( $wpdb->prepare("
    36                 SELECT
    37                         COUNT(c.comment_ID) AS comments,
    38                         p.ID AS post_ID
    39                 FROM
    40                         $wpdb->posts p
    41                         LEFT JOIN $wpdb->comments c ON c.comment_post_ID = p.ID
    42                 WHERE
    43                         p.post_status = 'publish'
    44                         AND p.post_type = 'post'
    45                 GROUP BY
    46                         p.ID
    47                 ") );
    48                 foreach ( (array) $posts as $tmp ) {
    49                         if ( null === $this->_comment_post && $tmp->comments > 0 ) {
    50                                 $this->_comment_post = get_post( $tmp->post_ID );
    51                                 break;
    52                         }
    53                 }
     29                $post_id = $this->factory->post->create();
     30                $this->factory->comment->create_post_comments( $post_id, 5 );
     31                $this->_comment_post = get_post( $post_id );
    5432        }
    5533
  • trunk/wp-testcase/test-ajax-actions/test_admin_ajax_get_comments.php

    r722 r833  
    11<?php
    2 
    3 /**
    4  * Get WPAjaxTestCase class
    5  */
    6 require_once( DIR_TESTCASE . '/test_admin_includes_ajax_actions.php' );
    72
    83/**
     
    1914 * @group      Ajax
    2015 */
    21 class TestAjaxCommentsGet extends WPAjaxTestCase {
     16class TestAjaxCommentsGet extends WP_Ajax_UnitTestCase {
    2217
    2318        /**
     
    3732         */
    3833        public function setUp() {
    39                 global $wpdb;
    4034                parent::setUp();
    41                 $posts = $wpdb->get_results( $wpdb->prepare("
    42                 SELECT
    43                         COUNT(c.comment_ID) AS comments,
    44                         p.ID AS post_ID
    45                 FROM
    46                         $wpdb->posts p
    47                         LEFT JOIN $wpdb->comments c ON c.comment_post_ID = p.ID
    48                 WHERE
    49                         p.post_status = 'publish'
    50                         AND p.post_type = 'post'
    51                 GROUP BY
    52                         p.ID
    53                 ") );
    54                 foreach ( (array) $posts as $tmp ) {
    55                         if ( null === $this->_comment_post && $tmp->comments > 0 ) {
    56                                 $this->_comment_post = get_post( $tmp->post_ID );
    57                         }
    58                         if ( null === $this->_no_comment_post && $tmp->comments == 0 ) {
    59                                 $this->_no_comment_post = get_post( $tmp->post_ID );
    60                         }
    61                         if ( null !== $this->_comment_post && null !== $this->_no_comment_post ) {
    62                                 break;
    63                         }
    64                 }
     35                $post_id = $this->factory->post->create();
     36                $this->factory->comment->create_post_comments( $post_id, 5 );
     37                $this->_comment_post = get_post( $post_id );
     38
     39                $post_id = $this->factory->post->create();
     40                $this->_no_comment_post = get_post( $post_id );
    6541        }
    6642
  • trunk/wp-testcase/test-ajax-actions/test_admin_ajax_replyto_comment.php

    r754 r833  
    11<?php
    2 
    3 /**
    4  * Get WPAjaxTestCase class
    5  */
    6 require_once( DIR_TESTCASE . '/test_admin_includes_ajax_actions.php' );
    72
    83/**
     
    1914 * @group      Ajax
    2015 */
    21 class TestAjaxCommentsReply extends WPAjaxTestCase {
     16class TestAjaxCommentsReply extends WP_Ajax_UnitTestCase {
    2217
    2318        /**
     
    3732         */
    3833        public function setUp() {
    39                 global $wpdb;
    4034                parent::setUp();
    41                 $posts = $wpdb->get_results( $wpdb->prepare("
    42                         SELECT
    43                                 COUNT(c.comment_ID) AS comments,
    44                                 p.ID AS post_ID,
    45                                 p.post_status
    46                         FROM
    47                                 $wpdb->posts p
    48                                 LEFT JOIN $wpdb->comments c ON c.comment_post_ID = p.ID
    49                         WHERE
    50                                 p.post_status IN('draft', 'publish')
    51                                 AND p.post_type = 'post'
    52                         GROUP BY
    53                                 p.ID
    54                 ") );
    55                 foreach ( (array) $posts as $tmp ) {
    56                         if ( null === $this->_comment_post && $tmp->comments > 0 && 'publish' == $tmp->post_status ) {
    57                                 $this->_comment_post = get_post( $tmp->post_ID );
    58                         }
    59                         if ( null === $this->_draft_post && 'draft' == $tmp->post_status ) {
    60                                 $this->_draft_post = get_post( $tmp->post_ID );
    61                         }
    62                         if ( null !== $this->_draft_post && null !== $this->_comment_post ) {
    63                                 break;
    64                         }
    65                 }
     35                $post_id = $this->factory->post->create();
     36                $this->factory->comment->create_post_comments( $post_id, 5 );
     37                $this->_comment_post = get_post( $post_id );
     38
     39                $post_id = $this->factory->post->create( array( 'post_status' => 'draft' ) );
     40                $this->_draft_post = get_post( $post_id );
    6641        }
    6742
  • trunk/wp-testcase/test-ajax-actions/test_admin_ajax_save_draft.php

    r722 r833  
    11<?php
    2 
    3 /**
    4  * Get WPAjaxTestCase class
    5  */
    6 require_once( DIR_TESTCASE . '/test_admin_includes_ajax_actions.php' );
    72
    83/**
     
    1914 * @group      Ajax
    2015 */
    21 class TestAjaxSaveDraft extends WPAjaxTestCase {
     16class TestAjaxSaveDraft extends WP_Ajax_UnitTestCase {
    2217
    2318        /**
     
    3328        public function setUp() {
    3429                parent::setUp();
    35                 $tmp = get_posts( array(
    36                     'post_status' => 'draft'
    37                 ) );
    38                 $this->_post = $tmp[0];
     30                $post_id = $this->factory->post->create( array( 'post_status' => 'draft' ) );
     31                $this->_post = get_post( $post_id );
    3932        }
    4033
  • trunk/wp-testcase/test-ajax-actions/test_admin_ajax_tag_search.php

    r733 r833  
    11<?php
    2 
    3 /**
    4  * Get WPAjaxTestCase class
    5  */
    6 require_once( DIR_TESTCASE . '/test_admin_includes_ajax_actions.php' );
    72
    83/**
     
    1914 * @group      Ajax
    2015 */
    21 class TestAjaxTagSearch extends WPAjaxTestCase {
     16class TestAjaxTagSearch extends WP_Ajax_UnitTestCase {
     17
     18        /**
     19         * List of terms to insert on setup
     20         * @var array
     21         */
     22        private $_terms = array(
     23                'chattels', 'depo', 'energumen', 'figuriste', 'habergeon', 'impropriation'
     24        );
     25
     26        /**
     27         * Setup
     28         * @todo use a term factory
     29         */
     30        public function setUp() {
     31                parent::setUp();
     32
     33                foreach ( $this->_terms as $term )
     34                        wp_insert_term( $term, 'post_tag' );
     35        }
    2236
    2337        /**
  • trunk/wp-testlib/exceptions.php

    r760 r833  
    44       
    55}
     6
     7/**
     8 * Exception for cases of wp_die()
     9 * This means there was an error (no output, and a call to wp_die)
     10 *
     11 * @package    WordPress
     12 * @subpackage Unit Tests
     13 * @since      3.4.0
     14 */
     15class WPAjaxDieStopException extends Exception {}
     16
     17/**
     18 * Exception for cases of wp_die()
     19 * This means execution of the ajax function should be halted, but the unit
     20 * test can continue.  The function finished normally and there was not an
     21 * error (output happened, but wp_die was called to end execution)  This is
     22 * used with WP_Ajax_Response::send
     23 *
     24 * @package    WordPress
     25 * @subpackage Unit Tests
     26 * @since      3.4.0
     27 */
     28class WPAjaxDieContinueException extends Exception {}
  • trunk/wp-testlib/testcase-ajax.php

    r823 r833  
    99
    1010/**
    11  * Sample blog data
    12  */
    13 include_once(DIR_TESTDATA . '/sample_blogs.php');
    14 
    15 /**
    16  * Exception for cases of wp_die()
    17  * This means there was an error (no output, and a call to wp_die)
    18  *
    19  * @package    WordPress
    20  * @subpackage Unit Tests
    21  * @since      3.4.0
    22  */
    23 class WPAjaxDieStopException extends Exception {}
    24 
    25 /**
    26  * Exception for cases of wp_die()
    27  * This means execution of the ajax function should be halted, but the unit
    28  * test can continue.  The function finished normally and there was not an
    29  * error (output happened, but wp_die was called to end execution)  This is
    30  * used with WP_Ajax_Response::send
    31  *
    32  * @package    WordPress
    33  * @subpackage Unit Tests
    34  * @since      3.4.0
    35  */
    36 class WPAjaxDieContinueException extends Exception {}
    37 
    38 /**
    3911 * Ajax test case class
    4012 *
     
    4315 * @since      3.4.0
    4416 */
    45 class WPAjaxTestCase extends _WPDataset2 {
     17abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
    4618       
    4719        /**
     
    10678                $this->_error_level = error_reporting();
    10779                error_reporting( $this->_error_level & ~E_WARNING );
     80
     81                // Make some posts
     82                $this->factory->post->create_many( 5 );
     83                $this->factory->comment->create( 5 );
    10884        }
    10985       
     
    177153        protected function _setRole( $role ) {
    178154                $post = $_POST;
    179                 $user_id = $this->_make_user( $role );
     155                $user_id = $this->factory->user->create( array( 'role' => $role ) );
    180156                wp_set_current_user( $user_id );
    181157                $_POST = array_merge($_POST, $post);
     
    191167               
    192168                // Start output buffering
     169                ini_set( 'implicit_flush', false );
    193170                ob_start();
    194171
Note: See TracChangeset for help on using the changeset viewer.