2 require_once('modules/Emails/Email.php');
3 require_once('modules/Notes/Note.php');
8 class Bug32489Test extends Sugar_PHPUnit_Framework_TestCase
14 var $outbound_id = null;
16 public function setUp()
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');
25 $em->name = 'tst_' . uniqid();
26 $em->type = 'inbound';
28 $em->date_sent = $timedate->to_display_date_time(gmdate("Y-m-d H:i:s", (gmmktime() + (3600 * 24 * 2) ))) ; //Two days from today
33 $n->name = 'tst_' . uniqid();
34 $n->filename = 'file_' . uniqid();
35 $n->parent_type = 'Emails';
36 $n->parent_id = $this->em1->id;
43 public function tearDown()
45 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
46 unset($GLOBALS['current_user']);
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}'");
58 function testSimpleImportEmailSearch(){
59 global $current_user,$timedate;
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.");
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" );
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" );
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" );
87 function testSimpleImportEmailSearchWithAttachments()
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" );
95 //Add a second note related to same parent, same results should be obtained.
97 $n->name = 'tst2_' . uniqid();
98 $n->filename = 'file2_' . uniqid();
99 $n->parent_type = 'Emails';
100 $n->parent_id = $this->em1->id;
103 $results = $this->em1->searchImportedEmails();
104 $this->assertEquals(1, count($results['out']), "Could not perform a simple search for imported emails with multiple attachment" );