]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Emails/Bug32489Test.php
Release 6.2.0
[Github/sugarcrm.git] / tests / modules / Emails / Bug32489Test.php
1 <?php 
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37  
38 require_once('modules/Emails/Email.php');
39 require_once('modules/Notes/Note.php');
40
41 /**
42  * @ticket 32489
43  */
44 class Bug32489Test extends Sugar_PHPUnit_Framework_TestCase
45 {
46         var $em1 = null;
47     var $note1 = null;
48     var $note2 = null;
49     
50         var $outbound_id = null;
51         
52         public function setUp()
53     {
54         global $current_user, $currentModule,$timedate ;
55                 $mod_strings = return_module_language($GLOBALS['current_language'], "Contacts");
56                 $current_user = SugarTestUserUtilities::createAnonymousUser();
57                 $this->outbound_id = uniqid();
58                 $time = date('Y-m-d H:i:s');
59
60                 $em = new Email();
61                 $em->name = 'tst_' . uniqid();
62                 $em->type = 'inbound';
63                 $em->intent = 'pick';
64                 $em->date_sent = $timedate->to_display_date_time(gmdate("Y-m-d H:i:s", (gmmktime() + (3600 * 24 * 2) ))) ; //Two days from today 
65                 $em->save();
66             $this->em1 = $em;
67             
68             $n = new Note();
69             $n->name = 'tst_' . uniqid();
70             $n->filename = 'file_' . uniqid();
71             $n->parent_type = 'Emails';
72             $n->parent_id = $this->em1->id;
73             $n->save();
74             $this->note1 = $n;
75             
76             
77         }
78
79     public function tearDown()
80     {
81         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
82         unset($GLOBALS['current_user']);
83         unset($GLOBALS['mod_strings']);
84         $GLOBALS['db']->query("DELETE FROM emails WHERE id= '{$this->em1->id}'");
85         $GLOBALS['db']->query("DELETE FROM notes WHERE id= '{$this->note1->id}'");
86         if($this->note2 != null)
87                 $GLOBALS['db']->query("DELETE FROM notes WHERE id= '{$this->note2->id}'");
88         
89         unset($this->em1);
90         unset($this->note1);
91         unset($this->note2);
92     }
93     
94         function testSimpleImportEmailSearch(){
95             global $current_user,$timedate;
96            
97             //Simple search by name
98         $_REQUEST['name'] = $this->em1->name;
99             $results = $this->em1->searchImportedEmails();
100                 $this->assertEquals(1, count($results['out']), "Could not perform a simple search for imported emails" );
101                 $this->assertEquals(count($results['out']), $results['totalCount'], "Imported emails search, total count of result set and count query not equal.");
102                 
103                 //Search should return nothing
104                 $_REQUEST['name'] =  uniqid() . uniqid(); //Should be enough entropy.   
105                 $results = $this->em1->searchImportedEmails();  
106                 $this->assertEquals(0, count($results['out']), "Could not perform a simple search for imported emails, expected no results" );
107                 
108                 //Search by date filters.
109                 $tomm = gmdate('Y-m-d H:i:s',(gmmktime() + 3600 * 24));
110                 $tommDisplay = $timedate->to_display_date_time($tomm);
111                 $_REQUEST['dateFrom'] = $tommDisplay;
112                 unset($_REQUEST['name']);
113                 $results = $this->em1->searchImportedEmails();
114                 $this->assertTrue(count($results['out']) >= 1, "Could not perform a simple search for imported emails with a single date filter" );
115
116                 $weekFromNow = gmdate('Y-m-d H:i:s',(gmmktime() + (3600 * 24 * 7)));
117                 $weekFromNowDisplay = $timedate->to_display_date_time($weekFromNow);
118                 $_REQUEST['dateTo'] = $weekFromNowDisplay;
119                 $results = $this->em1->searchImportedEmails();
120                 $this->assertTrue(count($results['out']) >= 1, "Could not perform a simple search for imported emails with a two date filter" );
121     }
122     
123     function testSimpleImportEmailSearchWithAttachments()
124     {
125         unset($_REQUEST);
126         $_REQUEST['name'] = $this->em1->name;
127         $_REQUEST['attachmentsSearch'] = 1;
128         $results = $this->em1->searchImportedEmails();  
129                 $this->assertEquals(1, count($results['out']), "Could not perform a simple search for imported emails with single attachment" );
130                 
131                 //Add a second note related to same parent, same results should be obtained.
132                 $n = new Note();
133             $n->name = 'tst2_' . uniqid();
134             $n->filename = 'file2_' . uniqid();
135             $n->parent_type = 'Emails';
136             $n->parent_id = $this->em1->id;
137             $n->save();
138             $this->note2 = $n;
139             $results = $this->em1->searchImportedEmails();      
140                 $this->assertEquals(1, count($results['out']), "Could not perform a simple search for imported emails with multiple attachment" );
141     }
142 }
143 ?>