2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
38 require_once 'modules/Schedulers/Scheduler.php';
40 class Bug44215Test extends Sugar_PHPUnit_Framework_TestCase
44 public function setUp()
46 unset($GLOBALS['disable_date_format']);
47 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
48 $GLOBALS['current_user']->setPreference('datef', "m/d/Y");
49 $GLOBALS['current_user']->setPreference('timef', "h:ia");
50 $GLOBALS['current_user']->setPreference('timezone', "America/Los_Angeles");
51 $this->testScheduler = new Bug44215MockTestScheduler();
52 $this->testScheduler->save();
55 public function tearDown()
57 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
58 unset($GLOBALS['current_user']);
59 $GLOBALS['db']->query("DELETE FROM schedulers WHERE id = '" . $this->testScheduler->id . "'");
60 $GLOBALS['db']->query("DELETE FROM schedulers_times WHERE scheduler_id = '" . $this->testScheduler->id . "'");
64 public function testFlushDeadJobs()
66 $this->testScheduler->fire();
67 $this->testScheduler->status = 'In Progress';
68 $this->testScheduler->save();
69 $this->assertEquals('In Progress', $this->testScheduler->status, "Assert that the test scheduler instance has status of 'In Progress'");
71 $result = $GLOBALS['db']->query("SELECT id FROM schedulers_times WHERE scheduler_id ='{$this->testScheduler->id}'");
74 while($row = $GLOBALS['db']->fetchByAssoc($result))
76 $job = new SchedulersJob();
77 $job->retrieve($row['id']);
79 $this->assertEquals('completed', $job->status, "Assert that schedulers_times status is set to 'completed'");
81 $job->execute_time = $this->testScheduler->date_time_start; //Set this to the start time of the scheduler which is in year 2005
86 $this->assertTrue($jobCount > 0, "Assert that we created schedulers_times entries");
87 $this->testScheduler->flushDeadJobs();
89 $this->testScheduler->retrieve($this->testScheduler->id);
90 $this->assertEquals('Active', $this->testScheduler->status, "Assert that the status for scheduler is set to 'Active'");
92 $result = $GLOBALS['db']->query("SELECT id FROM schedulers_times WHERE scheduler_id ='{$this->testScheduler->id}'");
94 while($row = $GLOBALS['db']->fetchByAssoc($result))
96 $job = new SchedulersJob();
97 $job->retrieve($row['id']);
98 $this->assertEquals('failed', $job->status, "Assert that schedulers_times status is set to 'failed'");
106 function Bug44215TestFunction()
108 //Could do something here, but don't need to
112 //Mock Scheduler bean for the test scheduler
113 class Bug44215MockTestScheduler extends Scheduler
115 public $fired = false;
116 public $name = "Bug44215MockTestScheduler";
117 public $date_time_start = '2005-01-01 19:00:00';
118 public $job_interval = '*::*::*::*::*';
119 public $job = 'function::Bug44215TestFunction';