]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Schedulers/Bug44125Test.php
Release 6.2.0
[Github/sugarcrm.git] / tests / modules / Schedulers / Bug44125Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37  
38 require_once 'modules/Schedulers/Scheduler.php';
39
40 class Bug44215Test extends Sugar_PHPUnit_Framework_TestCase
41 {
42         var $testScheduler;
43         
44         public function setUp()
45     {
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(); 
53     }
54
55     public function tearDown()
56     {
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 . "'");
61     }
62
63     
64     public function testFlushDeadJobs()
65     {
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'");
70                 
71                 $result = $GLOBALS['db']->query("SELECT id FROM schedulers_times WHERE scheduler_id ='{$this->testScheduler->id}'");
72                 $jobCount = 0;
73                 
74                 while($row = $GLOBALS['db']->fetchByAssoc($result)) 
75                 {
76                         $job = new SchedulersJob();
77                         $job->retrieve($row['id']);
78                         
79                         $this->assertEquals('completed', $job->status, "Assert that schedulers_times status is set to 'completed'");
80                         
81                         $job->execute_time = $this->testScheduler->date_time_start; //Set this to the start time of the scheduler which is in year 2005
82                         $job->save();
83                         $jobCount++;
84                 }
85                 
86                 $this->assertTrue($jobCount > 0, "Assert that we created schedulers_times entries");
87                 $this->testScheduler->flushDeadJobs();
88                 
89                 $this->testScheduler->retrieve($this->testScheduler->id);
90                 $this->assertEquals('Active', $this->testScheduler->status, "Assert that the status for scheduler is set to 'Active'");
91                 
92         $result = $GLOBALS['db']->query("SELECT id FROM schedulers_times WHERE scheduler_id ='{$this->testScheduler->id}'");
93
94                 while($row = $GLOBALS['db']->fetchByAssoc($result)) 
95                 {
96                         $job = new SchedulersJob();
97                         $job->retrieve($row['id']);     
98                         $this->assertEquals('failed', $job->status, "Assert that schedulers_times status is set to 'failed'");
99                 }               
100                 
101     }
102
103
104 }
105
106 function Bug44215TestFunction()
107 {
108         //Could do something here, but don't need to
109         return true;
110 }
111
112 //Mock Scheduler bean for the test scheduler
113 class Bug44215MockTestScheduler extends Scheduler
114 {
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';
120 }