2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 require_once('modules/Emails/Email.php');
39 require_once('modules/Notes/Note.php');
44 class Bug32489Test extends Sugar_PHPUnit_Framework_TestCase
50 var $outbound_id = null;
52 public function setUp()
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');
61 $em->name = 'tst_' . uniqid();
62 $em->type = 'inbound';
64 $em->date_sent = $timedate->to_display_date_time(gmdate("Y-m-d H:i:s", (gmmktime() + (3600 * 24 * 2) ))) ; //Two days from today
69 $n->name = 'tst_' . uniqid();
70 $n->filename = 'file_' . uniqid();
71 $n->parent_type = 'Emails';
72 $n->parent_id = $this->em1->id;
79 public function tearDown()
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}'");
94 function testSimpleImportEmailSearch(){
95 global $current_user,$timedate;
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.");
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" );
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" );
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" );
123 function testSimpleImportEmailSearchWithAttachments()
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" );
131 //Add a second note related to same parent, same results should be obtained.
133 $n->name = 'tst2_' . uniqid();
134 $n->filename = 'file2_' . uniqid();
135 $n->parent_type = 'Emails';
136 $n->parent_id = $this->em1->id;
139 $results = $this->em1->searchImportedEmails();
140 $this->assertEquals(1, count($results['out']), "Could not perform a simple search for imported emails with multiple attachment" );