2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 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 ********************************************************************************/
37 //Helper functions used by both SOAP and REST Unit Test Calls.
42 function populateSeedDataForSearchTest($user_id)
45 $a1_id = create_guid();
48 $a1->new_with_id = TRUE;
49 $a1->name = "UNIT TEST $a1_id";
50 $a1->assigned_user_id = $user_id;
52 $results[] = array('id' => $a1_id, 'fieldName' => 'name', 'fieldValue' => "UNIT TEST $a1_id");
54 $a2_id = create_guid();
56 $a2->new_with_id = TRUE;
58 $a2->name = "UNIT TEST $a2_id";
59 $a2->assigned_user_id = 'unittest';
61 $results[] = array('id' => $a2_id, 'fieldName' => 'name', 'fieldValue' => "UNIT TEST $a2_id");
63 $c1_id = create_guid();
66 $c1->new_with_id = TRUE;
67 $c1->first_name = "UNIT TEST";
68 $c1->last_name = "UNIT_TEST";
69 $c1->assigned_user_id = $user_id;
71 $results[] = array('id' => $c1_id, 'fieldName' => 'name', 'fieldValue' => $c1->first_name .' ' . $c1->last_name);
73 $op1_id = create_guid();
74 $op1 = new Opportunity();
75 $op1->new_with_id = TRUE;
77 $op1->name = "UNIT TEST $op1_id";
78 $op1->assigned_user_id = $user_id;
80 $results[] = array('id' => $op1_id, 'fieldName' => 'name', 'fieldValue' => "UNIT TEST $op1_id");
82 $op2_id = create_guid();
83 $op2 = new Opportunity();
84 $op2->new_with_id = TRUE;
86 $op2->name = "UNIT TEST $op2_id";
87 $op2->assigned_user_id = 'unittest';
89 $results[] = array('id' => $op2_id, 'fieldName' => 'name', 'fieldValue' => "UNIT TEST $op2_id");
95 * Linear search function used to find a bean id in an entry list array.
98 * @param string $bean_id
100 function findBeanIdFromEntryList($list,$bean_id,$module)
103 foreach ($list as $moduleEntry)
105 if($moduleEntry['name'] == $module)
107 foreach ($moduleEntry['records'] as $entry)
109 foreach ($entry as $fieldEntry)
111 if($fieldEntry['name'] == 'id' && $fieldEntry['value'] == $bean_id )
122 * Linear search function used to find a particular field in an entry list array.
125 * @param string $bean_id
127 function findFieldByNameFromEntryList($list,$bean_id,$module,$fieldName)
131 foreach ($list as $moduleEntry)
133 if($moduleEntry['name'] == $module)
135 foreach ($moduleEntry['records'] as $entry)
137 $value = $this->_retrieveFieldValueByFieldName($entry, $fieldName,$bean_id);
147 function _retrieveFieldValueByFieldName($entry, $fieldName, $beanId)
151 foreach ($entry as $fieldEntry)
153 if($fieldEntry['name'] == 'id' && $fieldEntry['value'] == $beanId )
156 if($fieldEntry['name'] == $fieldName )
157 $fieldValue = $fieldEntry['value'];