includesComment.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * @group admin
  4. * @group comment
  5. */
  6. class Tests_Admin_IncludesComment extends WP_UnitTestCase {
  7. /**
  8. * Post ID to add comments to.
  9. *
  10. * @var int
  11. */
  12. public static $post_id;
  13. /**
  14. * Comment IDs.
  15. *
  16. * @var array
  17. */
  18. public static $comment_ids = array();
  19. /**
  20. * Create the post and comments for the tests.
  21. *
  22. * @param WP_UnitTest_Factory $factory
  23. */
  24. public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
  25. self::$post_id = $factory->post->create();
  26. self::$comment_ids[] = $factory->comment->create(
  27. array(
  28. 'comment_author' => 1,
  29. 'comment_date' => '2014-05-06 12:00:00',
  30. 'comment_date_gmt' => '2014-05-06 07:00:00',
  31. 'comment_post_ID' => self::$post_id,
  32. )
  33. );
  34. self::$comment_ids[] = $factory->comment->create(
  35. array(
  36. 'comment_author' => 2,
  37. 'comment_date' => '2004-01-02 12:00:00',
  38. 'comment_post_ID' => self::$post_id,
  39. )
  40. );
  41. }
  42. /**
  43. * Verify that both the comment date and author must match for a comment to exist.
  44. */
  45. public function test_must_match_date_and_author() {
  46. $this->assertNull( comment_exists( 1, '2004-01-02 12:00:00' ) );
  47. $this->assertEquals( self::$post_id, comment_exists( 1, '2014-05-06 12:00:00' ) );
  48. }
  49. /**
  50. * @ticket 33871
  51. */
  52. public function test_default_value_of_timezone_should_be_blog() {
  53. $this->assertEquals( self::$post_id, comment_exists( 1, '2014-05-06 12:00:00' ) );
  54. }
  55. /**
  56. * @ticket 33871
  57. */
  58. public function test_should_respect_timezone_blog() {
  59. $this->assertEquals( self::$post_id, comment_exists( 1, '2014-05-06 12:00:00', 'blog' ) );
  60. }
  61. /**
  62. * @ticket 33871
  63. */
  64. public function test_should_respect_timezone_gmt() {
  65. $this->assertEquals( self::$post_id, comment_exists( 1, '2014-05-06 07:00:00', 'gmt' ) );
  66. }
  67. /**
  68. * @ticket 33871
  69. */
  70. public function test_invalid_timezone_should_fall_back_on_blog() {
  71. $this->assertEquals( self::$post_id, comment_exists( 1, '2014-05-06 12:00:00', 'not_a_valid_value' ) );
  72. }
  73. }