2 require_once('include/MVC/View/SugarView.php');
4 class LoadMenuTest extends Sugar_PHPUnit_Framework_TestCase
6 protected $_moduleName;
8 public function setUp()
10 global $mod_strings, $app_strings;
11 $mod_strings = return_module_language($GLOBALS['current_language'], 'Accounts');
12 $app_strings = return_application_language($GLOBALS['current_language']);
14 // create a dummy module directory
15 $this->_moduleName = 'TestModule'.mt_rand();
17 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
19 sugar_mkdir("modules/{$this->_moduleName}",null,true);
22 public function tearDown()
24 unset($GLOBALS['mod_strings']);
25 unset($GLOBALS['app_strings']);
27 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
28 unset($GLOBALS['current_user']);
30 if ( is_dir("modules/{$this->_moduleName}") )
31 rmdir_recursive("modules/{$this->_moduleName}");
32 if ( is_dir("custom/modules/{$this->_moduleName}") )
33 rmdir_recursive("custom/modules/{$this->_moduleName}");
36 public function testMenuDoesNotExists()
38 $view = new SugarView;
39 $module_menu = $view->getMenu($this->_moduleName);
40 $this->assertTrue(empty($module_menu),'Assert the module menu array is empty');
43 public function testMenuExistsCanFindModuleMenu()
46 if( $fh = @fopen("modules/{$this->_moduleName}/Menu.php", 'w+') ) {
49 \$module_menu[]=Array("index.php?module=Import&action=bar&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
56 $view = new SugarView;
57 $module_menu = $view->getMenu($this->_moduleName);
58 $found_custom_menu = false;
59 foreach ($module_menu as $menu_entry) {
60 foreach ($menu_entry as $menu_item) {
61 if (preg_match('/action=bar/', $menu_item)) {
62 $found_custom_menu = true;
66 $this->assertTrue($found_custom_menu, "Assert that menu was detected");
72 public function testMenuExistsCanFindModuleExtMenu()
74 // Create module ext menu
75 sugar_mkdir("custom/modules/{$this->_moduleName}/Ext/Menus/",null,true);
76 if( $fh = @fopen("custom/modules/{$this->_moduleName}/Ext/Menus/menu.ext.php", 'w+') ) {
79 \$module_menu[]=Array("index.php?module=Import&action=foo&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
86 $view = new SugarView;
87 $module_menu = $view->getMenu($this->_moduleName);
88 $found_custom_menu = false;
89 foreach ($module_menu as $key => $menu_entry) {
90 foreach ($menu_entry as $id => $menu_item) {
91 if (preg_match('/action=foo/', $menu_item)) {
92 $found_custom_menu = true;
96 $this->assertTrue($found_custom_menu, "Assert that custom menu was detected");
102 public function testMenuExistsCanFindModuleExtMenuWhenModuleMenuDefinedGlobal()
104 // Create module ext menu
105 sugar_mkdir("custom/modules/{$this->_moduleName}/Ext/Menus/",null,true);
106 if( $fh = @fopen("custom/modules/{$this->_moduleName}/Ext/Menus/menu.ext.php", 'w+') ) {
109 global \$module_menu;
110 \$module_menu[]=Array("index.php?module=Import&action=foo&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
113 fputs( $fh, $string);
117 $view = new SugarView;
118 $module_menu = $view->getMenu($this->_moduleName);
119 $found_custom_menu = false;
120 foreach ($module_menu as $key => $menu_entry) {
121 foreach ($menu_entry as $id => $menu_item) {
122 if (preg_match('/action=foo/', $menu_item)) {
123 $found_custom_menu = true;
127 $this->assertTrue($found_custom_menu, "Assert that custom menu was detected");
130 public function testMenuExistsCanFindApplicationExtMenu()
132 // Create module ext menu
133 $backupCustomMenu = false;
134 if ( !is_dir("custom/application/Ext/Menus/") )
135 sugar_mkdir("custom/application/Ext/Menus/",null,true);
136 if (file_exists('custom/application/Ext/Menus/menu.ext.php')) {
137 copy('custom/application/Ext/Menus/menu.ext.php', 'custom/application/Ext/Menus/menu.ext.php.backup');
138 $backupCustomMenu = true;
141 if ( $fh = @fopen("custom/application/Ext/Menus/menu.ext.php", 'w+') ) {
144 \$module_menu[]=Array("index.php?module=Import&action=foobar&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
147 fputs( $fh, $string);
151 $view = new SugarView;
152 $module_menu = $view->getMenu($this->_moduleName);
153 $found_application_custom_menu = false;
154 foreach ($module_menu as $key => $menu_entry) {
155 foreach ($menu_entry as $id => $menu_item) {
156 if (preg_match('/action=foobar/', $menu_item)) {
157 $found_application_custom_menu = true;
161 $this->assertTrue($found_application_custom_menu, "Assert that application custom menu was detected");
163 if($backupCustomMenu) {
164 copy('custom/application/Ext/Menus/menu.ext.php.backup', 'custom/application/Ext/Menus/menu.ext.php');
165 unlink('custom/application/Ext/Menus/menu.ext.php.backup');
168 unlink('custom/application/Ext/Menus/menu.ext.php');
171 public function testMenuExistsCanFindModuleMenuAndModuleExtMenu()
173 // Create module menu
174 if( $fh = @fopen("modules/{$this->_moduleName}/Menu.php", 'w+') ) {
177 \$module_menu[]=Array("index.php?module=Import&action=foo&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
180 fputs( $fh, $string);
184 // Create module ext menu
185 sugar_mkdir("custom/modules/{$this->_moduleName}/Ext/Menus/",null,true);
186 if( $fh = @fopen("custom/modules/{$this->_moduleName}/Ext/Menus/menu.ext.php", 'w+') ) {
189 \$module_menu[]=Array("index.php?module=Import&action=bar&import_module=Accounts&return_module=Accounts&return_action=index","Foo","Foo", 'Accounts');
192 fputs( $fh, $string);
196 $view = new SugarView;
197 $module_menu = $view->getMenu($this->_moduleName);
198 $found_custom_menu = false;
200 foreach ($module_menu as $key => $menu_entry) {
201 foreach ($menu_entry as $id => $menu_item) {
202 if (preg_match('/action=foo/', $menu_item)) {
205 if (preg_match('/action=bar/', $menu_item)) {
206 $found_custom_menu = true;
210 $this->assertTrue($found_menu, "Assert that menu was detected");
211 $this->assertTrue($found_custom_menu, "Assert that custom menu was detected");
215 class ViewLoadMenuTest extends SugarView
217 public function menuExists(
221 return $this->_menuExists($module);