public function testhandleDateFormat() { $schedulersJob = new SchedulersJob(); //test with default params $result = $schedulersJob->handleDateFormat(); $this->assertGreaterThan(0, strlen($result)); //test with a valid date param $result = $schedulersJob->handleDateFormat('2015-01-01'); $this->assertEquals('2015-01-01 00:00:00', $result); }
/** * executes Scheduled job */ function fire() { if (empty($this->job)) { // only execute when valid $GLOBALS['log']->fatal('Scheduler tried to fire an empty job!!'); return false; } $exJob = explode('::', $this->job); if (is_array($exJob)) { // instantiate a new SchedulersJob object and prep it $trackerManager = TrackerManager::getInstance(); $trackerManager->pause(); $job = new SchedulersJob(); $job->scheduler_id = $this->id; $job->scheduler =& $this; $job->execute_time = $job->handleDateFormat('now'); $jobId = $job->save(); $trackerManager->unPause(); $job->retrieve($jobId); if ($exJob[0] == 'function') { $GLOBALS['log']->debug('----->Scheduler found a job of type FUNCTION'); require_once 'modules/Schedulers/_AddJobsHere.php'; $job->setJobFlag(1); $func = $exJob[1]; $GLOBALS['log']->debug('----->SchedulersJob firing ' . $func); $res = call_user_func($func); if ($res) { $job->setJobFlag(2); $job->finishJob(); return true; } else { $job->setJobFlag(3); return false; } } elseif ($exJob[0] == 'url') { if (function_exists('curl_init')) { $GLOBALS['log']->debug('----->SchedulersJob found a job of type URL'); $job->setJobFlag(1); $GLOBALS['log']->debug('----->SchedulersJob firing URL job: ' . $exJob[1]); if ($job->fireUrl($exJob[1])) { $job->setJobFlag(2); $job->finishJob(); return true; } else { $job->setJobFlag(3); return false; } } else { $job->setJobFlag(4); return false; } } } return false; }
/** * testSchedulersJobHandleDateFormatWithOtherTime * */ public function testSchedulersJobHandleDateFormatWithOtherTime() { global $current_user; $job = new SchedulersJob(false); $job->user = $current_user; $this->assertRegExp('/^\\d{4}\\-\\d{2}\\-\\d{2}\\s\\d{1,2}\\:\\d{2}\\:\\d{2}$/', $job->handleDateFormat('+7 days')); $this->assertRegExp('/^\\d{4}\\-\\d{2}\\-\\d{2}\\s\\d{1,2}\\:\\d{2}\\:\\d{2}$/', $job->handleDateFormat('+7 days', $current_user, false)); $this->assertRegExp('/^\\d{1,2}\\/\\d{1,2}\\/\\d{4}\\s\\d{1,2}\\:\\d{2}$/', $job->handleDateFormat('+7 days', $current_user, true)); }