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
This commit is contained in:
Sergey Biryukov 2020-08-31 22:41:02 +00:00
parent 23528d419a
commit 699e44cc76
4 changed files with 201 additions and 152 deletions

View File

@ -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 );

View File

@ -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 ) );

View File

@ -0,0 +1,191 @@
<?php
/**
* @group date
* @group datetime
* @group post
*/
class Tests_Date_Get_The_Modified_Date extends WP_UnitTestCase {
/**
* Test get_the_modified_time with post_id parameter.
*
* @ticket 37059
*
* @since 4.6.0
*/
public 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
*/
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 ) );
}
}

View File

@ -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