]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Emails/Bug32489Test.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / Emails / Bug32489Test.php
1 <?php 
2 require_once('modules/Emails/Email.php');
3 require_once('modules/Notes/Note.php');
4
5 /**
6  * @ticket 32489
7  */
8 class Bug32489Test extends Sugar_PHPUnit_Framework_TestCase
9 {
10         var $em1 = null;
11     var $note1 = null;
12     var $note2 = null;
13     
14         var $outbound_id = null;
15         
16         public function setUp()
17     {
18         global $current_user, $currentModule,$timedate ;
19                 $mod_strings = return_module_language($GLOBALS['current_language'], "Contacts");
20                 $current_user = SugarTestUserUtilities::createAnonymousUser();
21                 $this->outbound_id = uniqid();
22                 $time = date('Y-m-d H:i:s');
23
24                 $em = new Email();
25                 $em->name = 'tst_' . uniqid();
26                 $em->type = 'inbound';
27                 $em->intent = 'pick';
28                 $em->date_sent = $timedate->to_display_date_time(gmdate("Y-m-d H:i:s", (gmmktime() + (3600 * 24 * 2) ))) ; //Two days from today 
29                 $em->save();
30             $this->em1 = $em;
31             
32             $n = new Note();
33             $n->name = 'tst_' . uniqid();
34             $n->filename = 'file_' . uniqid();
35             $n->parent_type = 'Emails';
36             $n->parent_id = $this->em1->id;
37             $n->save();
38             $this->note1 = $n;
39             
40             
41         }
42
43     public function tearDown()
44     {
45         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
46         unset($GLOBALS['current_user']);
47         
48         $GLOBALS['db']->query("DELETE FROM emails WHERE id= '{$this->em1->id}'");
49         $GLOBALS['db']->query("DELETE FROM notes WHERE id= '{$this->note1->id}'");
50         if($this->note2 != null)
51                 $GLOBALS['db']->query("DELETE FROM notes WHERE id= '{$this->note2->id}'");
52         
53         unset($this->em1);
54         unset($this->note1);
55         unset($this->note2);
56     }
57     
58         function testSimpleImportEmailSearch(){
59             global $current_user,$timedate;
60            
61             //Simple search by name
62         $_REQUEST['name'] = $this->em1->name;
63             $results = $this->em1->searchImportedEmails();
64                 $this->assertEquals(1, count($results['out']), "Could not perform a simple search for imported emails" );
65                 $this->assertEquals(count($results['out']), $results['totalCount'], "Imported emails search, total count of result set and count query not equal.");
66                 
67                 //Search should return nothing
68                 $_REQUEST['name'] =  uniqid() . uniqid(); //Should be enough entropy.   
69                 $results = $this->em1->searchImportedEmails();  
70                 $this->assertEquals(0, count($results['out']), "Could not perform a simple search for imported emails, expected no results" );
71                 
72                 //Search by date filters.
73                 $tomm = gmdate('Y-m-d H:i:s',(gmmktime() + 3600 * 24));
74                 $tommDisplay = $timedate->to_display_date_time($tomm);
75                 $_REQUEST['dateFrom'] = $tommDisplay;
76                 unset($_REQUEST['name']);
77                 $results = $this->em1->searchImportedEmails();
78                 $this->assertTrue(count($results['out']) >= 1, "Could not perform a simple search for imported emails with a single date filter" );
79
80                 $weekFromNow = gmdate('Y-m-d H:i:s',(gmmktime() + (3600 * 24 * 7)));
81                 $weekFromNowDisplay = $timedate->to_display_date_time($weekFromNow);
82                 $_REQUEST['dateTo'] = $weekFromNowDisplay;
83                 $results = $this->em1->searchImportedEmails();
84                 $this->assertTrue(count($results['out']) >= 1, "Could not perform a simple search for imported emails with a two date filter" );
85     }
86     
87     function testSimpleImportEmailSearchWithAttachments()
88     {
89         unset($_REQUEST);
90         $_REQUEST['name'] = $this->em1->name;
91         $_REQUEST['attachmentsSearch'] = 1;
92         $results = $this->em1->searchImportedEmails();  
93                 $this->assertEquals(1, count($results['out']), "Could not perform a simple search for imported emails with single attachment" );
94                 
95                 //Add a second note related to same parent, same results should be obtained.
96                 $n = new Note();
97             $n->name = 'tst2_' . uniqid();
98             $n->filename = 'file2_' . uniqid();
99             $n->parent_type = 'Emails';
100             $n->parent_id = $this->em1->id;
101             $n->save();
102             $this->note2 = $n;
103             $results = $this->em1->searchImportedEmails();      
104                 $this->assertEquals(1, count($results['out']), "Could not perform a simple search for imported emails with multiple attachment" );
105     }
106 }
107 ?>