]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/SubPanel/Bug41738Test.php
Added unit tests.
[Github/sugarcrm.git] / tests / include / SubPanel / Bug41738Test.php
1 <?php
2
3 require_once('data/SugarBean.php');
4 require_once('modules/Contacts/Contact.php');
5 require_once('include/SubPanel/SubPanelDefinitions.php');
6
7 class Bug41738Test extends Sugar_PHPUnit_Framework_TestCase 
8 {       
9     protected $bean;
10
11         public function setUp()
12         {
13             global $moduleList, $beanList, $beanFiles;
14         require('include/modules.php');
15         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
16         $GLOBALS['modListHeader'] = query_module_access_list($GLOBALS['current_user']);
17         $GLOBALS['modules_exempt_from_availability_check']['Calls']='Calls';
18         $GLOBALS['modules_exempt_from_availability_check']['Meetings']='Meetings';
19         $this->bean = new Opportunity();
20         }
21
22         public function tearDown()
23         {
24             SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
25         unset($GLOBALS['current_user']);
26         }
27
28     public function testSubpanelCollectionWithSpecificQuery()
29     {
30         $subpanel = array(
31                         'order' => 20,
32                         'sort_order' => 'desc',
33                         'sort_by' => 'date_entered',
34                         'type' => 'collection',
35                         'subpanel_name' => 'history',   //this values is not associated with a physical file.
36                         'top_buttons' => array(),
37                         'collection_list' => array(
38                                 'meetings' => array(
39                                         'module' => 'Meetings',
40                                         'subpanel_name' => 'ForHistory',
41                     'get_subpanel_data' => 'function:subpanelCollectionWithSpecificQueryMeetings',
42                     'generate_select'=>false,
43                     'function_parameters' => array(
44                         'bean_id'=>$this->bean->id,
45                         'import_function_file' => __FILE__
46                     ),
47                                 ),
48                                 'tasks' => array(
49                                         'module' => 'Tasks',
50                                         'subpanel_name' => 'ForHistory',
51                     'get_subpanel_data' => 'function:subpanelCollectionWithSpecificQueryTasks',
52                     'generate_select'=>false,
53                     'function_parameters' => array(
54                         'bean_id'=>$this->bean->id,
55                         'import_function_file' => __FILE__
56                     ),
57                                 ),
58                         )
59         );
60         $subpanel_def = new aSubPanel("testpanel", $subpanel, $this->bean);
61         $query = $this->bean->get_union_related_list($this->bean, "", '', "", 0, 5, -1, 0, $subpanel_def);
62         $result = $this->bean->db->query($query["query"]);
63         $this->assertTrue($result != false, "Bad query: {$query['query']}");
64     }
65
66
67 }
68
69
70 function subpanelCollectionWithSpecificQueryMeetings($params)
71 {
72                 $query = "SELECT meetings.id , meetings.name , meetings.status , 0 reply_to_status , ' ' contact_name , ' ' contact_id , ' ' contact_name_owner , ' ' contact_name_mod , meetings.parent_id , meetings.parent_type , meetings.date_modified , jt1.user_name assigned_user_name , jt1.created_by assigned_user_name_owner , 'Users' assigned_user_name_mod, ' ' filename , meetings.assigned_user_id , 'meetings' panel_name 
73                         FROM meetings 
74                         LEFT JOIN users jt1 ON jt1.id= meetings.assigned_user_id AND jt1.deleted=0 AND jt1.deleted=0 
75                         WHERE ( meetings.parent_type = \"Opportunities\" 
76                                 AND meetings.deleted=0 
77                                 AND (meetings.status='Held' OR meetings.status='Not Held') 
78                                 AND meetings.parent_id IN(
79                                                                                         SELECT o.id 
80                                                                                         FROM opportunities o 
81                                                                                         INNER JOIN opportunities_contacts oc on o.id = oc.opportunity_id 
82                                                                                         AND oc.contact_id = '".$params['bean_id']."')
83                                                         )";
84
85                 return $query ;
86 }
87
88 function subpanelCollectionWithSpecificQueryTasks($params)
89 {
90                 $query = "SELECT tasks.id , tasks.name , tasks.status , 0 reply_to_status , ' ' contact_name , ' ' contact_id , ' ' contact_name_owner , ' ' contact_name_mod , tasks.parent_id , tasks.parent_type , tasks.date_modified , jt1.user_name assigned_user_name , jt1.created_by assigned_user_name_owner , 'Users' assigned_user_name_mod, ' ' filename , tasks.assigned_user_id , 'tasks' panel_name 
91                         FROM tasks 
92                         LEFT JOIN users jt1 ON jt1.id= tasks.assigned_user_id AND jt1.deleted=0 AND jt1.deleted=0 
93                         WHERE ( tasks.parent_type = \"Opportunities\" 
94                                 AND tasks.deleted=0 
95                                 AND (tasks.status='Completed' OR tasks.status='Deferred') 
96                                 AND tasks.parent_id IN(
97                                                                                         SELECT o.id 
98                                                                                         FROM opportunities o 
99                                                                                         INNER JOIN opportunities_contacts oc on o.id = oc.opportunity_id 
100                                                                                         AND oc.contact_id = '".$params['bean_id']."')
101                                                         )";
102
103                 return $query ;
104 }
105
106