Coding Standards: Disable WPCS warnings for date_default_timezone_set() and current_time( 'timestamp' ) calls in Date/Time tests.

These calls are intentional and required for the tests.

See #49222.

git-svn-id: https://develop.svn.wordpress.org/trunk@47118 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-01-28 00:51:42 +00:00
parent c1abc8203a
commit 48110faf25
4 changed files with 16 additions and 2 deletions

View File

@ -43,7 +43,9 @@ class Tests_Date_Current_Time extends WP_UnitTestCase {
$timestamp = time();
$wp_timestamp = $timestamp + 6 * HOUR_IN_SECONDS;
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.RequestedUTC
$this->assertEquals( $timestamp, current_time( 'timestamp', true ), 'The dates should be equal', 2 );
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
$this->assertEquals( $wp_timestamp, current_time( 'timestamp' ), 'The dates should be equal', 2 );
}
@ -56,11 +58,13 @@ class Tests_Date_Current_Time extends WP_UnitTestCase {
update_option( 'timezone_string', $timezone_string );
$datetime = new DateTime( 'now', new DateTimeZone( $timezone_string ) );
// phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
date_default_timezone_set( $timezone_string );
$current_time_custom_timezone_gmt = current_time( $format, true );
$current_time_custom_timezone = current_time( $format );
// phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
date_default_timezone_set( 'UTC' );
$current_time_gmt = current_time( $format, true );
@ -83,12 +87,17 @@ class Tests_Date_Current_Time extends WP_UnitTestCase {
$datetime->setTimezone( wp_timezone() );
$wp_timestamp = $timestamp + $datetime->getOffset();
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.RequestedUTC
$this->assertEquals( $timestamp, current_time( 'timestamp', true ), 'The dates should be equal', 2 );
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.RequestedUTC
$this->assertEquals( $timestamp, current_time( 'U', true ), 'The dates should be equal', 2 );
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
$this->assertEquals( $wp_timestamp, current_time( 'timestamp' ), 'The dates should be equal', 2 );
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
$this->assertEquals( $wp_timestamp, current_time( 'U' ), 'The dates should be equal', 2 );
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
$this->assertInternalType( 'int', current_time( 'timestamp' ) );
}

View File

@ -10,6 +10,7 @@ class Tests_Date_Get_Permalink extends WP_UnitTestCase {
function tearDown() {
delete_option( 'permalink_structure' );
update_option( 'timezone_string', 'UTC' );
// phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
date_default_timezone_set( 'UTC' );
parent::tearDown();
@ -22,6 +23,7 @@ class Tests_Date_Get_Permalink extends WP_UnitTestCase {
$timezone = 'America/Chicago';
update_option( 'timezone_string', $timezone );
update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%hour%/%minute%/%second%' );
// phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
date_default_timezone_set( 'UTC' );
$post_id = self::factory()->post->create(
@ -33,6 +35,7 @@ class Tests_Date_Get_Permalink extends WP_UnitTestCase {
$this->assertEquals( 'http://example.org/2018/07/22/21/13/23', get_permalink( $post_id ) );
// phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
date_default_timezone_set( $timezone );
$this->assertEquals( 'http://example.org/2018/07/22/21/13/23', get_permalink( $post_id ) );
}

View File

@ -7,6 +7,7 @@
class Tests_Date_mysql2date extends WP_UnitTestCase {
function tearDown() {
// phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
date_default_timezone_set( 'UTC' );
parent::tearDown();
@ -31,6 +32,7 @@ class Tests_Date_mysql2date extends WP_UnitTestCase {
*/
function test_mysql2date_should_format_time_with_changed_time_zone() {
$timezone = 'Europe/Kiev';
// phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
date_default_timezone_set( $timezone );
update_option( 'timezone_string', $timezone );
$datetime = new DateTime( 'now', new DateTimeZone( $timezone ) );

View File

@ -998,9 +998,9 @@ class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas
$term = get_term_by(
'id',
$this->factory->category->create(
[
array(
'parent' => $old_parent_term->term_id,
]
)
),
'category'
);