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. Merges [48911] to the 5.5 branch. See #51184. git-svn-id: https://develop.svn.wordpress.org/branches/5.5@48920 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
5e7d0e50bf
commit
0318feb679
@ -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
|
45
tests/phpunit/tests/date/getTheDate.php
Normal file
45
tests/phpunit/tests/date/getTheDate.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group date
|
||||
* @group datetime
|
||||
* @group post
|
||||
*/
|
||||
class Tests_Date_Get_The_Date extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @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 ) );
|
||||
}
|
||||
}
|
@ -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
|
||||
*/
|
||||
|
@ -3,6 +3,7 @@
|
||||
/**
|
||||
* @group date
|
||||
* @group datetime
|
||||
* @group post
|
||||
*/
|
||||
class Tests_Date_The_Date extends WP_UnitTestCase {
|
||||
|
||||
|
@ -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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user