mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
Clarify that get_the_date(), get_the_time(), get_post_time() and get_post_modified_time() should return false when get_post() is null.
Adds unit tests. Props GaryJ, SergeyBiryukov, tollmanz. Fixes #28310. git-svn-id: https://develop.svn.wordpress.org/trunk@29344 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -874,6 +874,163 @@ class Tests_Post extends WP_UnitTestCase {
|
||||
$this->assertEquals( 'March 1, 2014', get_the_date( 'F j, Y', $post_id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_get_the_date_returns_false_with_null_post() {
|
||||
$this->assertFalse( get_the_date() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_get_the_date_returns_false_with_format_and_null_post() {
|
||||
$this->assertFalse( get_the_date( 'F j, Y h:i:s' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_get_the_date_returns_false_with_post_that_is_not_found() {
|
||||
$this->assertFalse( get_the_date( '', 9 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_get_the_date_returns_false_with_format_and_post_that_is_not_found() {
|
||||
$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 = $this->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_post() {
|
||||
$this->assertFalse( get_the_time() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_get_the_time_returns_false_with_format_and_null_post() {
|
||||
$this->assertFalse( get_the_time( 'h:i:s' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_get_the_time_returns_false_with_post_that_is_not_found() {
|
||||
$this->assertFalse( get_the_time( '', 9 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_get_the_time_returns_false_with_format_and_post_that_is_not_found() {
|
||||
$this->assertFalse( get_the_time( 'h:i:s', 9 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_get_post_time_with_id_returns_correct_time() {
|
||||
$post_id = $this->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_post() {
|
||||
$this->assertFalse( get_post_time() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_get_post_time_returns_false_with_format_and_null_post() {
|
||||
$this->assertFalse( get_post_time( 'h:i:s' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_get_post_time_returns_false_with_post_that_is_not_found() {
|
||||
$this->assertFalse( get_post_time( '', false, 9 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_get_post_time_returns_false_with_format_and_post_that_is_not_found() {
|
||||
$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 = $this->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_post() {
|
||||
$this->assertFalse( get_post_modified_time() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_get_post_modified_time_returns_false_with_format_and_null_post() {
|
||||
$this->assertFalse( get_post_modified_time( 'h:i:s' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_get_post_modified_time_returns_false_with_post_that_is_not_found() {
|
||||
$this->assertFalse( get_post_modified_time( '', false, 9 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_get_post_modified_time_returns_false_with_format_and_post_that_is_not_found() {
|
||||
$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_unix_timestamp() {
|
||||
$this->assertEquals( '441013392', mysql2date( 'G', '1983-12-23 07:43:12' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28310
|
||||
*/
|
||||
function test_mysql2date_returns_unix_timestamp() {
|
||||
$this->assertEquals( '441013392', mysql2date( 'U', '1983-12-23 07:43:12' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 25566
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user