]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Home/Bug43395Test.php
Release 6.2.1
[Github/sugarcrm.git] / tests / modules / Home / Bug43395Test.php
1 <?php
2 class Bug43395Test extends Sugar_PHPUnit_Framework_OutputTestCase
3 {
4         private static $quickSearch;
5         private static $contact;
6         
7         static function setUpBeforeClass() 
8     {
9         global $app_strings, $app_list_strings;
10         $app_strings = return_application_language($GLOBALS['current_language']);
11         $app_list_strings = return_app_list_strings_language($GLOBALS['current_language']);     
12         $user = new User();
13         $user->retrieve('1');
14         $GLOBALS['current_user'] = $user;
15         self::$contact = SugarTestContactUtilities::createContact();
16         self::$contact->first_name = 'Bug43395';
17         self::$contact->last_name = 'Test';
18         self::$contact->salutation = 'Mr.'; 
19         self::$contact->save();         
20     }
21     
22     public static function tearDownAfterClass() 
23     {
24         unset($_REQUEST['data']);
25         unset($_REQUEST['query']);
26         SugarTestContactUtilities::removeAllCreatedContacts();
27     }
28     
29     public function testFormatResults()
30     {   
31         $_REQUEST = array();
32         $_REQUEST['data'] = '{"form":"search_form","method":"query","modules":["Contacts"],"group":"or","field_list":["name","id"],"populate_list":["contact_c_basic","contact_id_c_basic"],"required_list":["parent_id"],"conditions":[{"name":"name","op":"like_custom","end":"%","value":""}],"order":"name","limit":"30","no_match_text":"No Match"}';
33         $_REQUEST['query'] = self::$contact->first_name;
34         require_once 'modules/Home/quicksearchQuery.php';
35         
36         $json = getJSONobj();
37                 $data = $json->decode(html_entity_decode($_REQUEST['data']));
38                 if(isset($_REQUEST['query']) && !empty($_REQUEST['query'])){
39                 foreach($data['conditions'] as $k=>$v){
40                         if(empty($data['conditions'][$k]['value'])){
41                                 $data['conditions'][$k]['value']=$_REQUEST['query'];
42                         }
43                 }
44                 }
45                 self::$quickSearch = new quicksearchQuery();
46                 $result = self::$quickSearch->query($data);
47                 $resultBean = $json->decodeReal($result);
48             $this->assertEquals($resultBean['fields'][0]['name'], self::$contact->first_name . ' ' . self::$contact->last_name, 'Assert that the quicksearch returns a contact name without salutation');
49     }
50     
51     public function testPersonLocaleNameFormattting()
52     {
53         $GLOBALS['current_user']->setPreference('default_locale_name_format', 's f l');
54
55         self::$contact->createLocaleFormattedName = true;
56         self::$contact->_create_proper_name_field();
57         $this->assertEquals(self::$contact->name, 'Mr. Bug43395 Test', 'Assert that _create_proper_name_field with createLocaleFormattedName set to true returns salutation');
58
59         self::$contact->createLocaleFormattedName = false;
60         self::$contact->_create_proper_name_field();
61         $this->assertEquals(self::$contact->name, 'Bug43395 Test', 'Assert that _create_proper_name_field with createLocaleFormattedName set to false does not return salutation');
62     }
63     
64 }
65 ?>