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/ModuleBuilder/controller.php');
39 require_once('modules/ProjectTask/views/view.list.php');
43 * Query Failure when searching in Project Tasks list view, using Accounts field created from Relationship
45 * @author asokol@sugarcrm.com
49 class Bug50575Test extends Sugar_PHPUnit_Framework_OutputTestCase
52 protected $_projectTask;
55 protected $_savedSearchDefs;
56 protected $_savedSearchFields;
58 protected $relationship;
59 protected $relationships;
61 protected $_localSearchFields = array (
62 'ProjectTask' => array(
64 'query_type' => 'default',
66 'project_name' => array (
67 'query_type' => 'default',
75 public function setUp()
77 SugarTestHelper::setUp('current_user', array(true, 1));
78 SugarTestHelper::setUp('app_list_strings');
79 SugarTestHelper::setUp('beanFiles');
80 SugarTestHelper::setUp('beanList');
82 $this->relationships = new DeployedRelationships('Products');
84 'lhs_module' => 'Accounts',
85 'relationship_type' => 'one-to-many',
86 'rhs_module' => 'ProjectTask'
88 $this->relationship = RelationshipFactory::newRelationship($definition);
89 $this->relationships->add($this->relationship);
90 $this->relationships->save();
91 $this->relationships->build();
92 SugarTestHelper::setUp('relation', array(
99 'advanced_search' => array(
100 $this->relationship->getName() . '_name' => array (
104 'id' => strtoupper($this->relationship->getJoinKeyLHS()),
107 'name' => $this->relationship->getName() . '_name',
111 'templateMeta' => array (
113 'maxColumnsBasic' => '4',
120 // Add new field to advanced search layout
121 if(file_exists("custom/modules/ProjectTask/metadata/searchdefs.php"))
123 $this->_savedSearchDefs = file_get_contents("custom/modules/ProjectTask/metadata/searchdefs.php");
126 write_array_to_file("searchdefs['ProjectTask']", $searchDefs, 'custom/modules/ProjectTask/metadata/searchdefs.php');
128 if(file_exists("modules/ProjectTask/metadata/SearchFields.php"))
130 $this->_savedSearchFields = file_get_contents("modules/ProjectTask/metadata/SearchFields.php");
133 write_array_to_file("searchFields['ProjectTask']", $this->_localSearchFields['ProjectTask'], 'modules/ProjectTask/metadata/SearchFields.php');
135 // Creates linked test account, project and project task
136 $this->_project = SugarTestProjectUtilities::createProject();
137 $this->_account = SugarTestAccountUtilities::createAccount();
139 $projectTaskData = array (
140 'project_id' => $this->_project->id,
141 'parent_task_id' => '',
142 'project_task_id' => '1',
143 'percent_complete' => '0',
144 'name' => 'Test Task 1',
145 'duration_unit' => 'Days',
149 $this->_projectTask = SugarTestProjectTaskUtilities::createProjectTask($projectTaskData);
150 $this->_projectTask->{$this->relationship->getName()}->add($this->_account);
151 $this->_projectTask->save();
154 public function tearDown()
156 if(!empty($this->_savedSearchDefs))
158 file_put_contents("custom/modules/ProjectTask/metadata/searchdefs.php", $this->_savedSearchDefs);
162 @unlink("custom/modules/ProjectTask/metadata/searchdefs.php");
165 if(!empty($this->_savedSearchFields))
167 file_put_contents("modules/ProjectTask/metadata/SearchFields.php", $this->_savedSearchFields);
171 @unlink("modules/ProjectTask/metadata/SearchFields.php");
173 SugarTestProjectTaskUtilities::removeAllCreatedProjectTasks();
174 SugarTestProjectUtilities::removeAllCreatedProjects();
175 SugarTestAccountUtilities::removeAllCreatedAccounts();
177 $this->relationships->delete($this->relationship->getName());
178 $this->relationships->save();
180 SugarCache::$isCacheReset = false;
181 SugarTestHelper::tearDown();
182 $GLOBALS['reload_vardefs'] = true;
183 $bean = new ProjectTask();
184 unset($GLOBALS['reload_vardefs']);
188 * Test checks if advanced search provides correct result (correct SQL query)
191 public function testCustomAdvancedSearch()
193 $_REQUEST = $_POST = array(
194 "module" => "ProjectTask",
196 "searchFormTab" => "advanced_search",
197 "displayColumns" => "NAME|PROJECT_NAME",
199 $this->relationship->getName(). '_name_advanced' => $this->_account->name,
200 "button" => "Search",
203 $vl = new ProjectTaskViewList();
204 $vl->bean = $this->_projectTask;
205 $GLOBALS['module'] = 'ProjectTask';
206 $vl->module = 'ProjectTask';
208 $this->expectOutputRegex("/(" . $this->_project->name . ")/");