]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Home/QuickSearchTests.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / Home / QuickSearchTests.php
1 <?php
2 class QuickSearchTest extends Sugar_PHPUnit_Framework_TestCase
3 {
4         private $quickSearch;
5         
6         public function setUp() 
7     {
8         
9     }
10     
11     public function tearDown() 
12     {
13         unset($_REQUEST['data']);
14         unset($_REQUEST['query']);
15         $q = "delete from product_templates where name = 'MasonUnitTest';";
16         $GLOBALS['db']->query($q);
17     }
18         
19     public function testFormatResults()
20     {
21         $tempPT = new ProductTemplate();
22         $tempPT->name = 'MasonUnitTest';
23         $tempPT->description = "Unit'test";
24         $tempPT->cost_price = 1000;
25         $tempPT->discount_price = 800;
26         $tempPT->list_price = 1100;
27         $tempPT->save();
28         
29         $_REQUEST['data'] = '{"conditions":[{"end":"%","name":"name","op":"like_custom","value":""}],"field_list":["name","id","type_id","mft_part_num","cost_price","list_price","discount_price","pricing_factor","description","cost_usdollar","list_usdollar","discount_usdollar","tax_class_name"],"form":"EditView","group":"or","id":"EditView_product_name[1]","limit":"30","method":"query","modules":["ProductTemplates"],"no_match_text":"No Match","order":"name","populate_list":["name_1","product_template_id_1"],"post_onblur_function":"set_after_sqs"}';
30         $_REQUEST['query'] = 'MasonUnitTest';
31         require_once 'modules/home/quicksearchQuery.php';
32         
33         $json = getJSONobj();
34                 $data = $json->decode(html_entity_decode($_REQUEST['data']));
35                 if(isset($_REQUEST['query']) && !empty($_REQUEST['query'])){
36                 foreach($data['conditions'] as $k=>$v){
37                         if(empty($data['conditions'][$k]['value'])){
38                                 $data['conditions'][$k]['value']=$_REQUEST['query'];
39                         }
40                 }
41                 }
42                 $this->quickSearch = new quicksearchQuery();
43                 $result = $this->quickSearch->query($data);
44                 $resultBean = $json->decodeReal($result);
45                 $this->assertEquals($resultBean['fields'][0]['description'], $tempPT->description);
46     }
47 }
48 ?>