]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/ModuleInstall/ExtTest.php
Release 6.3.0
[Github/sugarcrm.git] / tests / ModuleInstall / ExtTest.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37
38 require_once('ModuleInstall/ModuleInstaller.php');
39
40 class ExtTest extends Sugar_PHPUnit_Framework_TestCase
41 {
42     protected $module_installer;
43
44     public static function setUpBeforeClass()
45     {
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");
52     }
53
54         public function setUp()
55         {
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';");
62         }
63
64         public function tearDown()
65         {
66             if($this->module_installer) {
67                 $this->module_installer->uninstall_extensions();
68             }
69             if(file_exists($this->module_installer->base_dir."/test.ext.php")) {
70                 @unlink($this->module_installer->base_dir."/test.ext.php");
71             }
72         }
73
74         public static function tearDownAfterClass()
75         {
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");
83             }
84         rmdir_recursive("cache/ExtTest");
85         }
86
87     public function getExt()
88     {
89         include 'ModuleInstall/extensions.php';
90         $params = array();
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']:'');
94         }
95         return $params;
96     }
97
98     /**
99      * @dataProvider getExt
100      * @param string $extname
101      * @param string $section
102      * @param string $dir
103      * @param string $file
104      * @param string $module
105      */
106     public function testExtFramework($extname, $section, $extdir, $file, $module = '')
107     {
108         if(empty($module)) {
109             $module = 'application';
110         }
111         $this->module_installer->installdefs[$section] = array(
112             array("from" => '<basepath>/test.ext.php', 'to_module' => $module)
113         );
114         $prefix = '';
115         $srcFileName = "test.ext.php";
116         if($extname == 'languages') {
117             $this->module_installer->installdefs[$section][0]['language'] = 'en_us';
118             $prefix = 'en_us.';
119             $file = 'lang.ext.php';
120             $srcFileName = "ExtFrameworkTest.php";
121         }
122             if($module == 'application') {
123             $srcfile = "custom/Extension/application/Ext/$extdir/{$prefix}{$srcFileName}";
124             $dstfile = "custom/application/Ext/$extdir/{$prefix}$file";
125         } else {
126             $srcfile = "custom/Extension/modules/$module/Ext/$extdir/{$prefix}{$srcFileName}";
127             $dstfile = "custom/modules/$module/Ext/$extdir/{$prefix}$file";
128         }
129         $this->module_installer->install_extensions();
130         // check file is there
131         $this->assertFileExists($srcfile);
132         $testvalue = null;
133         // check it works
134         include($dstfile);
135         $this->assertEquals($this->testvalue, $testvalue);
136         $testvalue = null;
137         // check disable
138         $this->module_installer->disable_extensions();
139         if(file_exists($dstfile)) include($dstfile);
140         $this->assertNull($testvalue);
141         // check enable
142         $this->module_installer->enable_extensions();
143         $this->assertFileExists($srcfile);
144         include($dstfile);
145         $this->assertEquals($this->testvalue, $testvalue);
146         $testvalue = null;
147         // check uninstall
148         $this->module_installer->uninstall_extensions();
149         if(file_exists($dstfile)) include($dstfile);
150         $this->assertNull($testvalue);
151     }
152
153     public function testExtModules()
154     {
155         $this->module_installer->installdefs['beans'] = array(
156             array(
157                 'module' => 'ExtFrameworkTest',
158                 'class' =>  'ExtFrameworkTest',
159                 'path' =>  'ExtFrameworkTest',
160                 'tab' => true
161             )
162         );
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);
168         $beanList = null;
169         // check it works
170         include($dstfile);
171         $this->assertEquals('ExtFrameworkTest', $beanList['ExtFrameworkTest']);
172         // check disable
173         $this->module_installer->disable_extensions();
174         $beanList = array();
175         if(file_exists($dstfile)) include($dstfile);
176         $this->assertArrayNotHasKey('ExtFrameworkTest', $beanList);
177         // check enable
178         $beanList = array();
179         $this->module_installer->enable_extensions();
180         $this->assertFileExists($srcfile);
181         include($dstfile);
182         $this->assertEquals('ExtFrameworkTest', $beanList['ExtFrameworkTest']);
183         $beanList = array();
184         // check uninstall
185         $this->module_installer->uninstall_extensions();
186         if(file_exists($dstfile)) include($dstfile);
187         $this->assertArrayNotHasKey('ExtFrameworkTest', $beanList);
188     }
189 }