WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/31/2015 08:12:16 PM (6 years ago)
Author:
wonderboymusic
Message:

Comments: don't auto-close comments on draft posts.

Adds unit tests.

Props solarissmoke, MikeHansenMe, nacin, rachelbaker.
Fixes #20262.

File:
1 edited

Legend:

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

    r35350 r35475  
    568568        return $email_sent_when_comment_approved || $email_sent_when_comment_added;
    569569    }
     570
     571    public function test_close_comments_for_old_post() {
     572        update_option( 'close_comments_for_old_posts', true );
     573        // Close comments more than one day old.
     574        update_option( 'close_comments_days_old', 1 );
     575
     576        $old_date = strtotime( '-25 hours' );
     577        $old_post_id = self::factory()->post->create( array( 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $old_date ) ) );
     578
     579        $old_post_comment_status = _close_comments_for_old_post( true, $old_post_id );
     580        $this->assertFalse( $old_post_comment_status );
     581
     582        $new_post_comment_status = _close_comments_for_old_post( true, self::$post_id );
     583        $this->assertTrue( $new_post_comment_status );
     584    }
     585
     586    public function test_close_comments_for_old_post_undated_draft() {
     587        $draft_id = self::factory()->post->create( array( 'post_status' => 'draft', 'post_type' => 'post' ) );
     588        $draft_comment_status = _close_comments_for_old_post( true, $draft_id );
     589
     590        $this->assertTrue( $draft_comment_status );
     591    }
    570592}
Note: See TracChangeset for help on using the changeset viewer.