]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/CampaignTrackers/CampaignTrackersTest.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / CampaignTrackers / CampaignTrackersTest.php
1 <?php
2 require_once 'modules/Campaigns/Campaign.php';
3 require_once 'modules/CampaignTrackers/CampaignTracker.php';
4
5 class CampaignTrackersTest extends Sugar_PHPUnit_Framework_TestCase
6 {
7         var $campaign = 'campaignforcamplogunittest';
8         var $campaign_tracker;
9
10     
11     public function setup()
12     {
13                 global $current_user;   
14                 $current_user = SugarTestUserUtilities::createAnonymousUser();
15                 //for the purpose of this test, we need to create a campaign and relate it to a campaign tracker object
16
17                 //create campaign
18         $c = new Campaign();
19         $c->name = 'CT test ' . time();
20         $c->campaign_type = 'Email';
21         $c->status = 'Active';
22         $timeDate = new TimeDate();
23         $c->end_date = $timeDate->to_display_date(date('Y')+1 .'-01-01');
24         $c->assigned_id = $current_user->id;
25         $c->team_id = '1';
26         $c->team_set_id = '1';
27         $c->save();             
28                 $this->campaign = $c;
29                 
30                 //create campaign tracker
31                 $ct = new CampaignTracker();
32                 $ct->tracker_name ='Campaign Tracker Test  ' . time();
33                 $ct->tracker_url = 'sugarcrm.com';
34                 $ct->campaign_id = $this->campaign->id;
35                 $ct->save();
36                 $this->campaign_tracker = $ct;
37
38
39
40                 
41     }
42     
43     public function tearDown()
44     {
45                 //delete the campaign and campaign tracker
46                 $GLOBALS['db']->query('DELETE FROM campaign_log WHERE campaign_id = \''.$this->campaign->id.'\' ');
47                 $GLOBALS['db']->query('DELETE FROM campaign_tracker WHERE id = \''.$this->campaign_tracker->id.'\' ');
48                 unset($this->campaign_tracker);
49         unset($this->campaign_log );
50         unset($GLOBALS['current_user']);
51     }
52         
53
54         public function testSave(){
55                 //save was already performed, so just confirm that the http protocol got added on save
56                 $this->assertSame('http://sugarcrm.com', $this->campaign_tracker->tracker_url, 'http protocol was not added to campaign_tracker->tracker_url on save');
57                 
58         }
59         
60         
61
62         public function testFillInAdditionalDetailFields(){
63                 global $current_user;
64
65                 $this->campaign_tracker->fill_in_additional_detail_fields();
66
67                 //test that campaign name gets filled in
68                 $this->assertSame($this->campaign->name, $this->campaign_tracker->campaign_name, 'campaign name was not set properly during function call');
69
70                 //test that message url gets filed out
71                 $this->assertFalse(empty($this->campaign_tracker->message_url), 'message url was not populated correctly during function call');                
72         }
73
74         public function testGetSummaryText(){
75                 //test that tracker name is returned
76                 $this->assertSame($this->campaign_tracker->tracker_name, $this->campaign_tracker->get_summary_text(), 'campaign tracker name is not set properly in summary text');
77                 
78         }
79
80
81         
82
83 }