WordPress.org

Make WordPress Core

Ticket #20262: 20262.6.diff

File 20262.6.diff, 1.8 KB (added by rachelbaker, 5 years ago)

Correcting unit test factory methods from 20262.5.diff to get the id

  • src/wp-includes/comment-functions.php

     
    25922592        if ( ! in_array( $post->post_type, $post_types ) )
    25932593                return $open;
    25942594
     2595        // Undated drafts should not show up as comments closed.
     2596        if ( $post->post_date_gmt === '0000-00-00 00:00:00' ) {
     2597                return $open;
     2598        }
     2599
    25952600        if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) )
    25962601                return false;
    25972602
  • tests/phpunit/tests/comment.php

     
    567567
    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}