2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 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 ********************************************************************************/
38 require_once "modules/Tasks/Task.php";
39 require_once "modules/Contacts/Contact.php";
40 require_once "include/SearchForm/SearchForm2.php";
44 * Test checks if SearchDef with 'force_unifiedsearch' => true concatenates the db_field array properly,
45 * when the search value is a multiple word term (contains space between the words)
47 * @author snigam@sugarcrm.com, avucinic@sugarcrm.com
50 class Bug45709_53785_Test extends Sugar_PHPUnit_Framework_TestCase
55 var $requestArray = null;
56 var $searchForm = null;
58 public function setUp()
60 SugarTestHelper::setUp('app_list_strings');
61 SugarTestHelper::setUp('app_strings');
62 SugarTestHelper::setUp('current_user');
64 $this->contact = SugarTestContactUtilities::createContact();
65 $this->task = SugarTestTaskUtilities::createTask();
66 $this->task->contact_id = $this->contact->id;
70 public function tearDown()
72 SugarTestContactUtilities::removeAllCreatedContacts();
73 SugarTestTaskUtilities::removeAllCreatedTasks();
74 SugarTestHelper::tearDown();
80 public function testGenerateSearchWhereForFieldsWhenFullContactNameGiven()
82 // Array to simulate REQUEST object
83 $this->requestArray['module'] = 'Tasks';
84 $this->requestArray['action'] = 'index';
85 $this->requestArray['searchFormTab'] = 'advanced_search';
86 $this->requestArray['contact_name_advanced'] = $this->contact->first_name . " " . $this->contact->last_name; //value of a contact name field set in REQUEST object
87 $this->requestArray['query'] = 'true';
89 // Initialize search form
90 $this->searchForm = new SearchForm($this->task, 'Tasks');
92 // Load the vardefs and search metadata
93 require 'modules/Tasks/vardefs.php';
94 require 'modules/Tasks/metadata/SearchFields.php';
95 require 'modules/Tasks/metadata/searchdefs.php';
96 $this->searchForm->searchFields = $searchFields[$this->searchForm->module];
97 $this->searchForm->searchdefs = $searchdefs[$this->searchForm->module];
98 $this->searchForm->fieldDefs = $this->task->getFieldDefinitions();
100 // Fill the data from the array we are using to simulate REQUEST
101 $this->searchForm->populateFromArray($this->requestArray,'advanced_search',false);
103 // Get the generated search clause
104 $whereArray = $this->searchForm->generateSearchWhere(true, $this->task->module_dir);
106 // And use it to load the contact created
107 $test_query = "SELECT id FROM contacts WHERE " . $whereArray[0];
108 $result = $GLOBALS['db']->query($test_query);
109 $row = $GLOBALS['db']->fetchByAssoc($result);
111 // Check if the contact was successfully loaded
112 $this->assertEquals($this->contact->id, $row['id'], "Didn't find the correct contact id");
114 // Load the task using the contact_id we got from the previous query
115 $result2 = $GLOBALS['db']->query("SELECT * FROM tasks WHERE tasks.contact_id='{$this->task->contact_id}'");
116 $row2 = $GLOBALS['db']->fetchByAssoc($result2);
118 // Check if the task is loaded properly
119 $this->assertEquals($this->task->id, $row2['id'], "Couldn't find the expected related task");