Adds unit test
This commit is contained in:
@ -8,6 +8,7 @@ use MailPoet\Mailer\MailerLog;
|
||||
use MailPoet\Models\ScheduledTask;
|
||||
use MailPoet\Models\ScheduledTaskSubscriber;
|
||||
use MailPoet\Models\SendingQueue;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@ -242,6 +243,6 @@ class Migration extends SimpleWorker {
|
||||
|
||||
static function getNextRunDate() {
|
||||
// run migration immediately
|
||||
return Carbon::createFromTimestamp(current_time('timestamp'));
|
||||
return Carbon::createFromTimestamp(WPFunctions::currentTime('timestamp'));
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,10 @@ class Functions {
|
||||
return self::callWithFallback('wp_remote_retrieve_response_message', func_get_args());
|
||||
}
|
||||
|
||||
static function currentTime() {
|
||||
return self::callWithFallback('current_time', func_get_args());
|
||||
}
|
||||
|
||||
private static function callWithFallback($func, $args) {
|
||||
$local_func = __NAMESPACE__ . '\\' . $func;
|
||||
if(function_exists($local_func)) {
|
||||
|
@ -71,3 +71,7 @@ function wp_remote_post() {
|
||||
function wp_remote_get() {
|
||||
return override(__FUNCTION__, func_get_args());
|
||||
}
|
||||
|
||||
function current_time() {
|
||||
return override(__FUNCTION__, func_get_args());
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
namespace MailPoet\Test\Cron\Workers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Helper\WordPress as WordPressHelper;
|
||||
use MailPoet\Cron\Workers\SendingQueue\Migration;
|
||||
use MailPoet\Mailer\MailerLog;
|
||||
use MailPoet\Models\ScheduledTask;
|
||||
@ -107,6 +108,20 @@ class MigrationTest extends \MailPoetTest {
|
||||
expect(MailerLog::isSendingPaused())->false();
|
||||
}
|
||||
|
||||
function testItUsesWPTimeToReturnNextRunDate() {
|
||||
$timestamp = 1514801410; // 01/01/2018 @ 10:10am (UTC)
|
||||
|
||||
WordPressHelper::interceptFunction('current_time', function($time) use($timestamp) {
|
||||
// "timestamp" string is passed as an argument
|
||||
expect($time)->equals('timestamp');
|
||||
|
||||
return $timestamp;
|
||||
});
|
||||
|
||||
$next_run_date = Migration::getNextRunDate();
|
||||
expect($next_run_date->timestamp)->equals($timestamp);
|
||||
}
|
||||
|
||||
private function createScheduledTask() {
|
||||
$task = ScheduledTask::create();
|
||||
$task->type = Migration::TASK_TYPE;
|
||||
@ -185,5 +200,7 @@ class MigrationTest extends \MailPoetTest {
|
||||
$this->restoreTable();
|
||||
$this->altered = false;
|
||||
}
|
||||
|
||||
WordPressHelper::releaseAllFunctions();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user