modulesHookFile)) { $this->hasCustomModulesLogicHookFile = true; copy($this->modulesHookFile, $this->modulesHookFile.'.bak'); } else { write_array_to_file("test", array(), $this->modulesHookFile); } if(file_exists($this->contactsHookFile)) { $this->hasCustomContactLogicHookFile = true; copy($this->contactsHookFile, $this->contactsHookFile.'.bak'); } else { write_array_to_file("test", array(), $this->contactsHookFile); } $this->useOutputBuffering = false; LogicHook::refreshHooks(); } public function tearDown() { //Remove the custom logic hook files if($this->hasCustomModulesLogicHookFile && file_exists($this->modulesHookFile.'.bak')) { copy($this->modulesHookFile.'.bak', $this->modulesHookFile); unlink($this->modulesHookFile.'.bak'); } else if(file_exists($this->modulesHookFile)) { unlink($this->modulesHookFile); } if($this->hasCustomContactLogicHookFile && file_exists($this->contactsHookFile.'.bak')) { copy($this->contactsHookFile.'.bak', $this->contactsHookFile); unlink($this->contactsHookFile.'.bak'); } else if(file_exists($this->contactsHookFile)) { unlink($this->contactsHookFile); } unset($GLOBALS['logic_hook']); } public function testSugarViewProcessLogicHookWithModule() { $GLOBALS['logic_hook'] = new LogicHookMock(); $hooks = $GLOBALS['logic_hook']->getHooks('Contacts'); $sugarViewMock = new SugarViewMock(); $sugarViewMock->module = 'Contacts'; $sugarViewMock->process(); $expectedHookCount = isset($hooks['after_ui_frame']) ? count($hooks['after_ui_frame']) : 0; $this->assertEquals($expectedHookCount, $GLOBALS['logic_hook']->hookRunCount, 'Assert that two logic hook files were run'); } public function testSugarViewProcessLogicHookWithoutModule() { $GLOBALS['logic_hook'] = new LogicHookMock(); $hooks = $GLOBALS['logic_hook']->getHooks(''); $sugarViewMock = new SugarViewMock(); $sugarViewMock->module = ''; $sugarViewMock->process(); $expectedHookCount = isset($hooks['after_ui_frame']) ? count($hooks['after_ui_frame']) : 0; $this->assertEquals($expectedHookCount, $GLOBALS['logic_hook']->hookRunCount, 'Assert that one logic hook file was run'); } } class SugarViewMock extends SugarView { var $options = array(); //no-opt methods we override function _trackView() {} function renderJavascript() {} function _buildModuleList() {} function preDisplay() {} function displayErrors() {} function display() {} } class LogicHookMock extends LogicHook { var $hookRunCount = 0; function process_hooks($hook_array, $event, $arguments) { if($event == 'after_ui_frame') { $this->hookRunCount++; } } } ?>