2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 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 'include/MVC/Controller/SugarController.php';
40 class SugarControllerTest extends Sugar_PHPUnit_Framework_TestCase
42 public function setUp()
44 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
47 public function tearDown()
49 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
50 unset($GLOBALS['current_user']);
53 public function testSetup()
55 $controller = new SugarControllerMock;
58 $this->assertEquals('Home',$controller->module);
59 $this->assertNull($controller->target_module);
62 public function testSetupSpecifyModule()
64 $controller = new SugarControllerMock;
65 $controller->setup('foo');
67 $this->assertEquals('foo',$controller->module);
68 $this->assertNull($controller->target_module);
71 public function testSetupUseRequestVars()
74 'module' => 'dog33434',
75 'target_module' => 'dog121255',
76 'action' => 'dog3232',
77 'record' => 'dog5656',
79 'return_module' => 'dog1312',
80 'return_action' => 'dog1212',
81 'return_id' => '11212',
83 $controller = new SugarControllerMock;
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);
96 public function testSetModule()
98 $controller = new SugarControllerMock;
99 $controller->setModule('cat');
101 $this->assertEquals('cat',$controller->module);
104 public function testLoadBean()
109 public function testCallLegacyCodeIfLegacyDetailViewFound()
111 $module_name = 'TestModule'.mt_rand();
112 sugar_mkdir("modules/$module_name/",null,true);
113 sugar_touch("modules/$module_name/DetailView.php");
115 $controller = new SugarControllerMock;
116 $controller->setup($module_name);
117 $controller->do_action = 'DetailView';
118 $controller->view = 'list';
119 $controller->callLegacyCode();
121 $this->assertEquals('classic',$controller->view);
123 rmdir_recursive("modules/$module_name");
126 public function testCallLegacyCodeIfNewDetailViewFound()
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");
132 $controller = new SugarControllerMock;
133 $controller->setup($module_name);
134 $controller->do_action = 'DetailView';
136 $controller->view = 'list';
137 $controller->callLegacyCode();
139 $this->assertEquals('list',$controller->view);
141 rmdir_recursive("modules/$module_name");
145 public function testCallLegacyCodeIfLegacyDetailViewAndNewDetailViewFound()
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");
152 $controller = new SugarControllerMock;
153 $controller->setup($module_name);
154 $controller->do_action = 'DetailView';
156 $controller->view = 'list';
157 $controller->callLegacyCode();
159 $this->assertEquals('list',$controller->view);
161 rmdir_recursive("modules/$module_name");
164 public function testCallLegacyCodeIfCustomLegacyDetailViewAndNewDetailViewFound()
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");
172 $controller = new SugarControllerMock;
173 $controller->setup($module_name);
174 $controller->do_action = 'DetailView';
176 $controller->view = 'list';
177 $controller->callLegacyCode();
179 $this->assertEquals('classic',$controller->view);
181 rmdir_recursive("modules/$module_name");
184 public function testCallLegacyCodeIfLegacyDetailViewAndCustomNewDetailViewFound()
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");
192 $controller = new SugarControllerMock;
193 $controller->setup($module_name);
194 $controller->do_action = 'DetailView';
195 $controller->view = 'list';
196 $controller->callLegacyCode();
198 $this->assertEquals('classic',$controller->view);
200 rmdir_recursive("modules/$module_name");
203 public function testCallLegacyCodeIfLegacyDetailViewAndNewDetailViewFoundAndCustomLegacyDetailViewFound()
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");
212 $controller = new SugarControllerMock;
213 $controller->setup($module_name);
214 $controller->do_action = 'DetailView';
216 $controller->view = 'list';
217 $controller->callLegacyCode();
219 $this->assertEquals('classic',$controller->view);
221 rmdir_recursive("modules/$module_name");
224 public function testCallLegacyCodeIfLegacyDetailViewAndNewDetailViewFoundAndCustomNewDetailViewFound()
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");
233 $controller = new SugarControllerMock;
234 $controller->setup($module_name);
235 $controller->do_action = 'DetailView';
236 $controller->view = 'list';
237 $controller->callLegacyCode();
239 $this->assertEquals('list',$controller->view);
241 rmdir_recursive("modules/$module_name");
244 public function testCallLegacyCodeIfLegacyDetailViewAndNewDetailViewFoundAndCustomLegacyDetailViewFoundAndCustomNewDetailViewFound()
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");
254 $controller = new SugarControllerMock;
255 $controller->setup($module_name);
256 $controller->do_action = 'DetailView';
258 $controller->view = 'list';
259 $controller->callLegacyCode();
261 $this->assertEquals('list',$controller->view);
263 rmdir_recursive("modules/$module_name");
267 class SugarControllerMock extends SugarController
271 public function callLegacyCode()
273 return parent::callLegacyCode();