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/View/SugarView.php');
40 class LoadMenuTest extends Sugar_PHPUnit_Framework_TestCase
42 protected $_moduleName;
44 public function setUp()
46 global $mod_strings, $app_strings;
47 $mod_strings = return_module_language($GLOBALS['current_language'], 'Accounts');
48 $app_strings = return_application_language($GLOBALS['current_language']);
50 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
52 // create a dummy module directory
53 $this->_moduleName = 'TestModule'.mt_rand();
55 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
57 sugar_mkdir("modules/{$this->_moduleName}",null,true);
60 public function tearDown()
62 unset($GLOBALS['mod_strings']);
63 unset($GLOBALS['app_strings']);
65 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
66 unset($GLOBALS['current_user']);
67 if(!empty($this->_moduleName)) {
68 if ( is_dir("modules/{$this->_moduleName}") )
69 rmdir_recursive("modules/{$this->_moduleName}");
70 if ( is_dir("custom/modules/{$this->_moduleName}") )
71 rmdir_recursive("custom/modules/{$this->_moduleName}");
73 unset($GLOBALS['current_user']);
76 public function testMenuDoesNotExists()
78 $view = new SugarView;
79 $module_menu = $view->getMenu($this->_moduleName);
80 $this->assertTrue(empty($module_menu),'Assert the module menu array is empty');
86 public function testMenuExistsCanFindModuleMenu()
89 if( $fh = @fopen("modules/{$this->_moduleName}/Menu.php", 'w+') ) {
92 \$module_menu[]=Array("index.php?module=Import&action=bar&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
99 $view = new SugarView;
100 $module_menu = $view->getMenu($this->_moduleName);
102 $found_menu_twice = false;
103 foreach ($module_menu as $menu_entry) {
104 foreach ($menu_entry as $menu_item) {
105 if (preg_match('/action=bar/', $menu_item)) {
107 $found_menu_twice = true;
114 $this->assertTrue($found_menu, "Assert that menu was detected");
115 $this->assertFalse($found_menu_twice, "Assert that menu item wasn't listed twice");
122 public function testMenuExistsCanFindModuleExtMenu()
124 // Create module ext menu
125 sugar_mkdir("custom/modules/{$this->_moduleName}/Ext/Menus/",null,true);
126 if( $fh = @fopen("custom/modules/{$this->_moduleName}/Ext/Menus/menu.ext.php", 'w+') ) {
129 \$module_menu[]=Array("index.php?module=Import&action=foo&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
132 fputs( $fh, $string);
136 $view = new SugarView;
137 $module_menu = $view->getMenu($this->_moduleName);
138 $found_custom_menu = false;
139 $found_custom_menu_twice = false;
140 foreach ($module_menu as $key => $menu_entry) {
141 foreach ($menu_entry as $id => $menu_item) {
142 if (preg_match('/action=foo/', $menu_item)) {
143 if ( $found_custom_menu ) {
144 $found_custom_menu_twice = true;
146 $found_custom_menu = true;
150 $this->assertTrue($found_custom_menu, "Assert that custom menu was detected");
151 $this->assertFalse($found_custom_menu_twice, "Assert that custom menu item wasn't listed twice");
158 public function testMenuExistsCanFindModuleExtMenuWhenModuleMenuDefinedGlobal()
160 // Create module ext menu
161 sugar_mkdir("custom/modules/{$this->_moduleName}/Ext/Menus/",null,true);
162 if( $fh = @fopen("custom/modules/{$this->_moduleName}/Ext/Menus/menu.ext.php", 'w+') ) {
165 global \$module_menu;
166 \$module_menu[]=Array("index.php?module=Import&action=foo&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
169 fputs( $fh, $string);
173 $view = new SugarView;
174 $module_menu = $view->getMenu($this->_moduleName);
175 $found_custom_menu = false;
176 $found_custom_menu_twice = false;
177 foreach ($module_menu as $key => $menu_entry) {
178 foreach ($menu_entry as $id => $menu_item) {
179 if (preg_match('/action=foo/', $menu_item)) {
180 if ( $found_custom_menu ) {
181 $found_custom_menu_twice = true;
183 $found_custom_menu = true;
188 $this->assertTrue($found_custom_menu, "Assert that custom menu was detected");
189 $this->assertFalse($found_custom_menu_twice, "Assert that custom menu item wasn't listed twice");
195 public function testMenuExistsCanFindApplicationExtMenu()
197 // Create module ext menu
198 $backupCustomMenu = false;
199 if ( !is_dir("custom/application/Ext/Menus/") )
200 sugar_mkdir("custom/application/Ext/Menus/",null,true);
201 if (file_exists('custom/application/Ext/Menus/menu.ext.php')) {
202 copy('custom/application/Ext/Menus/menu.ext.php', 'custom/application/Ext/Menus/menu.ext.php.backup');
203 $backupCustomMenu = true;
206 if ( $fh = @fopen("custom/application/Ext/Menus/menu.ext.php", 'w+') ) {
209 \$module_menu[]=Array("index.php?module=Import&action=foobar&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
212 fputs( $fh, $string);
216 $view = new SugarView;
217 $module_menu = $view->getMenu($this->_moduleName);
218 $found_application_custom_menu = false;
219 $found_application_custom_menu_twice = false;
220 foreach ($module_menu as $key => $menu_entry) {
221 foreach ($menu_entry as $id => $menu_item) {
222 if (preg_match('/action=foobar/', $menu_item)) {
223 if ( $found_application_custom_menu ) {
224 $found_application_custom_menu_twice = true;
226 $found_application_custom_menu = true;
231 $this->assertTrue($found_application_custom_menu, "Assert that application custom menu was detected");
232 $this->assertFalse($found_application_custom_menu_twice, "Assert that application custom menu item wasn't duplicated");
234 if($backupCustomMenu) {
235 copy('custom/application/Ext/Menus/menu.ext.php.backup', 'custom/application/Ext/Menus/menu.ext.php');
236 unlink('custom/application/Ext/Menus/menu.ext.php.backup');
239 unlink('custom/application/Ext/Menus/menu.ext.php');
245 public function testMenuExistsCanFindModuleMenuAndModuleExtMenu()
247 // Create module menu
248 if( $fh = @fopen("modules/{$this->_moduleName}/Menu.php", 'w+') ) {
251 \$module_menu[]=Array("index.php?module=Import&action=foo&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
254 fputs( $fh, $string);
258 // Create module ext menu
259 sugar_mkdir("custom/modules/{$this->_moduleName}/Ext/Menus/",null,true);
260 if( $fh = @fopen("custom/modules/{$this->_moduleName}/Ext/Menus/menu.ext.php", 'w+') ) {
263 \$module_menu[]=Array("index.php?module=Import&action=bar&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
266 fputs( $fh, $string);
270 $view = new SugarView;
271 $module_menu = $view->getMenu($this->_moduleName);
272 $found_custom_menu = false;
273 $found_custom_menu_twice = false;
275 $found_menu_twice = false;
276 foreach ($module_menu as $key => $menu_entry) {
277 foreach ($menu_entry as $id => $menu_item) {
278 if (preg_match('/action=foo/', $menu_item)) {
280 $found_menu_twice = true;
284 if (preg_match('/action=bar/', $menu_item)) {
285 if ( $found_custom_menu ) {
286 $found_custom_menu_twice = true;
288 $found_custom_menu = true;
292 $this->assertTrue($found_menu, "Assert that menu was detected");
293 $this->assertFalse($found_menu_twice, "Assert that menu item wasn't duplicated");
294 $this->assertTrue($found_custom_menu, "Assert that custom menu was detected");
295 $this->assertFalse($found_custom_menu_twice, "Assert that custom menu item wasn't duplicated");
299 class ViewLoadMenuTest extends SugarView
301 public function menuExists(
305 return $this->_menuExists($module);