]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/ProjectTask/Bug50575Test.php
Release 6.5.10
[Github/sugarcrm.git] / tests / modules / ProjectTask / Bug50575Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2013 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/ModuleBuilder/controller.php');
39 require_once('modules/ProjectTask/views/view.list.php');
40
41 /**
42  * Bug #50575
43  * Query Failure when searching in Project Tasks list view, using Accounts field created from Relationship
44  *
45  * @author asokol@sugarcrm.com
46  * @ticket 50575
47  */
48
49 class Bug50575Test extends Sugar_PHPUnit_Framework_OutputTestCase
50 {
51     protected $_project;
52     protected $_projectTask;
53     protected $_account;
54
55     protected $_savedSearchDefs;
56     protected $_savedSearchFields;
57
58     protected $relationship;
59     protected $relationships;
60
61     protected $_localSearchFields = array (
62         'ProjectTask' => array(
63             'name' => array (
64                 'query_type' => 'default',
65             ),
66             'project_name' => array (
67                 'query_type' => 'default',
68                 'db_field' => array (
69                     0 => 'project.name',
70                 ),
71             ),
72         )
73     );
74
75     public function setUp()
76     {
77         SugarTestHelper::setUp('current_user', array(true, 1));
78         SugarTestHelper::setUp('app_list_strings');
79         SugarTestHelper::setUp('beanFiles');
80         SugarTestHelper::setUp('beanList');
81         parent::setUp();
82         $this->relationships = new DeployedRelationships('Products');
83         $definition = array(
84             'lhs_module' => 'Accounts',
85             'relationship_type' => 'one-to-many',
86             'rhs_module' => 'ProjectTask'
87         );
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(
93             'Accounts',
94             'ProjectTask'
95         ));
96
97         $searchDefs = array(
98                 'layout' => array(
99                     'advanced_search' => array(
100                         $this->relationship->getName() . '_name' => array (
101                             'type' => 'relate',
102                             'link' => true,
103                             'label' => '',
104                             'id' => strtoupper($this->relationship->getJoinKeyLHS()),
105                             'width' => '10%',
106                             'default' => true,
107                             'name' => $this->relationship->getName() . '_name',
108                         ),
109                     )
110                 ),
111                 'templateMeta' => array (
112                     'maxColumns' => '3',
113                     'maxColumnsBasic' => '4',
114                     'widths' => array (
115                         'label' => '10',
116                         'field' => '30',
117                     ),
118                 ),
119         );
120         // Add new field to advanced search layout
121         if(file_exists("custom/modules/ProjectTask/metadata/searchdefs.php"))
122         {
123             $this->_savedSearchDefs = file_get_contents("custom/modules/ProjectTask/metadata/searchdefs.php");
124         }
125
126         write_array_to_file("searchdefs['ProjectTask']", $searchDefs, 'custom/modules/ProjectTask/metadata/searchdefs.php');
127
128         if(file_exists("modules/ProjectTask/metadata/SearchFields.php"))
129         {
130             $this->_savedSearchFields = file_get_contents("modules/ProjectTask/metadata/SearchFields.php");
131         }
132
133         write_array_to_file("searchFields['ProjectTask']", $this->_localSearchFields['ProjectTask'], 'modules/ProjectTask/metadata/SearchFields.php');
134
135         // Creates linked test account, project and project task
136         $this->_project = SugarTestProjectUtilities::createProject();
137         $this->_account = SugarTestAccountUtilities::createAccount();
138
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',
146             'duration' => '1',
147         );
148
149         $this->_projectTask = SugarTestProjectTaskUtilities::createProjectTask($projectTaskData);
150         $this->_projectTask->{$this->relationship->getName()}->add($this->_account);
151         $this->_projectTask->save();
152     }
153
154     public function tearDown()
155     {
156         if(!empty($this->_savedSearchDefs))
157         {
158             file_put_contents("custom/modules/ProjectTask/metadata/searchdefs.php", $this->_savedSearchDefs);
159         }
160         else
161         {
162             @unlink("custom/modules/ProjectTask/metadata/searchdefs.php");
163         }
164
165         if(!empty($this->_savedSearchFields))
166         {
167             file_put_contents("modules/ProjectTask/metadata/SearchFields.php", $this->_savedSearchFields);
168         }
169         else
170         {
171             @unlink("modules/ProjectTask/metadata/SearchFields.php");
172         }
173         SugarTestProjectTaskUtilities::removeAllCreatedProjectTasks();
174         SugarTestProjectUtilities::removeAllCreatedProjects();
175         SugarTestAccountUtilities::removeAllCreatedAccounts();
176
177         $this->relationships->delete($this->relationship->getName());
178         $this->relationships->save();
179         parent::tearDown();
180         SugarCache::$isCacheReset = false;
181         SugarTestHelper::tearDown();
182         $GLOBALS['reload_vardefs'] = true;
183         $bean = new ProjectTask();
184         unset($GLOBALS['reload_vardefs']);
185     }
186
187     /**
188      * Test checks if advanced search provides correct result (correct SQL query)
189      * @group 50575
190      */
191     public function testCustomAdvancedSearch()
192     {
193         $_REQUEST = $_POST = array(
194             "module" => "ProjectTask",
195             "action" => "index",
196             "searchFormTab" => "advanced_search",
197             "displayColumns" => "NAME|PROJECT_NAME",
198             "query" => "true",
199             $this->relationship->getName(). '_name_advanced' => $this->_account->name,
200             "button" => "Search",
201         );
202
203         $vl = new ProjectTaskViewList();
204         $vl->bean = $this->_projectTask;
205         $GLOBALS['module'] = 'ProjectTask';
206         $vl->module = 'ProjectTask';
207
208         $this->expectOutputRegex("/(" . $this->_project->name . ")/");
209         $vl->display();
210     }
211 }