]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/MVC/Controller/SugarControllerTest.php
Release 6.2.0
[Github/sugarcrm.git] / tests / include / MVC / Controller / SugarControllerTest.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 'include/MVC/Controller/SugarController.php';
39
40 class SugarControllerTest extends Sugar_PHPUnit_Framework_TestCase
41 {
42     public function setUp()
43     {
44         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
45     }
46     
47     public function tearDown()
48     {
49         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
50         unset($GLOBALS['current_user']);
51     }
52
53     public function testSetup()
54     {
55         $controller = new SugarControllerMock;
56         $controller->setup();
57         
58         $this->assertEquals('Home',$controller->module);
59         $this->assertNull($controller->target_module);
60     }
61     
62     public function testSetupSpecifyModule()
63     {
64         $controller = new SugarControllerMock;
65         $controller->setup('foo');
66         
67         $this->assertEquals('foo',$controller->module);
68         $this->assertNull($controller->target_module);
69     }
70     
71     public function testSetupUseRequestVars()
72     {
73         $_REQUEST = array(
74             'module' => 'dog33434',
75             'target_module' => 'dog121255',
76             'action' => 'dog3232',
77             'record' => 'dog5656',
78             'view' => 'dog4343',
79             'return_module' => 'dog1312',
80             'return_action' => 'dog1212',
81             'return_id' => '11212',
82             );
83         $controller = new SugarControllerMock;
84         $controller->setup();
85         
86         $this->assertEquals($_REQUEST['module'],$controller->module);
87         $this->assertEquals($_REQUEST['target_module'],$controller->target_module);
88         $this->assertEquals($_REQUEST['action'],$controller->action);
89         $this->assertEquals($_REQUEST['record'],$controller->record);
90         $this->assertEquals($_REQUEST['view'],$controller->view);
91         $this->assertEquals($_REQUEST['return_module'],$controller->return_module);
92         $this->assertEquals($_REQUEST['return_action'],$controller->return_action);
93         $this->assertEquals($_REQUEST['return_id'],$controller->return_id);
94     }
95     
96     public function testSetModule()
97     {
98         $controller = new SugarControllerMock;
99         $controller->setModule('cat');
100         
101         $this->assertEquals('cat',$controller->module);
102     }
103     
104     public function testLoadBean()
105     {
106         
107     }
108     
109     public function testCallLegacyCodeIfLegacyDetailViewFound()
110     {
111         $module_name = 'TestModule'.mt_rand();
112         sugar_mkdir("modules/$module_name/",null,true);
113         sugar_touch("modules/$module_name/DetailView.php");
114         
115         $controller = new SugarControllerMock;
116         $controller->setup($module_name);
117         $controller->do_action = 'DetailView';
118         $controller->view = 'list';
119         $controller->callLegacyCode();
120         
121         $this->assertEquals('classic',$controller->view);
122         
123         rmdir_recursive("modules/$module_name");
124     }
125
126     public function testCallLegacyCodeIfNewDetailViewFound()
127     {
128         $module_name = 'TestModule'.mt_rand();
129         sugar_mkdir("modules/$module_name/views",null,true);
130         sugar_touch("modules/$module_name/views/view.detail.php");
131         
132         $controller = new SugarControllerMock;
133         $controller->setup($module_name);
134         $controller->do_action = 'DetailView';
135
136         $controller->view = 'list';
137         $controller->callLegacyCode();
138         
139         $this->assertEquals('list',$controller->view);
140         
141         rmdir_recursive("modules/$module_name");
142     }
143
144
145     public function testCallLegacyCodeIfLegacyDetailViewAndNewDetailViewFound()
146     {
147         $module_name = 'TestModule'.mt_rand();
148         sugar_mkdir("modules/$module_name/views",null,true);
149         sugar_touch("modules/$module_name/views/view.detail.php");
150         sugar_touch("modules/$module_name/DetailView.php");
151         
152         $controller = new SugarControllerMock;
153         $controller->setup($module_name);
154         $controller->do_action = 'DetailView';
155
156         $controller->view = 'list';
157         $controller->callLegacyCode();
158         
159         $this->assertEquals('list',$controller->view);
160         
161         rmdir_recursive("modules/$module_name");
162     }
163
164     public function testCallLegacyCodeIfCustomLegacyDetailViewAndNewDetailViewFound()
165     {
166         $module_name = 'TestModule'.mt_rand();
167         sugar_mkdir("modules/$module_name/views",null,true);
168         sugar_touch("modules/$module_name/views/view.detail.php");
169         sugar_mkdir("custom/modules/$module_name",null,true);
170         sugar_touch("custom/modules/$module_name/DetailView.php");
171         
172         $controller = new SugarControllerMock;
173         $controller->setup($module_name);
174         $controller->do_action = 'DetailView';
175
176         $controller->view = 'list';
177         $controller->callLegacyCode();
178         
179         $this->assertEquals('classic',$controller->view);
180         
181         rmdir_recursive("modules/$module_name");
182     }
183
184     public function testCallLegacyCodeIfLegacyDetailViewAndCustomNewDetailViewFound()
185     {
186         $module_name = 'TestModule'.mt_rand();
187         sugar_mkdir("custom/modules/$module_name/views",null,true);
188         sugar_touch("custom/modules/$module_name/views/view.detail.php");
189         sugar_mkdir("modules/$module_name",null,true);
190         sugar_touch("modules/$module_name/DetailView.php");
191         
192         $controller = new SugarControllerMock;
193         $controller->setup($module_name);
194         $controller->do_action = 'DetailView';
195         $controller->view = 'list';
196         $controller->callLegacyCode();
197         
198         $this->assertEquals('classic',$controller->view);
199         
200         rmdir_recursive("modules/$module_name");
201     }
202
203     public function testCallLegacyCodeIfLegacyDetailViewAndNewDetailViewFoundAndCustomLegacyDetailViewFound()
204     {
205         $module_name = 'TestModule'.mt_rand();
206         sugar_mkdir("modules/$module_name/views",null,true);
207         sugar_touch("modules/$module_name/views/view.detail.php");
208         sugar_touch("modules/$module_name/DetailView.php");
209         sugar_mkdir("custom/modules/$module_name",null,true);
210         sugar_touch("custom/modules/$module_name/DetailView.php");
211         
212         $controller = new SugarControllerMock;
213         $controller->setup($module_name);
214         $controller->do_action = 'DetailView';
215
216         $controller->view = 'list';
217         $controller->callLegacyCode();
218         
219         $this->assertEquals('classic',$controller->view);
220         
221         rmdir_recursive("modules/$module_name");
222     }
223
224     public function testCallLegacyCodeIfLegacyDetailViewAndNewDetailViewFoundAndCustomNewDetailViewFound()
225     {
226         $module_name = 'TestModule'.mt_rand();
227         sugar_mkdir("custom/modules/$module_name/views",null,true);
228         sugar_touch("custom/modules/$module_name/views/view.detail.php");
229         sugar_mkdir("modules/$module_name/views",null,true);
230         sugar_touch("modules/$module_name/views/view.detail.php");
231         sugar_touch("modules/$module_name/DetailView.php");
232         
233         $controller = new SugarControllerMock;
234         $controller->setup($module_name);
235         $controller->do_action = 'DetailView';
236         $controller->view = 'list';
237         $controller->callLegacyCode();
238         
239         $this->assertEquals('list',$controller->view);
240         
241         rmdir_recursive("modules/$module_name");
242     }
243
244     public function testCallLegacyCodeIfLegacyDetailViewAndNewDetailViewFoundAndCustomLegacyDetailViewFoundAndCustomNewDetailViewFound()
245     {
246         $module_name = 'TestModule'.mt_rand();
247         sugar_mkdir("custom/modules/$module_name/views",null,true);
248         sugar_touch("custom/modules/$module_name/views/view.detail.php");
249         sugar_touch("custom/modules/$module_name/DetailView.php");
250         sugar_mkdir("modules/$module_name/views",null,true);
251         sugar_touch("modules/$module_name/views/view.detail.php");
252         sugar_touch("modules/$module_name/DetailView.php");
253         
254         $controller = new SugarControllerMock;
255         $controller->setup($module_name);
256         $controller->do_action = 'DetailView';
257
258         $controller->view = 'list';
259         $controller->callLegacyCode();
260         
261         $this->assertEquals('list',$controller->view);
262         
263         rmdir_recursive("modules/$module_name");
264     }
265 }
266
267 class SugarControllerMock extends SugarController
268 {
269     public $do_action;
270     
271     public function callLegacyCode()
272     {
273         return parent::callLegacyCode();
274     }
275 }