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');
83 public function testMenuExistsCanFindModuleMenu()
86 if( $fh = @fopen("modules/{$this->_moduleName}/Menu.php", 'w+') ) {
89 \$module_menu[]=Array("index.php?module=Import&action=bar&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
96 $view = new SugarView;
97 $module_menu = $view->getMenu($this->_moduleName);
98 $found_custom_menu = false;
99 foreach ($module_menu as $menu_entry) {
100 foreach ($menu_entry as $menu_item) {
101 if (preg_match('/action=bar/', $menu_item)) {
102 $found_custom_menu = true;
106 $this->assertTrue($found_custom_menu, "Assert that menu was detected");
112 public function testMenuExistsCanFindModuleExtMenu()
114 // Create module ext menu
115 sugar_mkdir("custom/modules/{$this->_moduleName}/Ext/Menus/",null,true);
116 if( $fh = @fopen("custom/modules/{$this->_moduleName}/Ext/Menus/menu.ext.php", 'w+') ) {
119 \$module_menu[]=Array("index.php?module=Import&action=foo&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
122 fputs( $fh, $string);
126 $view = new SugarView;
127 $module_menu = $view->getMenu($this->_moduleName);
128 $found_custom_menu = false;
129 foreach ($module_menu as $key => $menu_entry) {
130 foreach ($menu_entry as $id => $menu_item) {
131 if (preg_match('/action=foo/', $menu_item)) {
132 $found_custom_menu = true;
136 $this->assertTrue($found_custom_menu, "Assert that custom menu was detected");
142 public function testMenuExistsCanFindModuleExtMenuWhenModuleMenuDefinedGlobal()
144 // Create module ext menu
145 sugar_mkdir("custom/modules/{$this->_moduleName}/Ext/Menus/",null,true);
146 if( $fh = @fopen("custom/modules/{$this->_moduleName}/Ext/Menus/menu.ext.php", 'w+') ) {
149 global \$module_menu;
150 \$module_menu[]=Array("index.php?module=Import&action=foo&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
153 fputs( $fh, $string);
157 $view = new SugarView;
158 $module_menu = $view->getMenu($this->_moduleName);
159 $found_custom_menu = false;
160 foreach ($module_menu as $key => $menu_entry) {
161 foreach ($menu_entry as $id => $menu_item) {
162 if (preg_match('/action=foo/', $menu_item)) {
163 $found_custom_menu = true;
167 $this->assertTrue($found_custom_menu, "Assert that custom menu was detected");
170 public function testMenuExistsCanFindApplicationExtMenu()
172 // Create module ext menu
173 $backupCustomMenu = false;
174 if ( !is_dir("custom/application/Ext/Menus/") )
175 sugar_mkdir("custom/application/Ext/Menus/",null,true);
176 if (file_exists('custom/application/Ext/Menus/menu.ext.php')) {
177 copy('custom/application/Ext/Menus/menu.ext.php', 'custom/application/Ext/Menus/menu.ext.php.backup');
178 $backupCustomMenu = true;
181 if ( $fh = @fopen("custom/application/Ext/Menus/menu.ext.php", 'w+') ) {
184 \$module_menu[]=Array("index.php?module=Import&action=foobar&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
187 fputs( $fh, $string);
191 $view = new SugarView;
192 $module_menu = $view->getMenu($this->_moduleName);
193 $found_application_custom_menu = false;
194 foreach ($module_menu as $key => $menu_entry) {
195 foreach ($menu_entry as $id => $menu_item) {
196 if (preg_match('/action=foobar/', $menu_item)) {
197 $found_application_custom_menu = true;
201 $this->assertTrue($found_application_custom_menu, "Assert that application custom menu was detected");
203 if($backupCustomMenu) {
204 copy('custom/application/Ext/Menus/menu.ext.php.backup', 'custom/application/Ext/Menus/menu.ext.php');
205 unlink('custom/application/Ext/Menus/menu.ext.php.backup');
208 unlink('custom/application/Ext/Menus/menu.ext.php');
211 public function testMenuExistsCanFindModuleMenuAndModuleExtMenu()
213 // Create module menu
214 if( $fh = @fopen("modules/{$this->_moduleName}/Menu.php", 'w+') ) {
217 \$module_menu[]=Array("index.php?module=Import&action=foo&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
220 fputs( $fh, $string);
224 // Create module ext menu
225 sugar_mkdir("custom/modules/{$this->_moduleName}/Ext/Menus/",null,true);
226 if( $fh = @fopen("custom/modules/{$this->_moduleName}/Ext/Menus/menu.ext.php", 'w+') ) {
229 \$module_menu[]=Array("index.php?module=Import&action=bar&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
232 fputs( $fh, $string);
236 $view = new SugarView;
237 $module_menu = $view->getMenu($this->_moduleName);
238 $found_custom_menu = false;
240 foreach ($module_menu as $key => $menu_entry) {
241 foreach ($menu_entry as $id => $menu_item) {
242 if (preg_match('/action=foo/', $menu_item)) {
245 if (preg_match('/action=bar/', $menu_item)) {
246 $found_custom_menu = true;
250 $this->assertTrue($found_menu, "Assert that menu was detected");
251 $this->assertTrue($found_custom_menu, "Assert that custom menu was detected");
255 class ViewLoadMenuTest extends SugarView
257 public function menuExists(
261 return $this->_menuExists($module);