]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/SchedulersJobs/Bug56573Test.php
Release 6.5.14
[Github/sugarcrm.git] / tests / modules / SchedulersJobs / Bug56573Test.php
1 <?php
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
7  *
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.
11  *
12  * Copyright (C) 2004-2013 SugarCRM Inc.  All rights reserved.
13  ********************************************************************************/
14
15 require_once 'modules/SchedulersJobs/SchedulersJob.php';
16
17 /**
18  * Bug #56537 : Schedule Jobs don't work with classes
19  *
20  * @ticket 56537
21  */
22 class Bug56573Test extends Sugar_PHPUnit_Framework_TestCase
23 {
24     /**
25      * @var string job id
26      */
27     protected $id;
28
29     public function setUp()
30     {
31         $this->id = null;
32         SugarTestHelper::setUp('current_user');
33     }
34
35     public function tearDown()
36     {
37         if (!empty($this->id)) {
38             $job = new SchedulersJob();
39             $job->mark_deleted($this->id);
40         }
41         SugarTestHelper::tearDown();
42     }
43
44     protected function execJob($name, $data)
45     {
46         require_once('include/SugarQueue/SugarJobQueue.php');
47
48         $job = new SchedulersJob();
49         $job->name = "Bug56573Test Alert Job - '{$name}'";
50         $job->data = $data;
51         $job->target = "class::Bug56573TestJob";
52         $job->assigned_user_id = $GLOBALS['current_user']->id;
53         $jq = new SugarJobQueue();
54         $jq->submitJob($job);
55         $this->id = $job->id;
56         $job->runJob();
57         return $job;
58     }
59
60     public static function provider()
61     {
62         return array(
63             array('Success', true, SchedulersJob::JOB_SUCCESS),
64             array('Failure', false, SchedulersJob::JOB_FAILURE)
65         );
66     }
67
68     /**
69      * Job executed or failed
70      * @dataProvider provider
71      * @group 56537
72      */
73     public function testJob($name, $result, $resolution)
74     {
75         $job = $this->execJob($name, $result);
76         $this->assertEquals($resolution, $job->resolution, "Wrong resolution");
77         $this->assertEquals(SchedulersJob::JOB_STATUS_DONE, $job->status, "Wrong status");
78     }
79 }
80
81 class Bug56573TestJob implements RunnableSchedulerJob
82 {
83
84     public function run($data)
85     {
86         return $data;
87     }
88
89     public function setJob(SchedulersJob $job)
90     {
91         $this->job = $job;
92     }
93 }