From 699e44cc76200c006f168391b71f393cda9fbec6 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 31 Aug 2020 22:41:02 +0000 Subject: [PATCH] Tests: Move the tests for `get_the_modified_time()` to a more appropriate place. Add some new tests to better cover the functionality, for consistency with `get_the_date()` and `get_the_time()`. Follow-up to [48911], [48912], [48918]. Props wittich. Fixes #51184. git-svn-id: https://develop.svn.wordpress.org/trunk@48924 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/date/getCommentDate.php | 8 +- tests/phpunit/tests/date/getTheDate.php | 12 +- .../phpunit/tests/date/getTheModifiedDate.php | 191 ++++++++++++++++++ tests/phpunit/tests/general/template.php | 142 ------------- 4 files changed, 201 insertions(+), 152 deletions(-) create mode 100644 tests/phpunit/tests/date/getTheModifiedDate.php diff --git a/tests/phpunit/tests/date/getCommentDate.php b/tests/phpunit/tests/date/getCommentDate.php index 5369d96326..e1d0834025 100644 --- a/tests/phpunit/tests/date/getCommentDate.php +++ b/tests/phpunit/tests/date/getCommentDate.php @@ -10,7 +10,7 @@ class Tests_Date_Get_Comment_Date extends WP_UnitTestCase { /** * @ticket 51184 */ - function test_get_comment_date_returns_correct_time_with_comment_id() { + public function test_get_comment_date_returns_correct_time_with_comment_id() { $c = self::factory()->comment->create( array( 'comment_date' => '2020-08-29 01:51:00' ) ); $this->assertEquals( 'August 29, 2020', get_comment_date( 'F j, Y', $c ) ); @@ -19,7 +19,7 @@ class Tests_Date_Get_Comment_Date extends WP_UnitTestCase { /** * @ticket 51184 */ - function test_get_comment_date_returns_correct_time_with_empty_format() { + public function test_get_comment_date_returns_correct_time_with_empty_format() { $c = self::factory()->comment->create( array( 'comment_date' => '2020-08-29 01:51:00' ) ); $this->assertEquals( 'August 29, 2020', get_comment_date( '', $c ) ); @@ -29,7 +29,7 @@ class Tests_Date_Get_Comment_Date extends WP_UnitTestCase { /** * @ticket 51184 */ - function test_get_comment_time_returns_correct_time() { + public function test_get_comment_time_returns_correct_time() { $c = self::factory()->comment->create( array( 'comment_date' => '2020-08-29 01:51:00' ) ); $GLOBALS['comment'] = get_comment( $c ); @@ -39,7 +39,7 @@ class Tests_Date_Get_Comment_Date extends WP_UnitTestCase { /** * @ticket 51184 */ - function test_get_comment_time_returns_correct_time_with_empty_format() { + public function test_get_comment_time_returns_correct_time_with_empty_format() { $c = self::factory()->comment->create( array( 'comment_date' => '2020-08-29 01:51:00' ) ); $GLOBALS['comment'] = get_comment( $c ); diff --git a/tests/phpunit/tests/date/getTheDate.php b/tests/phpunit/tests/date/getTheDate.php index 2e45cd9c39..778936684c 100644 --- a/tests/phpunit/tests/date/getTheDate.php +++ b/tests/phpunit/tests/date/getTheDate.php @@ -10,7 +10,7 @@ class Tests_Date_Get_The_Date extends WP_UnitTestCase { /** * @ticket 13771 */ - function test_get_the_date_returns_correct_time_with_post_id() { + public function test_get_the_date_returns_correct_time_with_post_id() { $post_id = self::factory()->post->create( array( 'post_date' => '2014-03-01 16:35:00' ) ); $this->assertEquals( 'March 1, 2014', get_the_date( 'F j, Y', $post_id ) ); @@ -19,7 +19,7 @@ class Tests_Date_Get_The_Date extends WP_UnitTestCase { /** * @ticket 28310 */ - function test_get_the_date_returns_false_with_null_or_non_existing_post() { + public function test_get_the_date_returns_false_with_null_or_non_existing_post() { $this->assertFalse( get_the_date() ); $this->assertFalse( get_the_date( 'F j, Y h:i:s' ) ); $this->assertFalse( get_the_date( '', 9 ) ); @@ -29,7 +29,7 @@ class Tests_Date_Get_The_Date extends WP_UnitTestCase { /** * @ticket 51184 */ - function test_get_the_date_returns_correct_time_with_empty_format() { + public function test_get_the_date_returns_correct_time_with_empty_format() { $post_id = self::factory()->post->create( array( 'post_date' => '2020-08-29 01:51:00' ) ); $this->assertEquals( 'August 29, 2020', get_the_date( '', $post_id ) ); @@ -39,7 +39,7 @@ class Tests_Date_Get_The_Date extends WP_UnitTestCase { /** * @ticket 28310 */ - function test_get_the_time_returns_correct_time_with_post_id() { + public function test_get_the_time_returns_correct_time_with_post_id() { $post_id = self::factory()->post->create( array( 'post_date' => '2014-03-01 16:35:00' ) ); $this->assertEquals( '16:35:00', get_the_time( 'H:i:s', $post_id ) ); @@ -48,7 +48,7 @@ class Tests_Date_Get_The_Date extends WP_UnitTestCase { /** * @ticket 28310 */ - function test_get_the_time_returns_false_with_null_or_non_existing_post() { + public function test_get_the_time_returns_false_with_null_or_non_existing_post() { $this->assertFalse( get_the_time() ); $this->assertFalse( get_the_time( 'h:i:s' ) ); $this->assertFalse( get_the_time( '', 9 ) ); @@ -58,7 +58,7 @@ class Tests_Date_Get_The_Date extends WP_UnitTestCase { /** * @ticket 51184 */ - function test_get_the_time_returns_correct_time_with_empty_format() { + public function test_get_the_time_returns_correct_time_with_empty_format() { $post_id = self::factory()->post->create( array( 'post_date' => '2020-08-29 01:51:00' ) ); $this->assertEquals( '1:51 am', get_the_time( '', $post_id ) ); diff --git a/tests/phpunit/tests/date/getTheModifiedDate.php b/tests/phpunit/tests/date/getTheModifiedDate.php new file mode 100644 index 0000000000..9f104ae61a --- /dev/null +++ b/tests/phpunit/tests/date/getTheModifiedDate.php @@ -0,0 +1,191 @@ + '2016-01-21 15:34:36', + 'post_date_gmt' => '2016-01-21 15:34:36', + ); + $post_id = $this->factory->post->create( $details ); + $format = 'Y-m-d'; + $expected = '2016-01-21'; + $actual = get_the_modified_date( $format, $post_id ); + $this->assertEquals( $expected, $actual ); + } + + /** + * Test get_the_modified_date + * + * @ticket 37059 + * + * @since 4.6.0 + */ + public function test_get_the_modified_date_default() { + $details = array( + 'post_date' => '2016-01-21 15:34:36', + 'post_date_gmt' => '2016-01-21 15:34:36', + ); + $post_id = $this->factory->post->create( $details ); + $post = get_post( $post_id ); + + $GLOBALS['post'] = $post; + + $expected = '2016-01-21'; + $format = 'Y-m-d'; + $actual = get_the_modified_date( $format ); + $this->assertEquals( $expected, $actual ); + } + + /** + * Test get_the_modified_date failures are filtered + * + * @ticket 37059 + * + * @since 4.6.0 + */ + public function test_get_the_modified_date_failures_are_filtered() { + // Remove global post object. + $GLOBALS['post'] = null; + + $expected = 'filtered modified date failure result'; + add_filter( 'get_the_modified_date', array( $this, '_filter_get_the_modified_date_failure' ) ); + $actual = get_the_modified_date(); + $this->assertEquals( $expected, $actual ); + remove_filter( 'get_the_modified_date', array( $this, '_filter_get_the_modified_date_failure' ) ); + } + + public function _filter_get_the_modified_date_failure( $the_date ) { + $expected = false; + $actual = $the_date; + $this->assertEquals( $expected, $actual ); + + if ( false === $the_date ) { + return 'filtered modified date failure result'; + } + return $the_date; + } + + /** + * @ticket 51184 + */ + public function test_get_the_modified_date_returns_false_with_null_or_non_existing_post() { + $this->assertFalse( get_the_modified_date() ); + $this->assertFalse( get_the_modified_date( 'F j, Y h:i:s' ) ); + $this->assertFalse( get_the_modified_date( '', 9 ) ); + $this->assertFalse( get_the_modified_date( 'F j, Y h:i:s', 9 ) ); + } + + /** + * @ticket 51184 + */ + public function test_get_the_modified_date_returns_correct_time_with_empty_format() { + $post_id = self::factory()->post->create( array( 'post_date' => '2020-08-31 23:14:00' ) ); + + $this->assertEquals( 'August 31, 2020', get_the_modified_date( '', $post_id ) ); + $this->assertEquals( 'August 31, 2020', get_the_modified_date( false, $post_id ) ); + } + + /** + * Test get_the_modified_time with post_id parameter. + * + * @ticket 37059 + * + * @since 4.6.0 + */ + public function test_get_the_modified_time_with_post_id() { + $details = array( + 'post_date' => '2016-01-21 15:34:36', + 'post_date_gmt' => '2016-01-21 15:34:36', + ); + $post_id = $this->factory->post->create( $details ); + $format = 'G'; + $expected = '1453390476'; + $actual = get_the_modified_time( $format, $post_id ); + $this->assertEquals( $expected, $actual ); + } + + /** + * Test get_the_modified_time + * + * @ticket 37059 + * + * @since 4.6.0 + */ + public function test_get_the_modified_time_default() { + $details = array( + 'post_date' => '2016-01-21 15:34:36', + 'post_date_gmt' => '2016-01-21 15:34:36', + ); + $post_id = $this->factory->post->create( $details ); + $post = get_post( $post_id ); + + $GLOBALS['post'] = $post; + + $expected = '1453390476'; + $format = 'G'; + $actual = get_the_modified_time( $format ); + $this->assertEquals( $expected, $actual ); + } + + /** + * Test get_the_modified_time failures are filtered + * + * @ticket 37059 + * + * @since 4.6.0 + */ + public function test_get_the_modified_time_failures_are_filtered() { + // Remove global post object. + $GLOBALS['post'] = null; + + $expected = 'filtered modified time failure result'; + add_filter( 'get_the_modified_time', array( $this, '_filter_get_the_modified_time_failure' ) ); + $actual = get_the_modified_time(); + $this->assertEquals( $expected, $actual ); + remove_filter( 'get_the_modified_time', array( $this, '_filter_get_the_modified_time_failure' ) ); + } + + public function _filter_get_the_modified_time_failure( $the_time ) { + $expected = false; + $actual = $the_time; + $this->assertEquals( $expected, $actual ); + + if ( false === $the_time ) { + return 'filtered modified time failure result'; + } + return $the_time; + } + + /** + * @ticket 51184 + */ + public function test_get_the_modified_time_returns_false_with_null_or_non_existing_post() { + $this->assertFalse( get_the_modified_time() ); + $this->assertFalse( get_the_modified_time( 'h:i:s' ) ); + $this->assertFalse( get_the_modified_time( '', 9 ) ); + $this->assertFalse( get_the_modified_time( 'h:i:s', 9 ) ); + } + + /** + * @ticket 51184 + */ + public function test_get_the_modified_time_returns_correct_time_with_empty_format() { + $post_id = self::factory()->post->create( array( 'post_date' => '2020-08-31 23:14:00' ) ); + + $this->assertEquals( '11:14 pm', get_the_modified_time( '', $post_id ) ); + $this->assertEquals( '11:14 pm', get_the_modified_time( false, $post_id ) ); + } +} diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php index 8c4a2b003a..e6c3d104f9 100644 --- a/tests/phpunit/tests/general/template.php +++ b/tests/phpunit/tests/general/template.php @@ -417,148 +417,6 @@ class Tests_General_Template extends WP_UnitTestCase { return $this->custom_logo_id; } - /** - * Test get_the_modified_time - * - * @ticket 37059 - * - * @since 4.6.0 - */ - function test_get_the_modified_time_default() { - $details = array( - 'post_date' => '2016-01-21 15:34:36', - 'post_date_gmt' => '2016-01-21 15:34:36', - ); - $post_id = $this->factory->post->create( $details ); - $post = get_post( $post_id ); - - $GLOBALS['post'] = $post; - - $expected = '1453390476'; - $format = 'G'; - $actual = get_the_modified_time( $format ); - $this->assertEquals( $expected, $actual ); - } - - /** - * Test get_the_modified_time failures are filtered - * - * @ticket 37059 - * - * @since 4.6.0 - */ - function test_get_the_modified_time_failures_are_filtered() { - // Remove global post object. - $GLOBALS['post'] = null; - - $expected = 'filtered modified time failure result'; - add_filter( 'get_the_modified_time', array( $this, '_filter_get_the_modified_time_failure' ) ); - $actual = get_the_modified_time(); - $this->assertEquals( $expected, $actual ); - remove_filter( 'get_the_modified_time', array( $this, '_filter_get_the_modified_time_failure' ) ); - } - - function _filter_get_the_modified_time_failure( $the_time ) { - $expected = false; - $actual = $the_time; - $this->assertEquals( $expected, $actual ); - - if ( false === $the_time ) { - return 'filtered modified time failure result'; - } - return $the_time; - } - - /** - * Test get_the_modified_time with post_id parameter. - * - * @ticket 37059 - * - * @since 4.6.0 - */ - function test_get_the_modified_date_with_post_id() { - $details = array( - 'post_date' => '2016-01-21 15:34:36', - 'post_date_gmt' => '2016-01-21 15:34:36', - ); - $post_id = $this->factory->post->create( $details ); - $format = 'Y-m-d'; - $expected = '2016-01-21'; - $actual = get_the_modified_date( $format, $post_id ); - $this->assertEquals( $expected, $actual ); - } - - /** - * Test get_the_modified_date - * - * @ticket 37059 - * - * @since 4.6.0 - */ - function test_get_the_modified_date_default() { - $details = array( - 'post_date' => '2016-01-21 15:34:36', - 'post_date_gmt' => '2016-01-21 15:34:36', - ); - $post_id = $this->factory->post->create( $details ); - $post = get_post( $post_id ); - - $GLOBALS['post'] = $post; - - $expected = '2016-01-21'; - $format = 'Y-m-d'; - $actual = get_the_modified_date( $format ); - $this->assertEquals( $expected, $actual ); - } - - /** - * Test get_the_modified_date failures are filtered - * - * @ticket 37059 - * - * @since 4.6.0 - */ - function test_get_the_modified_date_failures_are_filtered() { - // Remove global post object. - $GLOBALS['post'] = null; - - $expected = 'filtered modified date failure result'; - add_filter( 'get_the_modified_date', array( $this, '_filter_get_the_modified_date_failure' ) ); - $actual = get_the_modified_date(); - $this->assertEquals( $expected, $actual ); - remove_filter( 'get_the_modified_date', array( $this, '_filter_get_the_modified_date_failure' ) ); - } - - function _filter_get_the_modified_date_failure( $the_date ) { - $expected = false; - $actual = $the_date; - $this->assertEquals( $expected, $actual ); - - if ( false === $the_date ) { - return 'filtered modified date failure result'; - } - return $the_date; - } - - /** - * Test get_the_modified_time with post_id parameter. - * - * @ticket 37059 - * - * @since 4.6.0 - */ - function test_get_the_modified_time_with_post_id() { - $details = array( - 'post_date' => '2016-01-21 15:34:36', - 'post_date_gmt' => '2016-01-21 15:34:36', - ); - $post_id = $this->factory->post->create( $details ); - $format = 'G'; - $expected = '1453390476'; - $actual = get_the_modified_time( $format, $post_id ); - $this->assertEquals( $expected, $actual ); - } - /** * @ticket 38253 * @group ms-required