]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Leads/ConvertLeadTest.php
Release 6.5.10
[Github/sugarcrm.git] / tests / modules / Leads / ConvertLeadTest.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37
38 require_once('tests/SugarTestViewConvertLeadUtilities.php');
39 require_once 'modules/Leads/views/view.convertlead.php';
40 require_once 'tests/SugarTestViewConvertLeadUtilities.php';
41
42
43 class ConvertLeadTest extends Sugar_PHPUnit_Framework_TestCase
44 {
45     /**
46      * @var mixed
47      */
48     protected $license_expires_in = null;
49
50     public function setUp()
51     {
52         SugarTestHelper::setUp('beanFiles');
53         SugarTestHelper::setUp('beanList');
54         SugarTestHelper::setUp('app_list_strings');
55         SugarTestHelper::setUp('mod_strings', array('Leads'));
56         SugarTestHelper::setUp('current_user');
57         if (isset($_SESSION['LICENSE_EXPIRES_IN']))
58         {
59             $this->license_expires_in = $_SESSION['LICENSE_EXPIRES_IN'];
60         }
61         $_SESSION['LICENSE_EXPIRES_IN'] = '5';
62     }
63     
64     public function tearDown()
65     {
66         $_SESSION['LICENSE_EXPIRES_IN'] = $this->license_expires_in;
67         SugarTestHelper::tearDown();
68     }
69     
70     /**
71     * @group bug39787
72     */
73     public function testOpportunityNameValueFilled()
74     {
75         $lead = SugarTestLeadUtilities::createLead();
76         $lead->opportunity_name = 'SBizzle Dollar Store';
77         $lead->save();
78         
79         $_REQUEST['module'] = 'Leads';
80         $_REQUEST['action'] = 'ConvertLead';
81         $_REQUEST['record'] = $lead->id;
82         
83         // Check that the opportunity name doesn't get populated when it's not in the Leads editview layout
84         require_once('include/MVC/Controller/ControllerFactory.php');
85         require_once('include/MVC/View/ViewFactory.php');
86         $GLOBALS['app']->controller = ControllerFactory::getController($_REQUEST['module']);
87         ob_start();
88         $GLOBALS['app']->controller->execute();
89         $output = ob_get_clean();
90         
91         $matches_one = array();
92         $pattern = '/SBizzle Dollar Store/';
93         preg_match($pattern, $output, $matches_one);
94         $this->assertTrue(count($matches_one) == 0, "Opportunity name got carried over to the Convert Leads page when it shouldn't have.");
95
96         // Add the opportunity_name to the Leads EditView
97         SugarTestStudioUtilities::addFieldToLayout('Leads', 'editview', 'opportunity_name');
98         
99         // Check that the opportunity name now DOES get populated now that it's in the Leads editview layout
100         ob_start();
101         $GLOBALS['app']->controller = ControllerFactory::getController($_REQUEST['module']);
102         $GLOBALS['app']->controller->execute();
103         $output = ob_get_clean();
104         $matches_two = array();
105         $pattern = '/SBizzle Dollar Store/';
106         preg_match($pattern, $output, $matches_two);
107         $this->assertTrue(count($matches_two) > 0, "Opportunity name did not carry over to the Convert Leads page when it should have.");
108         
109         SugarTestStudioUtilities::removeAllCreatedFields();
110         unset($GLOBALS['app']->controller);
111         unset($_REQUEST['module']);
112         unset($_REQUEST['action']);
113         unset($_REQUEST['record']);
114         SugarTestLeadUtilities::removeAllCreatedLeads();
115     }
116
117     /**
118      * @group bug44033
119      */
120     public function testActivityMove() {
121         // init
122         $lead = SugarTestLeadUtilities::createLead();
123         $contact = SugarTestContactUtilities::createContact();
124         $meeting = SugarTestMeetingUtilities::createMeeting();
125         SugarTestMeetingUtilities::addMeetingParent($meeting->id, $lead->id);
126         $relation_id = SugarTestMeetingUtilities::addMeetingLeadRelation($meeting->id, $lead->id);
127         $_REQUEST['record'] = $lead->id;
128
129         // refresh the meeting to include parent_id and parent_type
130         $meeting_id = $meeting->id;
131         $meeting = new Meeting();
132         $meeting->retrieve($meeting_id);
133
134         // action: move meeting from lead to contact
135         $convertObj = new TestViewConvertLead();
136         $convertObj->moveActivityWrapper($meeting, $contact);
137
138         // verification 1, parent id should be contact id
139         $this->assertTrue($meeting->parent_id == $contact->id, 'Meeting parent id is not converted to contact id.');
140
141         // verification 2, parent type should be "Contacts"
142         $this->assertTrue($meeting->parent_type == 'Contacts', 'Meeting parent type is not converted to Contacts.');
143
144         // verification 3, record should be deleted from meetings_leads table
145         $sql = "select id from meetings_leads where meeting_id='{$meeting->id}' and lead_id='{$lead->id}' and deleted=0";
146         $result = $GLOBALS['db']->query($sql);
147         $row = $GLOBALS['db']->fetchByAssoc($result);
148         $this->assertFalse($row, "Meeting-Lead relationship is not removed.");
149
150         // verification 4, record should be added to meetings_contacts table
151         $sql = "select id from meetings_contacts where meeting_id='{$meeting->id}' and contact_id='{$contact->id}' and deleted=0";
152         $result = $GLOBALS['db']->query($sql);
153         $row = $GLOBALS['db']->fetchByAssoc($result);
154         $this->assertFalse(empty($row), "Meeting-Contact relationship is not added.");
155
156         // clean up
157         unset($_REQUEST['record']);
158         $GLOBALS['db']->query("delete from meetings_contacts where meeting_id='{$meeting->id}' and contact_id= '{$contact->id}'");
159         SugarTestMeetingUtilities::deleteMeetingLeadRelation($relation_id);
160         SugarTestMeetingUtilities::removeMeetingContacts();
161         SugarTestMeetingUtilities::removeAllCreatedMeetings();
162         SugarTestContactUtilities::removeAllCreatedContacts();
163         SugarTestLeadUtilities::removeAllCreatedLeads();
164     }
165
166
167     public function testActivityCopyWithParent() {
168         // lets the run the activity copy again, only this time we pass in a parent account
169         $lead = SugarTestLeadUtilities::createLead();
170         $contact = SugarTestContactUtilities::createContact();
171         $meeting = SugarTestMeetingUtilities::createMeeting();
172         $account = SugarTestAccountUtilities::createAccount();
173         SugarTestMeetingUtilities::addMeetingParent($meeting->id, $lead->id);
174                 $relation_id = SugarTestMeetingUtilities::addMeetingLeadRelation($meeting->id, $lead->id);
175         $_REQUEST['record'] = $lead->id;
176
177         // refresh the meeting to include parent_id and parent_type
178         $meeting_id = $meeting->id;
179         $meeting = new Meeting();
180         $meeting->retrieve($meeting_id);
181
182         // action: copy meeting from lead to contact
183         $convertObj = new TestViewConvertLead();
184         $convertObj->copyActivityWrapper($meeting, $contact, array('id'=>$account->id,'type'=>'Accounts'));
185
186
187         // 2a a newly created meeting with no parent info passed in, so parent id and type are empty
188         //parent type=Contatcs and parent_id=$contact->id
189         //$sql = "select id from meetings where parent_id='{$contact->id}' and parent_type= 'Contacts' and deleted=0";
190         $sql = "select id, parent_id from meetings where name = '{$meeting->name}'";
191         $result = $GLOBALS['db']->query($sql);
192         while ($row = $GLOBALS['db']->fetchByAssoc($result)){
193             //skip if this is the original message
194             if($row['id'] == $meeting_id){
195                 continue;
196             }
197
198             $this->assertEquals($row['parent_id'], $account->id, 'parent id of meeting should be equal to passed in account id: '.$account->id);
199         }
200
201     }
202
203     
204     public function testActivityCopyWithNoParent() {
205         // init
206         $lead = SugarTestLeadUtilities::createLead();
207         $contact = SugarTestContactUtilities::createContact();
208         $meeting = SugarTestMeetingUtilities::createMeeting();
209         SugarTestMeetingUtilities::addMeetingParent($meeting->id, $lead->id);
210         $relation_id = SugarTestMeetingUtilities::addMeetingLeadRelation($meeting->id, $lead->id);
211         $_REQUEST['record'] = $lead->id;
212
213         // refresh the meeting to include parent_id and parent_type
214         $meeting_id = $meeting->id;
215         $meeting = new Meeting();
216         $meeting->retrieve($meeting_id);
217
218         // action: copy meeting from lead to contact
219         $convertObj = new TestViewConvertLead();
220         $convertObj->copyActivityWrapper($meeting, $contact);
221
222         // 1. the original meeting should still have the same parent_type and parent_id
223         $meeting->retrieve($meeting_id);
224         $this->assertEquals('Leads', $meeting->parent_type, 'parent_type of the original meeting was changed from Leads to '.$meeting->parent_type);
225         $this->assertEquals($lead->id, $meeting->parent_id, 'parent_id of the original meeting was changed from '.$lead->id.' to '.$meeting->parent_id);
226
227         // 2. a newly created meeting with no parent info passed in, so parent id and type are empty
228         $new_meeting_id = '';
229         $sql = "select id, parent_id from meetings where name = '{$meeting->name}'";
230               $result = $GLOBALS['db']->query($sql);
231               while ($row = $GLOBALS['db']->fetchByAssoc($result)){
232                   //skip if this is the original message
233                   if($row['id'] == $meeting_id){
234                       continue;
235                   }
236                   $new_meeting_id = $row['id'];
237                   $this->assertEmpty($row['parent_id'],'parent id of meeting should be empty as no parent was sent in ');
238               }
239
240
241
242         // 3. record should not be deleted from meetings_leads table
243         $sql = "select id from meetings_leads where meeting_id='{$meeting->id}' and lead_id='{$lead->id}' and deleted=0";
244         $result = $GLOBALS['db']->query($sql);
245         $row = $GLOBALS['db']->fetchByAssoc($result);
246         $this->assertNotNull($row, "Meeting-Lead relationship was removed.");
247
248         // 4. new meeting record should be added to meetings_contacts table
249         $sql = "select id from meetings_contacts where meeting_id='{$new_meeting_id}' and contact_id='{$contact->id}' and deleted=0";
250         $result = $GLOBALS['db']->query($sql);
251         $row = $GLOBALS['db']->fetchByAssoc($result);
252         $this->assertFalse(empty($row), "Meeting-Contact relationship has not been added.");
253
254         // clean up
255         unset($_REQUEST['record']);
256         $GLOBALS['db']->query("delete from meetings where parent_id='{$contact->id}' and parent_type= 'Contacts'");
257         $GLOBALS['db']->query("delete from meetings where parent_id='{$lead->id}' and parent_type= 'Leads'");
258         $GLOBALS['db']->query("delete from meetings_contacts where meeting_id='{$new_meeting_id}' and contact_id= '{$contact->id}'");
259         SugarTestMeetingUtilities::deleteMeetingLeadRelation($relation_id);
260         SugarTestMeetingUtilities::removeMeetingContacts();
261         SugarTestMeetingUtilities::removeAllCreatedMeetings();
262         SugarTestContactUtilities::removeAllCreatedContacts();
263         SugarTestLeadUtilities::removeAllCreatedLeads();
264     }
265
266     /**
267      * @outputBuffering enabled
268      */
269     public function testConversionAndMoveActivities() {
270         global $sugar_config;
271
272         // init
273         $lead = SugarTestLeadUtilities::createLead();
274         $account = SugarTestAccountUtilities::createAccount();
275         $meeting = SugarTestMeetingUtilities::createMeeting();
276         SugarTestMeetingUtilities::addMeetingParent($meeting->id, $lead->id);
277         $relation_id = SugarTestMeetingUtilities::addMeetingLeadRelation($meeting->id, $lead->id);
278         $_REQUEST['record'] = $lead->id;
279
280         // set the request/post parameters before converting the lead
281         $_REQUEST['module'] = 'Leads';
282         $_REQUEST['action'] = 'ConvertLead';
283         $_REQUEST['record'] = $lead->id;
284         $_REQUEST['handle'] = 'save';
285         $_REQUEST['selectedAccount'] = $account->id;
286         $sugar_config['lead_conv_activity_opt'] = 'move';
287         $_POST['lead_conv_ac_op_sel'] = 'Contacts';
288
289         // call display to trigger conversion
290         $vc = new ViewConvertLead();
291         $vc->display();
292
293         // refresh meeting
294         $meeting_id = $meeting->id;
295         $meeting = new Meeting();
296         $meeting->retrieve($meeting_id);
297
298         // refresh lead
299         $lead_id = $lead->id;
300         $lead = new Lead();
301         $lead->retrieve($lead_id);
302
303         // retrieve the new contact id from the conversion
304         $contact_id = $lead->contact_id;
305
306         // 1. Lead's contact_id should not be null
307         $this->assertNotNull($contact_id, 'Lead has null contact id after conversion.');
308
309         // 2. Lead status should be 'Converted'
310         $this->assertEquals('Converted', $lead->status, "Lead atatus should be 'Converted'.");
311
312         // 3. new parent_type should be Contacts
313         $this->assertEquals('Contacts', $meeting->parent_type, 'Meeting parent type has not been set to Contacts');
314
315         // 4. new parent_id should be contact id
316         $this->assertEquals($contact_id, $meeting->parent_id, 'Meeting parent id has not been set to contact id.');
317
318         // 5. record should be deleted from meetings_leads table
319         $sql = "select id from meetings_leads where meeting_id='{$meeting->id}' and lead_id='{$lead->id}' and deleted=0";
320         $result = $GLOBALS['db']->query($sql);
321         $row = $GLOBALS['db']->fetchByAssoc($result);
322         $this->assertFalse($row, "Meeting-Lead relationship is not removed.");
323
324         // 6. record should be added to meetings_contacts table
325         $sql = "select id from meetings_contacts where meeting_id='{$meeting->id}' and contact_id='{$contact_id}' and deleted=0";
326         $result = $GLOBALS['db']->query($sql);
327         $row = $GLOBALS['db']->fetchByAssoc($result);
328         $this->assertFalse(empty($row), "Meeting-Contact relationship is not added.");
329
330         // clean up
331         unset($_REQUEST['record']);
332         $GLOBALS['db']->query("delete from meetings where parent_id='{$lead->id}' and parent_type= 'Leads'");
333         $GLOBALS['db']->query("delete from meetings where parent_id='{$contact_id}' and parent_type= 'Contacts'");
334         $GLOBALS['db']->query("delete from contacts where id='{$contact_id}'");
335         $GLOBALS['db']->query("delete from meetings_contacts where meeting_id='{$meeting->id}' and contact_id= '{$contact_id}'");
336         SugarTestMeetingUtilities::deleteMeetingLeadRelation($relation_id);
337         SugarTestMeetingUtilities::removeMeetingContacts();
338         SugarTestMeetingUtilities::removeAllCreatedMeetings();
339         SugarTestAccountUtilities::removeAllCreatedAccounts();
340         SugarTestLeadUtilities::removeAllCreatedLeads();
341     }
342
343     /**
344      * @outputBuffering enabled
345      */
346     public function testConversionAndCopyActivities() {
347         global $sugar_config;
348
349         // init
350         $lead = SugarTestLeadUtilities::createLead();
351         $account = SugarTestAccountUtilities::createAccount();
352         $meeting = SugarTestMeetingUtilities::createMeeting();
353         SugarTestMeetingUtilities::addMeetingParent($meeting->id, $lead->id);
354         $relation_id = SugarTestMeetingUtilities::addMeetingLeadRelation($meeting->id, $lead->id);
355         $_REQUEST['record'] = $lead->id;
356
357         // set the request/post parameters before converting the lead
358         $_REQUEST['module'] = 'Leads';
359         $_REQUEST['action'] = 'ConvertLead';
360         $_REQUEST['record'] = $lead->id;
361         $_REQUEST['handle'] = 'save';
362         $_REQUEST['selectedAccount'] = $account->id;
363         $sugar_config['lead_conv_activity_opt'] = 'copy';
364         $_POST['lead_conv_ac_op_sel'] = array('Contacts');
365
366         // call display to trigger conversion
367         $vc = new ViewConvertLead();
368         $vc->display();
369
370         // refresh meeting
371         $meeting_id = $meeting->id;
372         $meeting = new Meeting();
373         $meeting->retrieve($meeting_id);
374
375         // refresh lead
376         $lead_id = $lead->id;
377         $lead = new Lead();
378         $lead->retrieve($lead_id);
379
380         // retrieve the new contact id from the conversion
381         $contact_id = $lead->contact_id;
382
383         // 1. Lead's contact_id should not be null
384         $this->assertNotNull($contact_id, 'Lead has null contact id after conversion.');
385
386         // 2. Lead status should be 'Converted'
387         $this->assertEquals('Converted', $lead->status, "Lead atatus should be 'Converted'.");
388
389         // 3. parent_type of the original meeting should be Leads
390         $this->assertEquals('Leads', $meeting->parent_type, 'Meeting parent should be Leads');
391
392         // 4. parent_id of the original meeting should be contact id
393         $this->assertEquals($lead_id, $meeting->parent_id, 'Meeting parent id should be lead id.');
394
395         // 5. record should NOT be deleted from meetings_leads table
396         $sql = "select id from meetings_leads where meeting_id='{$meeting->id}' and lead_id='{$lead->id}' and deleted=0";
397         $result = $GLOBALS['db']->query($sql);
398         $row = $GLOBALS['db']->fetchByAssoc($result);
399         $this->assertFalse(empty($row), "Meeting-Lead relationship is removed.");
400
401         // 6. record should be added to meetings_contacts table
402         $sql = "select meeting_id from meetings_contacts where contact_id='{$contact_id}' and deleted=0";
403         $result = $GLOBALS['db']->query($sql);
404         $row = $GLOBALS['db']->fetchByAssoc($result);
405         $this->assertFalse(empty($row), "Meeting-Contact relationship is not added.");
406
407         // 7. the parent_type of the new meeting should be empty
408         $new_meeting_id = $row['meeting_id'];
409         $sql = "select id, parent_type, parent_id from meetings where id='{$new_meeting_id}' and deleted=0";
410         $result = $GLOBALS['db']->query($sql);
411         $row = $GLOBALS['db']->fetchByAssoc($result);
412         $this->assertFalse(empty($row), "New meeting is not added for contact.");
413         $this->assertEmpty($row['parent_type'], 'Parent type of the new meeting should be Empty');
414
415         // 8. the parent_id of the new meeting should be contact id
416         $this->assertEmpty($row['parent_id'], 'Parent id of the new meeting should be empty.');
417
418        // clean up
419         unset($_REQUEST['record']);
420         $GLOBALS['db']->query("delete from meetings where parent_id='{$lead->id}' and parent_type= 'Leads'");
421         $GLOBALS['db']->query("delete from meetings where parent_id='{$contact_id}' and parent_type= 'Contacts'");
422         $GLOBALS['db']->query("delete from contacts where id='{$contact_id}'");
423         $GLOBALS['db']->query("delete from meetings_leads where meeting_id='{$meeting->id}' and lead_id= '{$lead_id}'");
424         $GLOBALS['db']->query("delete from meetings_contacts where contact_id= '{$contact_id}'");
425         SugarTestMeetingUtilities::deleteMeetingLeadRelation($relation_id);
426         SugarTestMeetingUtilities::removeMeetingContacts();
427         SugarTestMeetingUtilities::removeAllCreatedMeetings();
428         SugarTestAccountUtilities::removeAllCreatedAccounts();
429         SugarTestLeadUtilities::removeAllCreatedLeads();
430     }
431
432     /**
433      * @outputBuffering enabled
434      */
435     public function testConversionAndDoNothing() {
436         global $sugar_config;
437
438         // init
439         $lead = SugarTestLeadUtilities::createLead();
440         $account = SugarTestAccountUtilities::createAccount();
441         $meeting = SugarTestMeetingUtilities::createMeeting();
442         SugarTestMeetingUtilities::addMeetingParent($meeting->id, $lead->id);
443         $relation_id = SugarTestMeetingUtilities::addMeetingLeadRelation($meeting->id, $lead->id);
444         $_REQUEST['record'] = $lead->id;
445
446         // set the request/post parameters before converting the lead
447         $_REQUEST['module'] = 'Leads';
448         $_REQUEST['action'] = 'ConvertLead';
449         $_REQUEST['record'] = $lead->id;
450         $_REQUEST['handle'] = 'save';
451         $_REQUEST['selectedAccount'] = $account->id;
452         $sugar_config['lead_conv_activity_opt'] = 'none';
453
454         // call display to trigger conversion
455         $vc = new ViewConvertLead();
456         $vc->display();
457
458         // refresh meeting
459         $meeting_id = $meeting->id;
460         $meeting = new Meeting();
461         $meeting->retrieve($meeting_id);
462
463         // refresh lead
464         $lead_id = $lead->id;
465         $lead = new Lead();
466         $lead->retrieve($lead_id);
467
468         // retrieve the new contact id from the conversion
469         $contact_id = $lead->contact_id;
470
471         // 1. Lead's contact_id should not be null
472         $this->assertNotNull($contact_id, 'Lead has null contact id after conversion.');
473
474         // 2. Lead status should be 'Converted'
475         $this->assertEquals('Converted', $lead->status, "Lead atatus should be 'Converted'.");
476
477         // 3. parent_type of the original meeting should be Leads
478         $this->assertEquals('Leads', $meeting->parent_type, 'Meeting parent should be Leads');
479
480         // 4. parent_id of the original meeting should be contact id
481         $this->assertEquals($lead_id, $meeting->parent_id, 'Meeting parent id should be lead id.');
482
483         // 5. record should NOT be deleted from meetings_leads table
484         $sql = "select id from meetings_leads where meeting_id='{$meeting->id}' and lead_id='{$lead->id}' and deleted=0";
485         $result = $GLOBALS['db']->query($sql);
486         $row = $GLOBALS['db']->fetchByAssoc($result);
487         $this->assertFalse(empty($row), "Meeting-Lead relationship is removed.");
488
489         // 6. record should NOT be added to meetings_contacts table
490         $sql = "select meeting_id from meetings_contacts where contact_id='{$contact_id}' and deleted=0";
491         $result = $GLOBALS['db']->query($sql);
492         $row = $GLOBALS['db']->fetchByAssoc($result);
493         $this->assertFalse($row, "Meeting-Contact relationship should not be added.");
494
495         // clean up
496         unset($_REQUEST['record']);
497         $GLOBALS['db']->query("delete from meetings where parent_id='{$lead->id}' and parent_type= 'Leads'");
498         $GLOBALS['db']->query("delete from meetings where parent_id='{$contact_id}' and parent_type= 'Contacts'");
499         $GLOBALS['db']->query("delete from contacts where id='{$contact_id}'");
500         $GLOBALS['db']->query("delete from meetings_leads where meeting_id='{$meeting->id}' and lead_id= '{$lead_id}'");
501         $GLOBALS['db']->query("delete from meetings_contacts where contact_id= '{$contact_id}'");
502         SugarTestMeetingUtilities::deleteMeetingLeadRelation($relation_id);
503         SugarTestMeetingUtilities::removeMeetingContacts();
504         SugarTestMeetingUtilities::removeAllCreatedMeetings();
505         SugarTestAccountUtilities::removeAllCreatedAccounts();
506         SugarTestLeadUtilities::removeAllCreatedLeads();
507     }
508
509     public function testMeetingsUsersRelationships()
510     {
511         global $current_user;
512
513         $bean = SugarTestMeetingUtilities::createMeeting();
514         $convert_lead = SugarTestViewConvertLeadUtilities::createViewConvertLead();
515
516         if ($bean->object_name == "Meeting")
517         {
518             $convert_lead->setMeetingsUsersRelationship($bean);
519         }
520
521         $this->assertTrue(is_object($bean->users), "Relationship wasn't set.");
522
523         SugarTestMeetingUtilities::removeMeetingUsers();
524         SugarTestMeetingUtilities::removeAllCreatedMeetings();
525     }
526 }
527
528 class TestViewConvertLead extends ViewConvertLead
529 {
530     public function moveActivityWrapper($activity, $bean) {
531         parent::moveActivity($activity, $bean);
532     }
533
534     public function copyActivityWrapper($activity, $bean,$parent=array()) {
535         parent::copyActivityAndRelateToBean($activity, $bean,$parent);
536     }
537
538     public function testMeetingsUsersRelationships()
539     {
540         global $current_user;
541         
542         $bean = SugarTestMeetingUtilities::createMeeting();
543         $convert_lead = SugarTestViewConvertLeadUtilities::createViewConvertLead();
544         
545         if ($bean->object_name == "Meeting")
546         {
547             $convert_lead->setMeetingsUsersRelationship($bean);
548         }
549         
550         $this->assertTrue(is_object($bean->users), "Relationship wasn't set.");
551         
552         SugarTestMeetingUtilities::removeMeetingUsers();
553         SugarTestMeetingUtilities::removeAllCreatedMeetings();
554     }
555 }