2 /*********************************************************************************
3 * By installing or using this file, you are confirming on behalf of the entity
4 * subscribed to the SugarCRM Inc. product ("Company") that Company is bound by
5 * the SugarCRM Inc. Master Subscription Agreement (“MSA”), which is viewable at:
6 * http://www.sugarcrm.com/master-subscription-agreement
8 * If Company is not bound by the MSA, then by installing or using this file
9 * you are agreeing unconditionally that Company will be bound by the MSA and
10 * certifying that you have authority to bind Company accordingly.
12 * Copyright (C) 2004-2013 SugarCRM Inc. All rights reserved.
13 ********************************************************************************/
15 require_once 'modules/SchedulersJobs/SchedulersJob.php';
18 * Bug #56537 : Schedule Jobs don't work with classes
22 class Bug56573Test extends Sugar_PHPUnit_Framework_TestCase
29 public function setUp()
32 SugarTestHelper::setUp('current_user');
35 public function tearDown()
37 if (!empty($this->id)) {
38 $job = new SchedulersJob();
39 $job->mark_deleted($this->id);
41 SugarTestHelper::tearDown();
44 protected function execJob($name, $data)
46 require_once('include/SugarQueue/SugarJobQueue.php');
48 $job = new SchedulersJob();
49 $job->name = "Bug56573Test Alert Job - '{$name}'";
50 $job->target = "class::Bug56573TestJob";
52 $job->assigned_user_id = $GLOBALS['current_user']->id;
54 // Add the Job the the job Queue
55 $jq = new SugarJobQueue();
60 // Save id for cleaning
66 public static function provider()
74 'status' => SchedulersJob::JOB_STATUS_RUNNING,
75 'resolution' => SchedulersJob::JOB_SUCCESS,
79 SchedulersJob::JOB_STATUS_DONE,
80 SchedulersJob::JOB_SUCCESS
87 'status' => SchedulersJob::JOB_STATUS_RUNNING,
88 'resolution' => SchedulersJob::JOB_FAILURE,
92 SchedulersJob::JOB_STATUS_DONE,
93 SchedulersJob::JOB_FAILURE
101 'status' => SchedulersJob::JOB_STATUS_QUEUED,
102 'resolution' => SchedulersJob::JOB_PARTIAL,
106 SchedulersJob::JOB_STATUS_QUEUED,
107 SchedulersJob::JOB_PARTIAL
113 * Test if runJob() sets proper values of status/resolution
115 * @dataProvider provider
118 public function testJob($name, $data, $status, $resolution)
120 $job = $this->execJob($name, $data);
121 $this->assertEquals($resolution, $job->resolution, "Wrong resolution");
122 $this->assertEquals($status, $job->status, "Wrong status");
127 * Job Class for testing SchedulersJob
129 class Bug56573TestJob implements RunnableSchedulerJob
131 public function run($data)
133 // Pull all the test data
134 $data = explode(',', $data);
136 // Set status and resolution
137 $this->job->status = $data[0];
138 $this->job->resolution = $data[1];
143 public function setJob(SchedulersJob $job)