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 ********************************************************************************/
40 * This test checks to see if the function repairTableDictionaryExtFile in uw_utils.php is working correctly.
41 * There were some scenarios in 6.0.x whereby the files loaded in the extension tabledictionary.ext.php file
42 * did not exist. This would cause warnings to appear during the upgrade. As a result, we added the
43 * repairTableDictionaryExtFile function to scan the contents of tabledictionary.ext.php and then remove entries
44 * where the file does not exist.
46 class Bug43208Test extends Sugar_PHPUnit_Framework_TestCase
49 var $tableDictionaryExtFile1 = 'custom/Extension/application/Ext/TableDictionary/tabledictionary.ext.php';
50 var $tableDictionaryExtFile2 = 'custom/application/Ext/TableDictionary/tabledictionary.ext.php';
51 var $corruptExtModuleFile = 'custom/Extension/application/Ext/TableDictionary/Bug43208_module.php';
55 if(file_exists($this->tableDictionaryExtFile1)) {
56 copy($this->tableDictionaryExtFile1, $this->tableDictionaryExtFile1 . '.backup');
57 unlink($this->tableDictionaryExtFile1);
58 } else if(!file_exists('custom/Extension/application/Ext/TableDictionary')){
59 mkdir_recursive('custom/Extension/application/Ext/TableDictionary');
62 if( $fh = @fopen($this->tableDictionaryExtFile1, 'w+') )
67 //WARNING: The contents of this file are auto-generated
68 include('custom/metadata/bug43208Test_productsMetaData.php');
70 //WARNING: The contents of this file are auto-generated
71 include('custom/Extension/application/Ext/TableDictionary/Bug43208_module.php');
79 if(file_exists($this->tableDictionaryExtFile2)) {
80 copy($this->tableDictionaryExtFile2, $this->tableDictionaryExtFile2 . '.backup');
81 unlink($this->tableDictionaryExtFile2);
82 } else if(!file_exists('custom/application/Ext/TableDictionary')){
83 mkdir_recursive('custom/application/Ext/TableDictionary');
86 if( $fh = @fopen($this->tableDictionaryExtFile2, 'w+') )
91 //WARNING: The contents of this file are auto-generated
92 include('custom/metadata/bug43208Test_productsMetaData.php');
94 //WARNING: The contents of this file are auto-generated
95 include('custom/Extension/application/Ext/TableDictionary/Bug43208_module.php');
102 if( $fh = @fopen($this->corruptExtModuleFile, 'w+') )
106 //WARNING: The contents of this file are auto-generated
107 include( "custom/metadata/bug43208Test_productsMetaData.php" );
110 fputs( $fh, $string);
116 function tearDown() {
117 if(file_exists($this->tableDictionaryExtFile1 . '.backup'))
119 copy($this->tableDictionaryExtFile1 . '.backup', $this->tableDictionaryExtFile1);
120 unlink($this->tableDictionaryExtFile1 . '.backup');
122 unlink($this->tableDictionaryExtFile1);
125 if(file_exists($this->tableDictionaryExtFile2 . '.backup'))
127 copy($this->tableDictionaryExtFile2 . '.backup', $this->tableDictionaryExtFile2);
128 unlink($this->tableDictionaryExtFile2 . '.backup');
130 unlink($this->tableDictionaryExtFile2);
133 if(file_exists($this->corruptExtModuleFile)) {
134 unlink($this->corruptExtModuleFile);
140 function testRepairTableDictionaryExtFile()
142 require_once('ModuleInstall/ModuleInstaller.php');
143 repairTableDictionaryExtFile();
145 if(function_exists('sugar_fopen'))
147 $fp = @sugar_fopen($this->tableDictionaryExtFile1, 'r');
149 $fp = fopen($this->tableDictionaryExtFile1, 'r');
155 while($line = fgets($fp))
157 if(preg_match('/\s*include\s*\(\s*[\'|\"](.*?)[\'\"]\s*\)\s*;/', $line, $match))
160 $this->assertTrue(file_exists($match[1]), 'Assert that entry for file ' . $line . ' exists');
166 $this->assertEquals($matches, 1, 'Assert that there was one match for correct entries in file ' . $this->tableDictionaryExtFile1);
169 if(function_exists('sugar_fopen'))
171 $fp = @sugar_fopen($this->tableDictionaryExtFile2, 'r');
173 $fp = fopen($this->tableDictionaryExtFile2, 'r');
179 while($line = fgets($fp))
181 if(preg_match('/\s*include\s*\(\s*[\'|\"](.*?)[\'\"]\s*\)\s*;/', $line, $match))
184 $this->assertTrue(file_exists($match[1]), 'Assert that entry for file ' . $line . ' exists');
190 $this->assertEquals($matches, 1, 'Assert that there was one match for correct entries in file ' . $this->tableDictionaryExtFile2);
193 if(function_exists('sugar_fopen'))
195 $fp = @sugar_fopen($this->corruptExtModuleFile, 'r');
197 $fp = fopen($this->corruptExtModuleFile, 'r');
203 while($line = fgets($fp))
205 if(preg_match('/\s*include\s*\(\s*[\'|\"](.*?)[\'\"]\s*\)\s*;/', $line, $match))
208 $this->assertTrue(file_exists($match[1]), 'Assert that entry for file ' . $line . ' exists');
214 $this->assertEquals($matches, 0, 'Assert that there was one match for correct entries in file ' . $this->corruptExtModuleFile);
222 * repairTableDictionaryExtFile
224 * There were some scenarios in 6.0.x whereby the files loaded in the extension tabledictionary.ext.php file
225 * did not exist. This would cause warnings to appear during the upgrade. As a result, this
226 * function scans the contents of tabledictionary.ext.php and then remove entries where the file does exist.
228 function repairTableDictionaryExtFile()
230 $tableDictionaryExtDirs = array('custom/Extension/application/Ext/TableDictionary', 'custom/application/Ext/TableDictionary');
232 foreach($tableDictionaryExtDirs as $tableDictionaryExt)
235 if(is_dir($tableDictionaryExt) && is_writable($tableDictionaryExt)){
236 $dir = dir($tableDictionaryExt);
237 while(($entry = $dir->read()) !== false)
239 $entry = $tableDictionaryExt . '/' . $entry;
240 if(is_file($entry) && preg_match('/\.php$/i', $entry) && is_writeable($entry))
243 if(function_exists('sugar_fopen'))
245 $fp = @sugar_fopen($entry, 'r');
247 $fp = fopen($entry, 'r');
256 while($line = fgets($fp))
258 if(preg_match('/\s*include\s*\(\s*[\'|\"](.*?)[\"|\']\s*\)\s*;/', $line, $match))
260 if(!file_exists($match[1]))
277 if(function_exists('sugar_fopen'))
279 $fp = @sugar_fopen($entry, 'w');
281 $fp = fopen($entry, 'w');
284 if($fp && fwrite($fp, $contents))