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('ModuleInstall/ModuleInstaller.php');
40 class ExtTest extends Sugar_PHPUnit_Framework_TestCase
42 protected $module_installer;
44 public static function setUpBeforeClass()
46 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
47 $GLOBALS['current_user']->is_admin = "1";
48 $GLOBALS['current_language'] = "en_us";
49 $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
50 $GLOBALS['mod_strings'] = return_module_language($GLOBALS['current_language'], 'Administration');
51 mkdir_recursive("cache/ExtTest");
54 public function setUp()
56 $this->module_installer = new ModuleInstaller();
57 $this->module_installer->silent = true;
58 $this->module_installer->base_dir = "cache/ExtTest";
59 $this->module_installer->id_name = 'ExtFrameworkTest';
60 $this->testvalue = uniqid("ext", true);
61 file_put_contents($this->module_installer->base_dir."/test.ext.php", "<?php \$testvalue = '$this->testvalue';");
64 public function tearDown()
66 if($this->module_installer) {
67 $this->module_installer->uninstall_extensions();
69 if(file_exists($this->module_installer->base_dir."/test.ext.php")) {
70 @unlink($this->module_installer->base_dir."/test.ext.php");
74 public static function tearDownAfterClass()
76 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
77 unset($GLOBALS['current_user']);
78 unset($GLOBALS['current_language']);
79 unset($GLOBALS['app_strings']);
80 unset($GLOBALS['mod_strings']);
81 if(file_exists("cache/ExtTest/test.ext.php")) {
82 @unlink("cache/ExtTest/test.ext.php");
84 rmdir_recursive("cache/ExtTest");
87 public function getExt()
89 include 'ModuleInstall/extensions.php';
91 foreach($extensions as $name => $ext) {
92 if($name == 'modules') continue;
93 $params[] = array($name, $ext['section'], $ext['extdir'], $ext['file'], isset($ext['module'])?$ext['module']:'');
99 * @dataProvider getExt
100 * @param string $extname
101 * @param string $section
103 * @param string $file
104 * @param string $module
106 public function testExtFramework($extname, $section, $extdir, $file, $module = '')
109 $module = 'application';
111 $this->module_installer->installdefs[$section] = array(
112 array("from" => '<basepath>/test.ext.php', 'to_module' => $module)
115 $srcFileName = "test.ext.php";
116 if($extname == 'languages') {
117 $this->module_installer->installdefs[$section][0]['language'] = 'en_us';
119 $file = 'lang.ext.php';
120 $srcFileName = "ExtFrameworkTest.php";
122 if($module == 'application') {
123 $srcfile = "custom/Extension/application/Ext/$extdir/{$prefix}{$srcFileName}";
124 $dstfile = "custom/application/Ext/$extdir/{$prefix}$file";
126 $srcfile = "custom/Extension/modules/$module/Ext/$extdir/{$prefix}{$srcFileName}";
127 $dstfile = "custom/modules/$module/Ext/$extdir/{$prefix}$file";
129 $this->module_installer->install_extensions();
130 // check file is there
131 $this->assertFileExists($srcfile);
135 $this->assertEquals($this->testvalue, $testvalue);
138 $this->module_installer->disable_extensions();
139 if(file_exists($dstfile)) include($dstfile);
140 $this->assertNull($testvalue);
142 $this->module_installer->enable_extensions();
143 $this->assertFileExists($srcfile);
145 $this->assertEquals($this->testvalue, $testvalue);
148 $this->module_installer->uninstall_extensions();
149 if(file_exists($dstfile)) include($dstfile);
150 $this->assertNull($testvalue);
153 public function testExtModules()
155 $this->module_installer->installdefs['beans'] = array(
157 'module' => 'ExtFrameworkTest',
158 'class' => 'ExtFrameworkTest',
159 'path' => 'ExtFrameworkTest',
163 $srcfile = "custom/Extension/application/Ext/Include/ExtFrameworkTest.php";
164 $dstfile = "custom/application/Ext/Include/modules.ext.php";
165 $this->module_installer->install_extensions();
166 // check file is there
167 $this->assertFileExists($srcfile);
171 $this->assertEquals('ExtFrameworkTest', $beanList['ExtFrameworkTest']);
173 $this->module_installer->disable_extensions();
175 if(file_exists($dstfile)) include($dstfile);
176 $this->assertArrayNotHasKey('ExtFrameworkTest', $beanList);
179 $this->module_installer->enable_extensions();
180 $this->assertFileExists($srcfile);
182 $this->assertEquals('ExtFrameworkTest', $beanList['ExtFrameworkTest']);
185 $this->module_installer->uninstall_extensions();
186 if(file_exists($dstfile)) include($dstfile);
187 $this->assertArrayNotHasKey('ExtFrameworkTest', $beanList);