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");
72 SugarCache::$isCacheReset = false;
75 public static function tearDownAfterClass()
77 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
78 unset($GLOBALS['current_user']);
79 unset($GLOBALS['current_language']);
80 unset($GLOBALS['app_strings']);
81 unset($GLOBALS['mod_strings']);
82 if(file_exists("cache/ExtTest/test.ext.php")) {
83 @unlink("cache/ExtTest/test.ext.php");
85 rmdir_recursive("cache/ExtTest");
88 public function getExt()
90 include 'ModuleInstall/extensions.php';
92 foreach($extensions as $name => $ext) {
93 if($name == 'modules') continue;
94 $params[] = array($name, $ext['section'], $ext['extdir'], $ext['file'], isset($ext['module'])?$ext['module']:'');
100 * @dataProvider getExt
101 * @param string $extname
102 * @param string $section
104 * @param string $file
105 * @param string $module
107 public function testExtFramework($extname, $section, $extdir, $file, $module = '')
110 $module = 'application';
112 $this->module_installer->installdefs[$section] = array(
113 array("from" => '<basepath>/test.ext.php', 'to_module' => $module)
116 $srcFileName = "test.ext.php";
117 if($extname == 'languages') {
118 $this->module_installer->installdefs[$section][0]['language'] = 'en_us';
120 $file = 'lang.ext.php';
121 $srcFileName = "ExtFrameworkTest.php";
123 if($module == 'application') {
124 $srcfile = "custom/Extension/application/Ext/$extdir/{$prefix}{$srcFileName}";
125 $dstfile = "custom/application/Ext/$extdir/{$prefix}$file";
127 $srcfile = "custom/Extension/modules/$module/Ext/$extdir/{$prefix}{$srcFileName}";
128 $dstfile = "custom/modules/$module/Ext/$extdir/{$prefix}$file";
130 $this->module_installer->install_extensions();
131 // check file is there
132 $this->assertFileExists($srcfile);
136 $this->assertEquals($this->testvalue, $testvalue);
139 $this->module_installer->disable_extensions();
140 if(file_exists($dstfile)) include($dstfile);
141 $this->assertNull($testvalue);
143 $this->module_installer->enable_extensions();
144 $this->assertFileExists($srcfile);
146 $this->assertEquals($this->testvalue, $testvalue);
149 $this->module_installer->uninstall_extensions();
150 if(file_exists($dstfile)) include($dstfile);
151 $this->assertNull($testvalue);
154 public function testExtModules()
156 $this->module_installer->installdefs['beans'] = array(
158 'module' => 'ExtFrameworkTest',
159 'class' => 'ExtFrameworkTest',
160 'path' => 'ExtFrameworkTest',
164 $srcfile = "custom/Extension/application/Ext/Include/ExtFrameworkTest.php";
165 $dstfile = "custom/application/Ext/Include/modules.ext.php";
166 $this->module_installer->install_extensions();
167 // check file is there
168 $this->assertFileExists($srcfile);
172 $this->assertEquals('ExtFrameworkTest', $beanList['ExtFrameworkTest']);
174 $this->module_installer->disable_extensions();
176 if(file_exists($dstfile)) include($dstfile);
177 $this->assertArrayNotHasKey('ExtFrameworkTest', $beanList);
180 $this->module_installer->enable_extensions();
181 $this->assertFileExists($srcfile);
183 $this->assertEquals('ExtFrameworkTest', $beanList['ExtFrameworkTest']);
186 $this->module_installer->uninstall_extensions();
187 if(file_exists($dstfile)) include($dstfile);
188 $this->assertArrayNotHasKey('ExtFrameworkTest', $beanList);