2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 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/utils/LogicHook.php');
40 class Bug46850Test extends Sugar_PHPUnit_Framework_TestCase
42 protected $renames = array();
43 protected $deletes = array();
45 protected $hook = array(
46 'test_logic_hook' => array(array(1, 'test_logic_hook', __FILE__, 'LogicHookTest', 'testLogicHook')),
49 public function setUp()
51 LogicHookTest::$called = false;
52 unset($GLOBALS['logic_hook']);
53 $GLOBALS['logic_hook'] = LogicHook::initialize();
54 LogicHook::refreshHooks();
57 public function tearDown()
59 foreach($this->renames as $file) {
60 rename($file.".bak", $file);
62 foreach($this->deletes as $file) {
65 unset($GLOBALS['logic_hook']);
66 LogicHook::refreshHooks();
69 protected function saveHook($file)
71 if(file_exists($file)) {
72 rename($file, $file.".bak");
73 $this->renames[] = $file;
75 $this->deletes[] = $file;
79 public function getModules()
89 * @dataProvider getModules
91 public function testHooksDirect($module)
93 $dir = rtrim("custom/modules/$module", "/");
94 $file = "$dir/logic_hooks.php";
95 $this->saveHook($file);
97 mkdir($dir, 0755, true);
99 write_array_to_file('hook_array', $this->hook, $file);
100 $GLOBALS['logic_hook']->getHooks($module, true); // manually refresh
101 $GLOBALS['logic_hook']->call_custom_logic($module, 'test_logic_hook');
102 $this->assertTrue(LogicHookTest::$called);
106 * @dataProvider getModules
108 public function testHooksExtDirect($module)
111 $dir = "custom/application/Ext/LogicHooks";
113 $dir = "custom/modules/$module/Ext/LogicHooks";
116 mkdir($dir, 0755, true);
118 $file = "$dir/logichooks.ext.php";
119 $this->saveHook($file);
120 write_array_to_file('hook_array', $this->hook, $file);
121 $GLOBALS['logic_hook']->getHooks($module, true); // manually refresh
122 $GLOBALS['logic_hook']->call_custom_logic($module, 'test_logic_hook');
123 $this->assertTrue(LogicHookTest::$called);
127 * @dataProvider getModules
129 public function testHooksUtils($module)
131 $dir = rtrim("custom/modules/$module", "/");
132 $file = "$dir/logic_hooks.php";
134 mkdir($dir, 0755, true);
136 $this->saveHook($file);
137 check_logic_hook_file($module, 'test_logic_hook', $this->hook['test_logic_hook'][0]);
138 $GLOBALS['logic_hook']->getHooks($module, true); // manually refresh
139 $GLOBALS['logic_hook']->call_custom_logic($module, 'test_logic_hook');
140 $this->assertTrue(LogicHookTest::$called);
145 * @dataProvider getModules
147 public function testGeHookArray($module)
149 $dir = rtrim("custom/modules/$module", "/");
150 $file = "$dir/logic_hooks.php";
152 mkdir($dir, 0755, true);
154 $this->saveHook($file);
155 check_logic_hook_file($module, 'test_logic_hook', $this->hook['test_logic_hook'][0]);
156 $array = get_hook_array($module);
157 $this->assertEquals($this->hook, $array);
161 class LogicHookTest {
162 public static $called = false;
163 function testLogicHook() {
164 self::$called = true;