WordPress.org

Make WordPress Core

Ticket #35006: 35006.2.diff

File 35006.2.diff, 2.0 KB (added by swissspidy, 5 years ago)
  • src/wp-includes/comment.php

    diff --git src/wp-includes/comment.php src/wp-includes/comment.php
    index a84f0a7..2a94ec1 100644
    function wp_new_comment_notify_postauthor( $comment_ID ) { 
    18021802        }
    18031803
    18041804        // Only send notifications for approved comments.
    1805         if ( ! isset( $comment->comment_approved ) || 'spam' === $comment->comment_approved || ! $comment->comment_approved ) {
     1805        if ( ! isset( $comment->comment_approved ) || '1' != $comment->comment_approved ) {
    18061806                return false;
    18071807        }
    18081808
  • tests/phpunit/tests/comment.php

    diff --git tests/phpunit/tests/comment.php tests/phpunit/tests/comment.php
    index 844e4d1..8386881 100644
    class Tests_Comment extends WP_UnitTestCase { 
    293293                $this->assertTrue( wp_notify_moderator( $c ) );
    294294        }
    295295
     296        public function test_wp_new_comment_notify_postauthor_should_send_email_when_comment_is_approved() {
     297                $c = self::factory()->comment->create( array(
     298                        'comment_post_ID' => self::$post_id,
     299                ) );
     300
     301                $sent = wp_new_comment_notify_postauthor( $c );
     302                $this->assertTrue( $sent );
     303        }
     304
     305        public function test_wp_new_comment_notify_postauthor_should_not_send_email_when_comment_is_unapproved() {
     306                $c = self::factory()->comment->create( array(
     307                        'comment_post_ID' => self::$post_id,
     308                        'comment_approved' => '0',
     309                ) );
     310
     311                $sent = wp_new_comment_notify_postauthor( $c );
     312                $this->assertFalse( $sent );
     313        }
     314
    296315        /**
    297316         * @ticket 33587
    298317         */
    class Tests_Comment extends WP_UnitTestCase { 
    307326        }
    308327
    309328        /**
     329         * @ticket 35006
     330         */
     331        public function test_wp_new_comment_notify_postauthor_should_not_send_email_when_comment_has_been_trashed() {
     332                $c = self::factory()->comment->create( array(
     333                        'comment_post_ID' => self::$post_id,
     334                        'comment_approved' => 'trash',
     335                ) );
     336
     337                $sent = wp_new_comment_notify_postauthor( $c );
     338                $this->assertFalse( $sent );
     339        }
     340
     341        /**
    310342         * @ticket 12431
    311343         */
    312344        public function test_wp_new_comment_with_meta() {