2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 require_once('data/SugarBean.php');
44 * This test handles verifying that the SQL string or array returned from the create_new_list_query call can properly
45 * processing the alter_many_to_many_query flag in SugarBean.
50 class Bug49385Test extends Sugar_PHPUnit_Framework_OutputTestCase
53 static $call_id = null;
54 static $meeting_id = null;
55 static $contact_id = null;
57 static public function setUpBeforeClass()
60 $current_user = SugarTestUserUtilities::createAnonymousUser();
62 global $beanList, $beanFiles;
63 require('include/modules.php');
65 $GLOBALS['db']->query("DELETE FROM meetings WHERE name = 'Bug49385Test'");
66 $GLOBALS['db']->query("DELETE FROM calls WHERE name = 'Bug49385Test'");
68 $contact1 = SugarTestContactUtilities::createContact();
69 Bug49385Test::$contact_id = $contact1->id;
71 $contact2 = SugarTestContactUtilities::createContact();
72 $contact3 = SugarTestContactUtilities::createContact();
74 $meeting = SugarTestMeetingUtilities::createMeeting();
75 Bug49385Test::$meeting_id = $meeting->id;
76 $meeting->name = 'Bug49385Test';
79 $data_values = array('accept_status'=>'none');
81 $relate_values = array('contact_id'=>$contact1->id,'meeting_id'=>$meeting->id);
82 $meeting->set_relationship($meeting->rel_contacts_table, $relate_values, true, true, $data_values);
84 $relate_values = array('contact_id'=>$contact2->id,'meeting_id'=>$meeting->id);
85 $meeting->set_relationship($meeting->rel_contacts_table, $relate_values, true, true, $data_values);
87 $relate_values = array('contact_id'=>$contact3->id,'meeting_id'=>$meeting->id);
88 $meeting->set_relationship($meeting->rel_contacts_table, $relate_values, true, true, $data_values);
90 $call = SugarTestCallUtilities::createCall();
91 Bug49385Test::$call_id = $call->id;
92 $call->name = 'Bug49385Test';
95 $relate_values = array('contact_id'=>$contact1->id,'call_id'=>$call->id);
96 $call->set_relationship($call->rel_contacts_table, $relate_values, true, true, $data_values);
98 $relate_values = array('contact_id'=>$contact2->id,'call_id'=>$call->id);
99 $call->set_relationship($call->rel_contacts_table, $relate_values, true, true, $data_values);
101 $relate_values = array('contact_id'=>$contact3->id,'call_id'=>$call->id);
102 $call->set_relationship($call->rel_contacts_table, $relate_values, true, true, $data_values);
106 static public function tearDownAfterClass()
108 SugarTestContactUtilities::removeAllCreatedContacts();
109 SugarTestMeetingUtilities::removeAllCreatedMeetings();
110 SugarTestCallUtilities::removeAllCreatedCalls();
111 $GLOBALS['db']->query("DELETE FROM meetings_contacts WHERE meeting_id = '" . Bug49385Test::$meeting_id . "'");
112 $GLOBALS['db']->query("DELETE FROM calls_contacts WHERE call_id = '" . Bug49385Test::$call_id . "'");
113 unset($GLOBALS['current_user']);
118 * testMeetingsController
120 * This tests the controller code added to make sure we get contacts displayed for the popup window
122 public function testMeetingsController()
124 require_once('modules/Meetings/controller.php');
125 $controller = new MeetingsController();
126 $_REQUEST['bean_id'] = Bug49385Test::$meeting_id;
127 $_REQUEST['related_id'] = Bug49385Test::$contact_id;
128 $controller->action_DisplayInline();
129 $this->expectOutputRegex('/SugarContact/');
134 * testCallsController
136 * This tests the controller code to make sure we get contacts displayed for the popup window
138 public function testCallsController()
140 require_once('modules/Calls/controller.php');
141 $controller = new CallsController();
142 $_REQUEST['bean_id'] = Bug49385Test::$call_id;
143 $_REQUEST['related_id'] = Bug49385Test::$contact_id;
144 $controller->action_DisplayInline();
145 $this->expectOutputRegex('/SugarContact/');
150 * testMeetingsCreateNewListQuery
152 * This tests the create_new_list_query function of Meetings module
154 public function testMeetingsCreateNewListQuery()
156 $meeting = new Meeting();
157 $order_by = 'name ASC';
158 $where = "(meetings.name like 'Bug49385Test%')";
175 'assigned_user_name' => 1,
177 'favorites_only' => 1
185 $ret_array = $meeting->create_new_list_query($order_by, $where, $filter, $params, 0, '', true, $meeting);
186 $ret_array['inner_join'] = '';
187 if (!empty($meeting->listview_inner_join)) {
188 $ret_array['inner_join'] = ' ' . implode(' ', $meeting->listview_inner_join) . ' ';
190 $sql = $ret_array['select'] . $ret_array['from'] . $ret_array['inner_join'] . $ret_array['where'] . $ret_array['order_by'];
191 $sql = $ret_array['select'] . $ret_array['from'] . $ret_array['where'] . $ret_array['order_by'];
193 $result = $GLOBALS['db']->query($sql);
195 while($row = $GLOBALS['db']->fetchByAssoc($result))
200 $this->assertEquals(1, $count, 'Assert that the query returned 1 rows');
205 'collection_list' => array()
208 $meeting = new Meeting();
209 $ret_array = $meeting->create_new_list_query($order_by, $where, $filter, $params, 0, '', true, $meeting);
210 $ret_array['inner_join'] = '';
211 if (!empty($meeting->listview_inner_join)) {
212 $ret_array['inner_join'] = ' ' . implode(' ', $meeting->listview_inner_join) . ' ';
214 $sql = $ret_array['select'] . $ret_array['from'] . $ret_array['inner_join'] . $ret_array['where'] . $ret_array['order_by'];
216 $result = $GLOBALS['db']->query($sql);
218 while($row = $GLOBALS['db']->fetchByAssoc($result))
223 $this->assertEquals(3, $count, 'Assert that the query returned 3 rows');
228 * testCallsCreateNewListQuery
230 * This tests the create_new_list_query function of Calls module
232 public function testCallsCreateNewListQuery()
235 $order_by = 'name ASC';
236 $where = "(calls.name like 'Bug49385Test%')";
253 'assigned_user_name' => 1,
255 'favorites_only' => 1
263 $ret_array = $call->create_new_list_query($order_by, $where, $filter, $params, 0, '', true, $call);
264 $ret_array['inner_join'] = '';
265 if (!empty($call->listview_inner_join)) {
266 $ret_array['inner_join'] = ' ' . implode(' ', $call->listview_inner_join) . ' ';
268 $sql = $ret_array['select'] . $ret_array['from'] . $ret_array['inner_join'] . $ret_array['where'] . $ret_array['order_by'];
270 $result = $GLOBALS['db']->query($sql);
272 while($row = $GLOBALS['db']->fetchByAssoc($result))
277 $this->assertEquals(1, $count, 'Assert that the query returned 1 row');
282 'collection_list' => array()
286 $ret_array = $call->create_new_list_query($order_by, $where, $filter, $params, 0, '', true, $call);
287 $ret_array['inner_join'] = '';
288 if (!empty($call->listview_inner_join)) {
289 $ret_array['inner_join'] = ' ' . implode(' ', $call->listview_inner_join) . ' ';
291 $sql = $ret_array['select'] . $ret_array['from'] . $ret_array['inner_join'] . $ret_array['where'] . $ret_array['order_by'];
293 $result = $GLOBALS['db']->query($sql);
295 while($row = $GLOBALS['db']->fetchByAssoc($result))
300 $this->assertEquals(3, $count, 'Assert that the query returned 3 rows');
306 class Bug49385SugarBeanMock extends SugarBean
308 public function create_many_to_many_query($ret_array=array())
310 return parent::create_many_to_many_query($ret_array);