]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/SearchForm/Bug45709Test.php
Release 6.4.0
[Github/sugarcrm.git] / tests / include / SearchForm / Bug45709Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 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 "modules/Tasks/Task.php";
39 require_once "modules/Contacts/Contact.php";
40 require_once "include/SearchForm/SearchForm2.php";
41
42 class Bug45709Test extends Sugar_PHPUnit_Framework_TestCase
43 {
44         var $task = null;
45         var $contact = null;
46         var $requestArray = null;
47         var $searchForm = null;
48
49     public function setUp()
50     {
51                 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
52                 $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
53                 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
54                 $this->contact = SugarTestContactUtilities::createContact();
55         $this->task =SugarTestTaskUtilities::createTask();
56         $this->task->contact_id = $this->contact->id;
57         $this->task->save();
58     }
59
60     public function tearDown()
61     {
62
63         SugarTestContactUtilities::removeAllCreatedContacts();
64         SugarTestTaskUtilities::removeAllCreatedTasks();
65         unset($GLOBALS['current_user']);
66     }
67
68     /**
69      * @ticket 45709
70      */
71     public function testGenerateSearchWhereForFieldsWhenFullContactNameGiven()
72     {
73         //test GenerateSearchWhere for fields that have db_concat_fields set in vardefs
74         //Contact in advanced search panel in Tasks module is one of those
75
76         //array to simulate REQUEST object
77         $this->requestArray['module'] = 'Tasks';
78         $this->requestArray['action'] = 'index';
79         $this->requestArray['searchFormTab'] = 'advanced_search';
80         $this->requestArray['contact_name_advanced'] = $this->contact->first_name. " ". $this->contact->last_name; //value of a contact name field set in REQUEST object
81         $this->requestArray['query'] = 'true';
82
83
84         $this->searchForm = new SearchForm($this->task,'Tasks');
85
86         require 'modules/Tasks/vardefs.php';
87         require 'modules/Tasks/metadata/SearchFields.php';
88         require 'modules/Tasks/metadata/searchdefs.php';
89         $this->searchForm->searchFields = $searchFields[$this->searchForm->module];
90         $this->searchForm->searchdefs = $searchdefs[$this->searchForm->module];
91         $this->searchForm->fieldDefs = $this->task->getFieldDefinitions();
92         $this->searchForm->populateFromArray($this->requestArray,'advanced_search',false);
93         $whereArray = $this->searchForm->generateSearchWhere(true, $this->task->module_dir);
94         $test_query = "SELECT id FROM contacts WHERE " . $whereArray[0];
95         $result = $GLOBALS['db']->query($test_query);
96         $row = $GLOBALS['db']->fetchByAssoc($result);
97
98         $this->assertEquals($this->contact->id, $row['id'], "Didn't find the correct contact id");
99
100         $result2 = $GLOBALS['db']->query("SELECT * FROM tasks WHERE tasks.contact_id='{$this->task->contact_id}'");
101         $row2 = $GLOBALS['db']->fetchByAssoc($result2);
102
103         $this->assertEquals($this->task->id, $row2['id'], "Couldn't find the expected related task");
104     }
105 }