Squashed 'libraries/action-scheduler/' content from commit a95f351
git-subtree-dir: libraries/action-scheduler git-subtree-split: a95f351058eada5e5281faa22e5a40865542e839
This commit is contained in:
34
tests/phpunit/helpers/ActionScheduler_Callbacks.php
Normal file
34
tests/phpunit/helpers/ActionScheduler_Callbacks.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ActionScheduler_Callbacks class.
|
||||
*/
|
||||
class ActionScheduler_Callbacks {
|
||||
/**
|
||||
* Scheduled action hook that can be used when we want to simulate an action
|
||||
* with a registered callback.
|
||||
*/
|
||||
const HOOK_WITH_CALLBACK = 'hook_with_callback';
|
||||
|
||||
/**
|
||||
* Setup callbacks for different types of hook.
|
||||
*/
|
||||
public static function add_callbacks() {
|
||||
add_action( self::HOOK_WITH_CALLBACK, array( __CLASS__, 'empty_callback' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove callbacks.
|
||||
*/
|
||||
public static function remove_callbacks() {
|
||||
remove_action( self::HOOK_WITH_CALLBACK, array( __CLASS__, 'empty_callback' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* This stub is used as the callback function for the ActionScheduler_Callbacks::HOOK_WITH_CALLBACK hook.
|
||||
*
|
||||
* Action Scheduler will mark actions as 'failed' if a callback does not exist, this
|
||||
* simply serves to act as the callback for various test scenarios in child classes.
|
||||
*/
|
||||
public static function empty_callback() {}
|
||||
}
|
||||
48
tests/phpunit/helpers/ActionScheduler_Compatibility_Test.php
Normal file
48
tests/phpunit/helpers/ActionScheduler_Compatibility_Test.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// phpcs:disable WordPress.PHP.IniSet.max_execution_time_Blacklisted
|
||||
|
||||
/**
|
||||
* @group helpers
|
||||
*/
|
||||
class ActionScheduler_Compatibility_Test extends ActionScheduler_UnitTestCase {
|
||||
/**
|
||||
* Test the logic relating to ActionScheduler_Compatibility::raise_time_limit().
|
||||
*/
|
||||
public function test_raise_time_limit() {
|
||||
// We'll want to restore things after this test.
|
||||
$default_max_execution_time = ini_get( 'max_execution_time' );
|
||||
|
||||
ini_set( 'max_execution_time', 0 );
|
||||
ActionScheduler_Compatibility::raise_time_limit( 10 );
|
||||
$this->assertEquals(
|
||||
'0',
|
||||
ini_get( 'max_execution_time' ),
|
||||
'If the max_execution_time was already zero (unlimited), then it will not be changed.'
|
||||
);
|
||||
|
||||
ini_set( 'max_execution_time', 60 );
|
||||
ActionScheduler_Compatibility::raise_time_limit( 30 );
|
||||
$this->assertEquals(
|
||||
'60',
|
||||
ini_get( 'max_execution_time' ),
|
||||
'If the max_execution_time was already a higher value than we specify, then it will not be changed.'
|
||||
);
|
||||
|
||||
ActionScheduler_Compatibility::raise_time_limit( 200 );
|
||||
$this->assertEquals(
|
||||
'200',
|
||||
ini_get( 'max_execution_time' ),
|
||||
'If the max_execution_time was a lower value than we specify, but was above zero, then it will be updated to the new value.'
|
||||
);
|
||||
|
||||
ActionScheduler_Compatibility::raise_time_limit( 0 );
|
||||
$this->assertEquals(
|
||||
'0',
|
||||
ini_get( 'max_execution_time' ),
|
||||
'If the max_execution_time was a positive, non-zero value and we then specify zero (unlimited) as the new value, then it will be updated.'
|
||||
);
|
||||
|
||||
// Cleanup.
|
||||
ini_set( 'max_execution_time', $default_max_execution_time );
|
||||
}
|
||||
}
|
||||
110
tests/phpunit/helpers/ActionScheduler_TimezoneHelper_Test.php
Normal file
110
tests/phpunit/helpers/ActionScheduler_TimezoneHelper_Test.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group timezone
|
||||
*/
|
||||
class ActionScheduler_TimezoneHelper_Test extends ActionScheduler_UnitTestCase {
|
||||
|
||||
/**
|
||||
* Ensure that the timezone string we expect works properly.
|
||||
*
|
||||
* @dataProvider local_timezone_provider
|
||||
*
|
||||
* @param string $timezone_string Timezone.
|
||||
*/
|
||||
public function test_local_timezone_strings( $timezone_string ) {
|
||||
$timezone_filter = function ( $tz ) use ( $timezone_string ) {
|
||||
return $timezone_string;
|
||||
};
|
||||
|
||||
add_filter( 'option_timezone_string', $timezone_filter );
|
||||
|
||||
$date = new ActionScheduler_DateTime();
|
||||
$timezone = ActionScheduler_TimezoneHelper::set_local_timezone( $date )->getTimezone();
|
||||
$this->assertInstanceOf( 'DateTimeZone', $timezone );
|
||||
$this->assertEquals( $timezone_string, $timezone->getName() );
|
||||
|
||||
remove_filter( 'option_timezone_string', $timezone_filter );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get timezone strings.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function local_timezone_provider() {
|
||||
return array(
|
||||
array( 'America/New_York' ),
|
||||
array( 'Australia/Melbourne' ),
|
||||
array( 'UTC' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that most GMT offsets don't return UTC as the timezone.
|
||||
*
|
||||
* @dataProvider local_timezone_offsets_provider
|
||||
*
|
||||
* @param string $gmt_offset GMT offset.
|
||||
*/
|
||||
public function test_local_timezone_offsets( $gmt_offset ) {
|
||||
$gmt_filter = function ( $gmt ) use ( $gmt_offset ) {
|
||||
return $gmt_offset;
|
||||
};
|
||||
|
||||
$date = new ActionScheduler_DateTime();
|
||||
|
||||
add_filter( 'option_gmt_offset', $gmt_filter );
|
||||
ActionScheduler_TimezoneHelper::set_local_timezone( $date );
|
||||
remove_filter( 'option_gmt_offset', $gmt_filter );
|
||||
|
||||
$offset_in_seconds = $gmt_offset * HOUR_IN_SECONDS;
|
||||
|
||||
$this->assertEquals( $offset_in_seconds, $date->getOffset() );
|
||||
$this->assertEquals( $offset_in_seconds, $date->getOffsetTimestamp() - $date->getTimestamp() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get timezone offsets.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function local_timezone_offsets_provider() {
|
||||
return array(
|
||||
array( '-11' ),
|
||||
array( '-10.5' ),
|
||||
array( '-10' ),
|
||||
array( '-9' ),
|
||||
array( '-8' ),
|
||||
array( '-7' ),
|
||||
array( '-6' ),
|
||||
array( '-5' ),
|
||||
array( '-4.5' ),
|
||||
array( '-4' ),
|
||||
array( '-3.5' ),
|
||||
array( '-3' ),
|
||||
array( '-2' ),
|
||||
array( '-1' ),
|
||||
array( '1' ),
|
||||
array( '1.5' ),
|
||||
array( '2' ),
|
||||
array( '3' ),
|
||||
array( '4' ),
|
||||
array( '5' ),
|
||||
array( '5.5' ),
|
||||
array( '5.75' ),
|
||||
array( '6' ),
|
||||
array( '7' ),
|
||||
array( '8' ),
|
||||
array( '8.5' ),
|
||||
array( '9' ),
|
||||
array( '9.5' ),
|
||||
array( '10' ),
|
||||
array( '10.5' ),
|
||||
array( '11' ),
|
||||
array( '11.5' ),
|
||||
array( '12' ),
|
||||
array( '13' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user