From 34dc1cc2c97a1638abb4c3d4356c01f704331421 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 31 Aug 2020 15:33:45 +0000 Subject: [PATCH] Tests: Bring some consistency to Date/Time tests: * Move some tests from `post.php` to a more appropriate location in the `date` directory. * Rename `date/postTime.php` to `date/getPostTime.php` to match the function name. Props Rarst. See #51184. git-svn-id: https://develop.svn.wordpress.org/trunk@48911 602fd350-edb4-49c9-b593-d223f7449a82 --- .../date/{postTime.php => getPostTime.php} | 39 ++++++++- tests/phpunit/tests/date/getTheDate.php | 45 ++++++++++ tests/phpunit/tests/date/mysql2date.php | 15 ++++ tests/phpunit/tests/date/theDate.php | 1 + tests/phpunit/tests/post.php | 87 ------------------- 5 files changed, 99 insertions(+), 88 deletions(-) rename tests/phpunit/tests/date/{postTime.php => getPostTime.php} (70%) create mode 100644 tests/phpunit/tests/date/getTheDate.php diff --git a/tests/phpunit/tests/date/postTime.php b/tests/phpunit/tests/date/getPostTime.php similarity index 70% rename from tests/phpunit/tests/date/postTime.php rename to tests/phpunit/tests/date/getPostTime.php index 1380c48160..c28add1450 100644 --- a/tests/phpunit/tests/date/postTime.php +++ b/tests/phpunit/tests/date/getPostTime.php @@ -3,8 +3,45 @@ /** * @group date * @group datetime + * @group post */ -class Tests_Date_Post_Time extends WP_UnitTestCase { +class Tests_Date_Get_Post_Time extends WP_UnitTestCase { + + /** + * @ticket 28310 + */ + public function test_get_post_time_with_id_returns_correct_time() { + $post_id = self::factory()->post->create( array( 'post_date' => '2014-03-01 16:35:00' ) ); + $this->assertEquals( '16:35:00', get_post_time( 'H:i:s', false, $post_id ) ); + } + + /** + * @ticket 28310 + */ + public function test_get_post_time_returns_false_with_null_or_non_existing_post() { + $this->assertFalse( get_post_time() ); + $this->assertFalse( get_post_time( 'h:i:s' ) ); + $this->assertFalse( get_post_time( '', false, 9 ) ); + $this->assertFalse( get_post_time( 'h:i:s', false, 9 ) ); + } + + /** + * @ticket 28310 + */ + public function test_get_post_modified_time_with_id_returns_correct_time() { + $post_id = self::factory()->post->create( array( 'post_date' => '2014-03-01 16:35:00' ) ); + $this->assertEquals( '16:35:00', get_post_modified_time( 'H:i:s', false, $post_id ) ); + } + + /** + * @ticket 28310 + */ + public function test_get_post_modified_time_returns_false_with_null_or_non_existing_post() { + $this->assertFalse( get_post_modified_time() ); + $this->assertFalse( get_post_modified_time( 'h:i:s' ) ); + $this->assertFalse( get_post_modified_time( '', false, 9 ) ); + $this->assertFalse( get_post_modified_time( 'h:i:s', false, 9 ) ); + } /** * @ticket 25002 diff --git a/tests/phpunit/tests/date/getTheDate.php b/tests/phpunit/tests/date/getTheDate.php new file mode 100644 index 0000000000..03248dba5f --- /dev/null +++ b/tests/phpunit/tests/date/getTheDate.php @@ -0,0 +1,45 @@ +post->create( array( 'post_date' => '2014-03-01 16:35:00' ) ); + $this->assertEquals( 'March 1, 2014', get_the_date( 'F j, Y', $post_id ) ); + } + + /** + * @ticket 28310 + */ + 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 ) ); + $this->assertFalse( get_the_date( 'F j, Y h:i:s', 9 ) ); + } + + /** + * @ticket 28310 + */ + function test_get_the_time_with_id_returns_correct_time() { + $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 ) ); + } + + /** + * @ticket 28310 + */ + 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 ) ); + $this->assertFalse( get_the_time( 'h:i:s', 9 ) ); + } +} diff --git a/tests/phpunit/tests/date/mysql2date.php b/tests/phpunit/tests/date/mysql2date.php index 25b0784e26..863f812d89 100644 --- a/tests/phpunit/tests/date/mysql2date.php +++ b/tests/phpunit/tests/date/mysql2date.php @@ -13,6 +13,21 @@ class Tests_Date_mysql2date extends WP_UnitTestCase { parent::tearDown(); } + /** + * @ticket 28310 + */ + function test_mysql2date_returns_false_with_no_date() { + $this->assertFalse( mysql2date( 'F j, Y H:i:s', '' ) ); + } + + /** + * @ticket 28310 + */ + function test_mysql2date_returns_gmt_or_unix_timestamp() { + $this->assertEquals( '441013392', mysql2date( 'G', '1983-12-23 07:43:12' ) ); + $this->assertEquals( '441013392', mysql2date( 'U', '1983-12-23 07:43:12' ) ); + } + /** * @ticket 28992 */ diff --git a/tests/phpunit/tests/date/theDate.php b/tests/phpunit/tests/date/theDate.php index 2542240d6b..46fff6709e 100644 --- a/tests/phpunit/tests/date/theDate.php +++ b/tests/phpunit/tests/date/theDate.php @@ -3,6 +3,7 @@ /** * @group date * @group datetime + * @group post */ class Tests_Date_The_Date extends WP_UnitTestCase { diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index 14cfb31d16..3b5af7bad4 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -895,93 +895,6 @@ class Tests_Post extends WP_UnitTestCase { $this->assertEquals( 0, $counts->test ); } - /** - * @ticket 13771 - */ - function test_get_the_date_with_id_returns_correct_time() { - $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 ) ); - } - - /** - * @ticket 28310 - */ - 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 ) ); - $this->assertFalse( get_the_date( 'F j, Y h:i:s', 9 ) ); - } - - /** - * @ticket 28310 - */ - function test_get_the_time_with_id_returns_correct_time() { - $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 ) ); - } - - /** - * @ticket 28310 - */ - 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 ) ); - $this->assertFalse( get_the_time( 'h:i:s', 9 ) ); - } - - /** - * @ticket 28310 - */ - function test_get_post_time_with_id_returns_correct_time() { - $post_id = self::factory()->post->create( array( 'post_date' => '2014-03-01 16:35:00' ) ); - $this->assertEquals( '16:35:00', get_post_time( 'H:i:s', false, $post_id ) ); - } - - /** - * @ticket 28310 - */ - function test_get_post_time_returns_false_with_null_or_non_existing_post() { - $this->assertFalse( get_post_time() ); - $this->assertFalse( get_post_time( 'h:i:s' ) ); - $this->assertFalse( get_post_time( '', false, 9 ) ); - $this->assertFalse( get_post_time( 'h:i:s', false, 9 ) ); - } - - /** - * @ticket 28310 - */ - function test_get_post_modified_time_with_id_returns_correct_time() { - $post_id = self::factory()->post->create( array( 'post_date' => '2014-03-01 16:35:00' ) ); - $this->assertEquals( '16:35:00', get_post_modified_time( 'H:i:s', false, $post_id ) ); - } - - /** - * @ticket 28310 - */ - function test_get_post_modified_time_returns_false_with_null_or_non_existing_post() { - $this->assertFalse( get_post_modified_time() ); - $this->assertFalse( get_post_modified_time( 'h:i:s' ) ); - $this->assertFalse( get_post_modified_time( '', false, 9 ) ); - $this->assertFalse( get_post_modified_time( 'h:i:s', false, 9 ) ); - } - - /** - * @ticket 28310 - */ - function test_mysql2date_returns_false_with_no_date() { - $this->assertFalse( mysql2date( 'F j, Y H:i:s', '' ) ); - } - - /** - * @ticket 28310 - */ - function test_mysql2date_returns_gmt_or_unix_timestamp() { - $this->assertEquals( '441013392', mysql2date( 'G', '1983-12-23 07:43:12' ) ); - $this->assertEquals( '441013392', mysql2date( 'U', '1983-12-23 07:43:12' ) ); - } - /** * @ticket 25566 */