PageRenderTime 37ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/modules/Emails/Bug32489Test.php

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