| 438 | /** |
| 439 | * @ticket 43805 |
| 440 | */ |
| 441 | public function test_wp_new_comment_notify_postauthor_content_should_include_link_to_parent() { |
| 442 | self::$notify_message = ''; |
| 443 | |
| 444 | $c = self::factory()->comment->create( |
| 445 | array( |
| 446 | 'comment_post_ID' => self::$post_id, |
| 447 | ) |
| 448 | ); |
| 449 | |
| 450 | $r = self::factory()->comment->create( |
| 451 | array( |
| 452 | 'comment_post_ID' => self::$post_id, |
| 453 | 'comment_parent' => $c, |
| 454 | ) |
| 455 | ); |
| 456 | |
| 457 | add_filter( 'comment_notification_text', array( $this, 'comment_notification_text_get' ), 10, 1 ); |
| 458 | $sent = wp_new_comment_notify_postauthor( $r ); |
| 459 | remove_filter( 'comment_notification_text', array( $this, 'comment_notification_text_get' ), 10, 1 ); |
| 460 | |
| 461 | $pattern = addcslashes( admin_url( "comment.php?action=editcomment&c={$c}" ), '/?&' ); |
| 462 | |
| 463 | $this->assertEquals( 1, preg_match( '/' . $pattern . '/', self::$notify_message ) ); |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * @ticket 43805 |
| 468 | */ |
| 469 | public function test_wp_new_comment_notify_postauthor_content_shouldnot_include_link_to_parent() { |
| 470 | self::$notify_message = ''; |
| 471 | |
| 472 | $c = self::factory()->comment->create( |
| 473 | array( |
| 474 | 'comment_post_ID' => self::$post_id, |
| 475 | ) |
| 476 | ); |
| 477 | |
| 478 | add_filter( 'comment_notification_text', array( $this, 'comment_notification_text_get' ), 10, 1 ); |
| 479 | $sent = wp_new_comment_notify_postauthor( $c ); |
| 480 | remove_filter( 'comment_notification_text', array( $this, 'comment_notification_text_get' ), 10, 1 ); |
| 481 | |
| 482 | $pattern = addcslashes( admin_url( "comment.php?action=editcomment&c={$c}" ), '/?&' ); |
| 483 | |
| 484 | $this->assertNotEquals( 1, preg_match( '/' . $pattern . '/', self::$notify_message ) ); |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * @ticket 43805 |
| 489 | */ |
| 490 | public function test_wp_new_comment_notify_moderator_content_should_include_link_to_parent() { |
| 491 | self::$notify_message = ''; |
| 492 | |
| 493 | $c = self::factory()->comment->create( |
| 494 | array( |
| 495 | 'comment_post_ID' => self::$post_id, |
| 496 | ) |
| 497 | ); |
| 498 | |
| 499 | $r = self::factory()->comment->create( |
| 500 | array( |
| 501 | 'comment_post_ID' => self::$post_id, |
| 502 | 'comment_parent' => $c, |
| 503 | 'comment_approved' => '0', |
| 504 | ) |
| 505 | ); |
| 506 | |
| 507 | add_filter( 'comment_moderation_text', array( $this, 'comment_notification_text_get' ), 10, 1 ); |
| 508 | $sent = wp_new_comment_notify_moderator( $r ); |
| 509 | remove_filter( 'comment_moderation_text', array( $this, 'comment_notification_text_get' ), 10, 1 ); |
| 510 | |
| 511 | $pattern = addcslashes( admin_url( "comment.php?action=editcomment&c={$c}" ), '/?&' ); |
| 512 | |
| 513 | $this->assertEquals( 1, preg_match( '/' . $pattern . '/', self::$notify_message ) ); |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * @ticket 43805 |
| 518 | */ |
| 519 | public function test_wp_new_comment_notify_moderator_content_shouldnot_include_link_to_parent() { |
| 520 | self::$notify_message = ''; |
| 521 | |
| 522 | $c = self::factory()->comment->create( |
| 523 | array( |
| 524 | 'comment_post_ID' => self::$post_id, |
| 525 | 'comment_approved' => '0' |
| 526 | ) |
| 527 | ); |
| 528 | |
| 529 | add_filter( 'comment_moderation_text', array( $this, 'comment_notification_text_get' ), 10, 1 ); |
| 530 | $sent = wp_new_comment_notify_moderator( $c ); |
| 531 | remove_filter( 'comment_moderation_text', array( $this, 'comment_notification_text_get' ), 10, 1 ); |
| 532 | |
| 533 | $pattern = addcslashes( admin_url( "comment.php?action=editcomment&c={$c}" ), '/?&' ); |
| 534 | |
| 535 | $this->assertNotEquals( 1, preg_match( '/' . $pattern . '/', self::$notify_message ) ); |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * Callback for the `comment_notification_text` & `comment_moderation_text` filters. |
| 540 | * |
| 541 | * @param string $notify_message The comment notification or moderation email text. |
| 542 | * @return string |
| 543 | */ |
| 544 | public function comment_notification_text_get( $notify_message = '' ) { |
| 545 | self::$notify_message = $notify_message; |
| 546 | return $notify_message; |
| 547 | } |
| 548 | |