]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Home/UnifiedSearchAdvancedTest.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / Home / UnifiedSearchAdvancedTest.php
1 <?php
2 require_once 'modules/Home/UnifiedSearchAdvanced.php';
3 require_once 'modules/Contacts/Contact.php';
4 require_once 'include/utils/layout_utils.php';
5
6 /**
7  * @group bug34125
8  */
9 class UnifiedSearchAdvancedTest extends Sugar_PHPUnit_Framework_TestCase
10 {
11     protected $_contact = null;
12
13     public function setUp()
14     {
15         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
16         
17         $unid = uniqid();
18         $contact = new Contact();
19         $contact->id = 'l_'.$unid;
20         $contact->first_name = 'Greg';
21         $contact->last_name = 'Brady';
22         $contact->new_with_id = true;
23         $contact->save();
24         $this->_contact = $contact;
25         }
26
27         public function tearDown()
28         {
29         $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->_contact->id}'");
30         unset($this->_contact);
31         }
32
33         public function testSearchByFirstName()
34         {
35                 global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles;
36                 require('config.php');
37                 require('include/modules.php');
38                 $modListHeader = $moduleList;
39         $_REQUEST['query_string'] = $this->_contact->first_name;
40         $_REQUEST['module'] = 'Home';
41                 $usa = new UnifiedSearchAdvanced();
42                 ob_start();
43                 $usa->search();
44                 $html = ob_get_contents();
45                 ob_clean();
46                 $pos = strpos($html, $this->_contact->first_name);
47                 $this->assertTrue(!empty($pos), "Could not find the contact: ".$this->_contact->first_name." in the search results.");
48     }
49
50         public function testSearchByFirstAndLastName()
51         {
52                 global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles;
53                 require('config.php');
54                 require('include/modules.php');
55                 $_REQUEST['query_string'] = $this->_contact->first_name.' '.$this->_contact->last_name;
56         $_REQUEST['module'] = 'Home';
57                 $usa = new UnifiedSearchAdvanced();
58                 ob_start();
59                 $usa->search();
60                 $html = ob_get_contents();
61                 ob_clean();
62                 $pos = strpos($html, $this->_contact->first_name);
63                 $this->assertTrue(!empty($pos), "Could not find the lead: ".$this->_contact->first_name." in the search results.");
64     }
65 }
66