WordPress.org

Make WordPress Core

Changeset 35173


Ignore:
Timestamp:
10/15/2015 12:38:26 AM (5 years ago)
Author:
wonderboymusic
Message:

Unit Tests: reuse fixtures in Tests_Comment.

See #30017, #33968.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment.php

    r34623 r35173  
    55 */
    66class Tests_Comment extends WP_UnitTestCase {
     7    protected static $user_id;
     8    protected static $post_id;
     9
     10    public static function setUpBeforeClass() {
     11        parent::setUpBeforeClass();
     12
     13        $factory = new WP_UnitTest_Factory();
     14
     15        self::$user_id = $factory->user->create();
     16        self::$post_id = $factory->post->create( array(
     17            'post_author' => self::$user_id
     18        ) );
     19
     20        self::commit_transaction();
     21    }
     22
    723    function test_wp_update_comment() {
    824        $post = $this->factory->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post' ) );
     
    2440     */
    2541    function test_wp_update_comment_updates_comment_type() {
    26         $post_id = $this->factory->post->create();
    27         $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $post_id ) );
     42        $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => self::$post_id ) );
    2843
    2944        wp_update_comment( array( 'comment_ID' => $comment_id, 'comment_type' => 'pingback' ) );
     
    3752     */
    3853    function test_wp_update_comment_updates_user_id() {
    39         $post_id = $this->factory->post->create();
    40         $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $post_id ) );
     54        $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => self::$post_id ) );
    4155
    4256        wp_update_comment( array( 'comment_ID' => $comment_id, 'user_id' => 1 ) );
     
    4761
    4862    public function test_get_approved_comments() {
    49         $p = $this->factory->post->create();
    50         $ca1 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1' ) );
    51         $ca2 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1' ) );
    52         $ca3 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '0' ) );
    53         $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1', 'comment_type' => 'pingback' ) );
    54         $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1', 'comment_type' => 'trackback' ) );
    55         $c4 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1', 'comment_type' => 'mario' ) );
    56         $c5 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1', 'comment_type' => 'luigi' ) );
    57 
    58         $found = get_approved_comments( $p );
     63        $ca1 = $this->factory->comment->create( array(
     64            'comment_post_ID' => self::$post_id, 'comment_approved' => '1'
     65        ) );
     66        $ca2 = $this->factory->comment->create( array(
     67            'comment_post_ID' => self::$post_id, 'comment_approved' => '1'
     68        ) );
     69        $ca3 = $this->factory->comment->create( array(
     70            'comment_post_ID' => self::$post_id, 'comment_approved' => '0'
     71        ) );
     72        $c2 = $this->factory->comment->create( array(
     73            'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback'
     74        ) );
     75        $c3 = $this->factory->comment->create( array(
     76            'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback'
     77        ) );
     78        $c4 = $this->factory->comment->create( array(
     79            'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario'
     80        ) );
     81        $c5 = $this->factory->comment->create( array(
     82            'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'luigi'
     83        ) );
     84
     85        $found = get_approved_comments( self::$post_id );
    5986
    6087        // all comments types will be returned
     
    6693     */
    6794    public function test_get_approved_comments_with_post_id_0_should_return_empty_array() {
    68         $p = $this->factory->post->create();
    69         $ca1 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1' ) );
     95        $ca1 = $this->factory->comment->create( array(
     96            'comment_post_ID' => self::$post_id, 'comment_approved' => '1'
     97        ) );
    7098
    7199        $found = get_approved_comments( 0 );
     
    78106     */
    79107    public function test_wp_new_comment_respects_dates() {
    80         $u = $this->factory->user->create();
    81         $post_id = $this->factory->post->create( array( 'post_author' => $u ) );
    82 
    83         $data = array(
    84             'comment_post_ID' => $post_id,
     108        $data = array(
     109            'comment_post_ID' => self::$post_id,
    85110            'comment_author' => rand_str(),
    86111            'comment_author_url' => '',
     
    104129     */
    105130    public function test_wp_new_comment_respects_author_ip() {
    106         $u = $this->factory->user->create();
    107         $post_id = $this->factory->post->create( array( 'post_author' => $u ) );
    108 
    109         $data = array(
    110             'comment_post_ID'      => $post_id,
     131        $data = array(
     132            'comment_post_ID'      => self::$post_id,
    111133            'comment_author'       => rand_str(),
    112134            'comment_author_IP'    => '192.168.1.1',
     
    128150     */
    129151    public function test_wp_new_comment_respects_author_ip_empty_string() {
    130         $u = $this->factory->user->create();
    131         $post_id = $this->factory->post->create( array( 'post_author' => $u ) );
    132 
    133         $data = array(
    134             'comment_post_ID'      => $post_id,
     152        $data = array(
     153            'comment_post_ID'      => self::$post_id,
    135154            'comment_author'       => rand_str(),
    136155            'comment_author_IP'    => '',
     
    152171     */
    153172    public function test_wp_new_comment_respects_comment_agent() {
    154         $u = $this->factory->user->create();
    155         $post_id = $this->factory->post->create( array( 'post_author' => $u ) );
    156 
    157         $data = array(
    158             'comment_post_ID'      => $post_id,
     173        $data = array(
     174            'comment_post_ID'      => self::$post_id,
    159175            'comment_author'       => rand_str(),
    160176            'comment_author_IP'    => '',
     
    177193     */
    178194    public function test_wp_new_comment_should_trim_provided_comment_agent_to_254_chars() {
    179         $u = $this->factory->user->create();
    180         $post_id = $this->factory->post->create( array( 'post_author' => $u ) );
    181 
    182         $data = array(
    183             'comment_post_ID'      => $post_id,
     195        $data = array(
     196            'comment_post_ID'      => self::$post_id,
    184197            'comment_author'       => rand_str(),
    185198            'comment_author_IP'    => '',
     
    202215     */
    203216    public function test_wp_new_comment_respects_comment_agent_empty_string() {
    204         $u = $this->factory->user->create();
    205         $post_id = $this->factory->post->create( array( 'post_author' => $u ) );
    206 
    207         $data = array(
    208             'comment_post_ID'      => $post_id,
     217        $data = array(
     218            'comment_post_ID'      => self::$post_id,
    209219            'comment_author'       => rand_str(),
    210220            'comment_author_IP'    => '',
     
    225235
    226236    public function test_comment_field_lengths() {
    227         $u = $this->factory->user->create();
    228         $post_id = $this->factory->post->create( array( 'post_author' => $u ) );
    229 
    230         $data = array(
    231             'comment_post_ID' => $post_id,
     237        $data = array(
     238            'comment_post_ID' => self::$post_id,
    232239            'comment_author' => rand_str(),
    233240            'comment_author_url' => '',
     
    265272     */
    266273    public function test_wp_new_comment_notify_postauthor_should_not_send_email_when_comment_has_been_marked_as_spam() {
    267         $p = $this->factory->post->create();
    268274        $c = $this->factory->comment->create( array(
    269             'comment_post_ID' => $p,
     275            'comment_post_ID' => self::$post_id,
    270276            'comment_approved' => 'spam',
    271277        ) );
     
    294300     */
    295301    public function test_wp_comment_get_children_should_fill_children() {
    296 
    297         $p = $this->factory->post->create();
    298 
    299302        $c1 = $this->factory->comment->create( array(
    300             'comment_post_ID' => $p,
     303            'comment_post_ID' => self::$post_id,
    301304            'comment_approved' => '1',
    302305        ) );
    303306
    304307        $c2 = $this->factory->comment->create( array(
    305             'comment_post_ID' => $p,
     308            'comment_post_ID' => self::$post_id,
    306309            'comment_approved' => '1',
    307310            'comment_parent' => $c1,
     
    309312
    310313        $c3 = $this->factory->comment->create( array(
    311             'comment_post_ID' => $p,
     314            'comment_post_ID' => self::$post_id,
    312315            'comment_approved' => '1',
    313316            'comment_parent' => $c2,
     
    315318
    316319        $c4 = $this->factory->comment->create( array(
    317             'comment_post_ID' => $p,
     320            'comment_post_ID' => self::$post_id,
    318321            'comment_approved' => '1',
    319322            'comment_parent' => $c1,
     
    321324
    322325        $c5 = $this->factory->comment->create( array(
    323             'comment_post_ID' => $p,
     326            'comment_post_ID' => self::$post_id,
    324327            'comment_approved' => '1',
    325328        ) );
    326329
    327330        $c6 = $this->factory->comment->create( array(
    328             'comment_post_ID' => $p,
     331            'comment_post_ID' => self::$post_id,
    329332            'comment_approved' => '1',
    330333            'comment_parent' => $c5,
     
    345348     */
    346349    public function test_post_properties_should_be_lazyloaded() {
    347         $p = $this->factory->post->create();
    348 
    349         $c = $this->factory->comment->create( array( 'comment_post_ID' => $p ) );
    350 
    351         $post = get_post( $p );
     350        $c = $this->factory->comment->create( array( 'comment_post_ID' => self::$post_id ) );
     351
     352        $post = get_post( self::$post_id );
    352353        $comment = get_comment( $c );
    353354
Note: See TracChangeset for help on using the changeset viewer.