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 * SoapRelationshipHelperTest.php
40 * This test may be used to write tests against the SoapRelationshipHelper.php file and the utility functions found there.
44 require_once('soap/SoapRelationshipHelper.php');
45 class SoapRelationshipHelperTest extends Sugar_PHPUnit_Framework_TestCase
48 var $noSoapErrorArray = array('number'=>0, 'name'=>'No Error', 'description'=>'No Error');
49 var $callsAndMeetingsSelectFields = array('id', 'date_modified', 'deleted', 'name', 'rt.deleted synced');
50 var $tasksSelectFields = array('id', 'date_modified', 'deleted', 'name');
51 var $contactsSelectFields = array('id', 'date_modified', 'deleted', 'first_name', 'last_name', 'rt.deleted synced', "(SELECT email_addresses.email_address FROM contacts LEFT JOIN email_addr_bean_rel on contacts.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module='Contacts' and email_addr_bean_rel.deleted=0 and email_addr_bean_rel.primary_address=1 LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id Where contacts.ID = m1.ID) email1","(SELECT email_addresses.email_address FROM contacts LEFT JOIN email_addr_bean_rel on contacts.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module='Contacts' and email_addr_bean_rel.deleted=0 and email_addr_bean_rel.primary_address!=1 LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id Where contacts.ID = m1.ID Limit 1) email2");
57 var $tenMinutesLaterTime;
60 public function setUp()
62 global $timedate, $current_user;
63 $timedate = TimeDate::getInstance();
64 require('include/modules.php');
65 $GLOBALS['beanList'] = $beanList;
66 $GLOBALS['beanFiles'] = $beanFiles;
67 $current_user = SugarTestUserUtilities::createAnonymousUser();
68 $this->nowTime = $timedate->asDb($timedate->getNow()->get("-10 minutes"));
69 $this->tenMinutesLaterTime = $timedate->asDb($timedate->getNow()->get("+10 minutes"));
70 $current_user->is_admin = 1;
71 $current_user->save();
72 $this->meeting = SugarTestMeetingUtilities::createMeeting();
73 $this->meeting->team_id = $current_user->team_id;
74 $this->meeting->team_set_id = $current_user->team_set_id;
75 $this->meeting->team_id = $current_user->team_id;
76 $this->meeting->team_set_id = $current_user->team_set_id;
77 $this->meeting->assigned_user_id = $current_user->id;
78 $this->meeting->save();
79 $this->meeting->load_relationship('users');
80 $this->meeting->users->add($current_user);
81 $this->call = SugarTestCallUtilities::createCall();
82 $this->call->team_id = $current_user->team_id;
83 $this->call->team_set_id = $current_user->team_set_id;
84 $this->call->assigned_user_id = $current_user->id;
86 $this->call->load_relationships('users');
87 $this->call->users->add($current_user);
88 $this->contact = SugarTestContactUtilities::createContact();
89 $this->contact->email1 = 'mark.zuckerberg@facebook.com';
90 $this->contact->contacts_users_id = $current_user->id;
91 $this->contact->load_relationship('user_sync');
92 $this->contact->user_sync->add($current_user);
93 $this->contact->sync_contact = 1;
94 $this->contact->save();
95 $this->task = SugarTestTaskUtilities::createTask();
96 $this->task->assigned_user_id = $current_user->id;
97 $this->task->team_id = $current_user->id;
98 $this->task->team_set_id = $current_user->id;
101 //$this->useOutputBuffering = false;
103 * This provider returns an Array of Array data. Each Array contains the following data
104 * 0 => String - Left side module name
105 * 1 => String - Right side module name
106 * 2 => String - Relationship Query
107 * 3 => boolean to return deleted records or not (this is actually ignored by the function)
108 * 4 => integer offset to start with
109 * 5 => integer value for the maximum number of results
110 * 6 => array of fields to select and return
111 * 7 => load_relationships - Relationship name to use
112 * 8 => array of expected results
113 * 9 => integer of expected total count
114 * 10 => array of expected soap error
115 * @return array The provider array
117 $this->testData = array(
118 array('Users', 'Meetings', "( (m1.date_modified > '{$this->nowTime}' AND m1.date_modified <= '{$this->tenMinutesLaterTime}' AND m1.deleted = 0) OR (m1.date_modified > '{$this->nowTime}' AND m1.date_modified <= '{$this->tenMinutesLaterTime}' AND m1.deleted = 1) AND m1.id IN ('{$this->meeting->id}')) OR (m1.id NOT IN ('{$this->meeting->id}') AND m1.deleted = 0) AND m2.id = '{$current_user->id}'", 0, 0 , 3000, $this->callsAndMeetingsSelectFields, 'meetings_users', array('id'=>$this->meeting->id), 1, $this->noSoapErrorArray),
119 array('Users', 'Calls', "( m1.deleted = 0) AND m2.id = '{$current_user->id}'",0,0,3000,$this->callsAndMeetingsSelectFields, 'calls_users', array('id'=>$this->call->id), 1, $this->noSoapErrorArray),
120 array('Users', 'Contacts', "( (m1.date_modified > '{$this->nowTime}' AND m1.date_modified <= '{$this->tenMinutesLaterTime}' AND {0}.deleted = 0) OR ({0}.date_modified > '{$this->nowTime}' AND {0}.date_modified <= '{$this->tenMinutesLaterTime}' AND {0}.deleted = 1) AND m1.id IN ('31a219bd-b9c1-2c3e-aa5d-4f2778ab0347','c794bc39-e4fb-f515-f1d5-4f285ca88965','d51a0555-8f84-9e62-0fbc-4f2787b5d839','a1219ae6-5a6b-0d1b-c49f-4f2854bc2912')) OR (m1.id NOT IN ('31a219bd-b9c1-2c3e-aa5d-4f2778ab0347','c794bc39-e4fb-f515-f1d5-4f285ca88965','d51a0555-8f84-9e62-0fbc-4f2787b5d839','a1219ae6-5a6b-0d1b-c49f-4f2854bc2912') AND {0}.deleted = 0) AND m2.id = '1'", 0, 0 , 3000, $this->contactsSelectFields, 'contacts_users', array('id'=>$this->contact->id, 'email1'=>'mark.zuckerberg@facebook.com'), 1, $this->noSoapErrorArray),
121 array('Users', 'Tasks', " ( (m1.date_modified > '{$this->nowTime}' AND m1.date_modified <= '{$this->tenMinutesLaterTime}' AND {0}.deleted = 0) OR ({0}.date_modified > '{$this->nowTime}' AND {0}.date_modified <= '{$this->tenMinutesLaterTime}' AND {0}.deleted = 1) AND m1.id IN ('{$this->task->id}')) OR (m1.id NOT IN ('{$this->task->id}') AND {0}.deleted = 0) AND m2.id = '1'", 0, 0, 3000, $this->tasksSelectFields, 'tasks_assigned_user', array('id'=>$this->task->id), 1, $this->noSoapErrorArray),
125 public function tearDown()
127 global $current_user;
128 $GLOBALS['db']->query("DELETE FROM meetings_users WHERE user_id = '{$current_user->id}'");
129 $GLOBALS['db']->query("DELETE FROM calls_users WHERE user_id = '{$current_user->id}'");
130 $GLOBALS['db']->query("DELETE FROM contacts_users WHERE user_id = '{$current_user->id}'");
131 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
132 SugarTestMeetingUtilities::removeAllCreatedMeetings();
133 SugarTestCallUtilities::removeAllCreatedCalls();
134 SugarTestContactUtilities::removeAllCreatedContacts();
135 SugarTestTaskUtilities::removeAllCreatedTasks();
136 unset($GLOBALS['current_user']);
137 unset($GLOBALS['beanFiles']);
138 unset($GLOBALS['beanList']);
143 * testRetrieveModifiedRelationships
144 * This test checks to make sure we can correctly retrieve related Meetings and Calls (see bugs 50092 & 50093)
147 public function testRetrieveModifiedRelationships()
149 if($GLOBALS['db']->dbType != 'mysql' ) {
150 $this->markTestIncomplete("Currently these queries don't work on non-mysql DBs, skip until query is fixed.");
152 foreach($this->testData as $data)
154 //retrieve_modified_relationships($module_name, $related_module, $relationship_query, $show_deleted, $offset, $max_results, $select_fields = array(), $relationship_name = '')
156 $result = retrieve_modified_relationships($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]);
157 $this->assertEquals($data[8]['id'], $result['result'][0]['id'], 'Ids do not match');
158 $this->assertEquals($data[9], $result['total_count'], 'Totals do not match');
159 $this->assertEquals($data[10], $result['error'], 'No SOAP Error');