]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Emails/ComposePackageTest.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / Emails / ComposePackageTest.php
1 <?php 
2 require_once('modules/Contacts/Contact.php');
3
4
5 /**
6  * @group bug32487
7  */
8 class ComposePackageTest extends Sugar_PHPUnit_Framework_TestCase
9 {
10         var $c = null;
11         var $a = null;
12         var $ac_id = null;
13         
14         public function setUp()
15     {
16         global $current_user, $currentModule ;
17         $mod_strings = return_module_language($GLOBALS['current_language'], "Contacts");
18         $beanList = array();
19         $beanFiles = array();
20         require('include/modules.php');
21         $GLOBALS['beanList'] = $beanList;
22         $GLOBALS['beanFiles'] = $beanFiles;
23         $current_user = SugarTestUserUtilities::createAnonymousUser();
24         $unid = uniqid();
25         $time = date('Y-m-d H:i:s');
26
27         $contact = new Contact();
28         $contact->id = 'c_'.$unid;
29         $contact->first_name = 'testfirst';
30         $contact->last_name = 'testlast';
31         $contact->new_with_id = true;
32         $contact->disable_custom_fields = true;
33         $contact->save();
34         $this->c = $contact;    
35         }
36
37     public function tearDown()
38     {
39         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
40         unset($GLOBALS['current_user']);
41         unset($GLOBALS['beanFiles']);
42         unset($GLOBALS['beanList']);
43         
44         $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->c->id}'");
45         
46         unset($this->c);
47     }
48
49         public function testComposeFromMethodCallNoData()
50         {    
51             $_REQUEST['forQuickCreate'] = true;
52             require_once('modules/Emails/Compose.php');
53             $data = array();
54             $compose_data = generateComposeDataPackage($data,FALSE);
55             
56                 $this->assertEquals('', $compose_data['to_email_addrs']);
57     }
58     
59     public function testComposeFromMethodCallForContact()
60     {    
61             $_REQUEST['forQuickCreate'] = true;
62             require_once('modules/Emails/Compose.php');
63             $data = array();
64             $data['parent_type'] = 'Contacts';
65             $data['parent_id'] = $this->c->id;
66             
67             $compose_data = generateComposeDataPackage($data,FALSE);
68
69                 $this->assertEquals('Contacts', $compose_data['parent_type']);
70                 $this->assertEquals($this->c->id, $compose_data['parent_id']);
71                 $this->assertEquals($this->c->name, $compose_data['parent_name']);
72     }
73 }